From f70865d246ba746f25e1701b0bfb5e5745e4d64c Mon Sep 17 00:00:00 2001 From: Dominic Date: Wed, 22 Apr 2020 11:18:10 +0200 Subject: [PATCH] fix no schema having content --- gotham_restful/src/openapi/router.rs | 7 +++---- gotham_restful/src/result.rs | 10 ++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/gotham_restful/src/openapi/router.rs b/gotham_restful/src/openapi/router.rs index a379585..a5ea5eb 100644 --- a/gotham_restful/src/openapi/router.rs +++ b/gotham_restful/src/openapi/router.rs @@ -317,9 +317,8 @@ fn new_operation( let mut responses : IndexMap> = IndexMap::new(); responses.insert(StatusCode::Code(default_status.as_u16()), Item(Response { description: default_status.canonical_reason().map(|d| d.to_string()).unwrap_or_default(), - headers: IndexMap::new(), content, - links: IndexMap::new() + ..Default::default() })); let request_body = body_schema.map(|schema| Item(OARequestBody { @@ -552,7 +551,7 @@ mod test { let types = NoContent::accepted_types(); let schema = ::schema(); - let content = schema_to_content(types.unwrap_or_default(), Item(schema.into_schema())); + let content = schema_to_content(types.unwrap_or_else(|| vec![STAR_STAR]), Item(schema.into_schema())); assert!(content.is_empty()); } @@ -561,7 +560,7 @@ mod test { let types = Raw::<&str>::accepted_types(); let schema = as OpenapiType>::schema(); - let content = schema_to_content(types.unwrap_or_default(), Item(schema.into_schema())); + let content = schema_to_content(types.unwrap_or_else(|| vec![STAR_STAR]), Item(schema.into_schema())); assert_eq!(content.len(), 1); let json = serde_json::to_string(&content.values().nth(0).unwrap()).unwrap(); assert_eq!(json, r#"{"schema":{"type":"string","format":"binary"}}"#); diff --git a/gotham_restful/src/result.rs b/gotham_restful/src/result.rs index 7e5bdd9..a8d49ed 100644 --- a/gotham_restful/src/result.rs +++ b/gotham_restful/src/result.rs @@ -483,6 +483,11 @@ impl ResourceResult for NoContent future::ok(Response::no_content()).boxed() } + fn accepted_types() -> Option> + { + Some(Vec::new()) + } + /// Returns the schema of the `()` type. #[cfg(feature = "openapi")] fn schema() -> OpenapiSchema @@ -515,6 +520,11 @@ where } } + fn accepted_types() -> Option> + { + NoContent::accepted_types() + } + #[cfg(feature = "openapi")] fn schema() -> OpenapiSchema {