From 415b280ae557c45507a846fb2dbad6aedd44e876 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 1789c80..4f1fd0b 100644 --- a/gotham_restful/src/openapi/router.rs +++ b/gotham_restful/src/openapi/router.rs @@ -314,9 +314,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 { @@ -540,7 +539,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()); } @@ -549,7 +548,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 f7d4e42..50b0305 100644 --- a/gotham_restful/src/result.rs +++ b/gotham_restful/src/result.rs @@ -384,6 +384,11 @@ impl ResourceResult for NoContent Ok(Response::no_content()) } + fn accepted_types() -> Option> + { + Some(Vec::new()) + } + /// Returns the schema of the `()` type. #[cfg(feature = "openapi")] fn schema() -> OpenapiSchema @@ -412,6 +417,11 @@ impl ResourceResult for Result } } + fn accepted_types() -> Option> + { + NoContent::accepted_types() + } + #[cfg(feature = "openapi")] fn schema() -> OpenapiSchema {