feat: add bounded binary API request bodies

This commit is contained in:
2026-09-23 18:29:54 +09:00
parent 2766e5b41b
commit 97822cf691
32 changed files with 1050 additions and 149 deletions
+22 -1
View File
@@ -2,7 +2,7 @@
#![allow(async_fn_in_trait, dead_code)]
use api_macros::{
api,
BinaryBody, api,
openapi::{OpenApiInfo, OpenApiSchema},
};
use schemars::JsonSchema;
@@ -100,6 +100,9 @@ pub trait FixtureApi {
#[delete("/widgets/{widget_id}", operation_id = "widgets.delete", status = 204)]
async fn delete(&self, #[path] widget_id: u32) -> ();
#[put("/uploads", operation_id = "uploads.put", status = 200)]
async fn upload(&self, #[binary] body: BinaryBody) -> Widget;
}
fn document() -> api_macros::openapi::OpenApiDocument {
@@ -282,6 +285,24 @@ fn operations_and_components_preserve_the_wire_contract() {
);
}
let upload = &value["paths"]["/uploads"]["put"];
assert_eq!(upload["operationId"], "uploads.put");
assert_eq!(
upload["requestBody"],
json!({
"required": true,
"content": {
"application/octet-stream": {
"schema": { "type": "string", "format": "binary" }
}
}
})
);
assert!(
!schemas.contains_key("BinaryBody"),
"binary payloads are not JSON Schema components"
);
let delete = &value["paths"]["/widgets/{widget_id}"]["delete"];
assert_eq!(delete["operationId"], "widgets.delete");
assert!(delete.get("security").is_none());