From b83d08e9b847387fc5b7f7f293f5b3e10d865e12 Mon Sep 17 00:00:00 2001 From: "Adam H. Leventhal" Date: Wed, 2 Mar 2022 11:11:25 -0800 Subject: [PATCH] improve OpenAPI description for Response endpoints --- dropshot/src/api_description.rs | 21 +++++++++++++++++++-- dropshot/tests/test_openapi.json | 7 ++++++- dropshot/tests/test_openapi_fuller.json | 7 ++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/dropshot/src/api_description.rs b/dropshot/src/api_description.rs index 27c99a0b6..930766ff2 100644 --- a/dropshot/src/api_description.rs +++ b/dropshot/src/api_description.rs @@ -699,15 +699,32 @@ impl ApiDescription { } else { // If no schema was specified, the response is hand-rolled. In // this case we'll fall back to the default response type which - // we assume to be inclusive of errors. + // we assume to be inclusive of errors. The media type and + // and schema will similarly be maximally permissive. + let mut content = indexmap::IndexMap::new(); + content.insert( + "*/*".to_string(), + openapiv3::MediaType { + schema: Some(openapiv3::ReferenceOr::Item( + openapiv3::Schema { + schema_data: openapiv3::SchemaData::default(), + schema_kind: openapiv3::SchemaKind::Any( + openapiv3::AnySchema::default(), + ), + }, + )), + ..Default::default() + }, + ); operation.responses.default = Some(openapiv3::ReferenceOr::Item(openapiv3::Response { // TODO: perhaps we should require even free-form // responses to have a description since it's required // by OpenAPI. description: "".to_string(), + content, ..Default::default() - })) + })); } // Drop in the operation. diff --git a/dropshot/tests/test_openapi.json b/dropshot/tests/test_openapi.json index 6fa917163..0163a7831 100644 --- a/dropshot/tests/test_openapi.json +++ b/dropshot/tests/test_openapi.json @@ -446,7 +446,12 @@ "operationId": "handler16", "responses": { "default": { - "description": "" + "description": "", + "content": { + "*/*": { + "schema": {} + } + } } } } diff --git a/dropshot/tests/test_openapi_fuller.json b/dropshot/tests/test_openapi_fuller.json index 6287d5a0b..13e843622 100644 --- a/dropshot/tests/test_openapi_fuller.json +++ b/dropshot/tests/test_openapi_fuller.json @@ -454,7 +454,12 @@ "operationId": "handler16", "responses": { "default": { - "description": "" + "description": "", + "content": { + "*/*": { + "schema": {} + } + } } } }