Skip to content

Commit 18078c4

Browse files
authored
improve OpenAPI description for Response<Body> endpoints (#295)
1 parent 6ca8e21 commit 18078c4

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

dropshot/src/api_description.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,15 +778,32 @@ impl<Context: ServerContext> ApiDescription<Context> {
778778
} else {
779779
// If no schema was specified, the response is hand-rolled. In
780780
// this case we'll fall back to the default response type which
781-
// we assume to be inclusive of errors.
781+
// we assume to be inclusive of errors. The media type and
782+
// and schema will similarly be maximally permissive.
783+
let mut content = indexmap::IndexMap::new();
784+
content.insert(
785+
"*/*".to_string(),
786+
openapiv3::MediaType {
787+
schema: Some(openapiv3::ReferenceOr::Item(
788+
openapiv3::Schema {
789+
schema_data: openapiv3::SchemaData::default(),
790+
schema_kind: openapiv3::SchemaKind::Any(
791+
openapiv3::AnySchema::default(),
792+
),
793+
},
794+
)),
795+
..Default::default()
796+
},
797+
);
782798
operation.responses.default =
783799
Some(openapiv3::ReferenceOr::Item(openapiv3::Response {
784800
// TODO: perhaps we should require even free-form
785801
// responses to have a description since it's required
786802
// by OpenAPI.
787803
description: "".to_string(),
804+
content,
788805
..Default::default()
789-
}))
806+
}));
790807
}
791808

792809
// Drop in the operation.

dropshot/tests/test_openapi.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,12 @@
485485
"operationId": "handler16",
486486
"responses": {
487487
"default": {
488-
"description": ""
488+
"description": "",
489+
"content": {
490+
"*/*": {
491+
"schema": {}
492+
}
493+
}
489494
}
490495
}
491496
}

dropshot/tests/test_openapi_fuller.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,12 @@
493493
"operationId": "handler16",
494494
"responses": {
495495
"default": {
496-
"description": ""
496+
"description": "",
497+
"content": {
498+
"*/*": {
499+
"schema": {}
500+
}
501+
}
497502
}
498503
}
499504
}

0 commit comments

Comments
 (0)