feat: add typed conditional API responses

This commit is contained in:
2026-09-23 19:32:05 +09:00
parent 97822cf691
commit 237ab0e592
25 changed files with 1871 additions and 276 deletions
+30
View File
@@ -103,6 +103,16 @@ pub trait FixtureApi {
#[put("/uploads", operation_id = "uploads.put", status = 200)]
async fn upload(&self, #[binary] body: BinaryBody) -> Widget;
#[get(
"/conditional",
operation_id = "conditional.get",
responses = [
(status = 200, body = Widget, headers = [("etag", String), ("cache-control", String)]),
(status = 304, headers = [("etag", String), ("cache-control", String)])
]
)]
async fn conditional(&self) -> fixture_api_responses::Conditional;
}
fn document() -> api_macros::openapi::OpenApiDocument {
@@ -303,6 +313,26 @@ fn operations_and_components_preserve_the_wire_contract() {
"binary payloads are not JSON Schema components"
);
let conditional = &value["paths"]["/conditional"]["get"];
assert_eq!(
conditional["responses"]["200"]["content"]["application/json"]["schema"],
json!({ "$ref": "#/components/schemas/Widget" })
);
assert_eq!(
conditional["responses"]["200"]["headers"]["etag"]["schema"],
json!({ "$ref": "#/components/schemas/string" })
);
assert_eq!(
conditional["responses"]["304"],
json!({
"description": "Alternate successful response",
"headers": {
"cache-control": { "schema": { "$ref": "#/components/schemas/string" } },
"etag": { "schema": { "$ref": "#/components/schemas/string" } }
}
})
);
let delete = &value["paths"]["/widgets/{widget_id}"]["delete"];
assert_eq!(delete["operationId"], "widgets.delete");
assert!(delete.get("security").is_none());