diff --git a/gotham_restful/src/openapi/router.rs b/gotham_restful/src/openapi/router.rs index 3500df5..48565de 100644 --- a/gotham_restful/src/openapi/router.rs +++ b/gotham_restful/src/openapi/router.rs @@ -476,6 +476,7 @@ implOpenapiRouter!(ScopeBuilder); #[cfg(test)] mod test { + use crate::ResourceResult; use super::*; #[derive(OpenapiType)] @@ -521,4 +522,24 @@ mod test let json = serde_json::to_string(¶ms).unwrap(); assert_eq!(json, format!(r#"[{{"in":"path","name":"{}","required":true,"schema":{{"type":"string"}},"style":"simple"}},{{"in":"query","name":"id","required":true,"schema":{{"type":"integer"}},"style":"form"}}]"#, name)); } + + #[test] + fn no_content_schema_to_content() + { + let types = NoContent::accepted_types(); + let schema = ::schema(); + let content = schema_to_content(types.unwrap_or_default(), Item(schema.into_schema())); + assert!(content.is_empty()); + } + + #[test] + fn raw_schema_to_content() + { + let types = Raw::<&str>::accepted_types(); + let schema = as OpenapiType>::schema(); + let content = schema_to_content(types.unwrap_or_default(), 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 2cdd719..c5e67b0 100644 --- a/gotham_restful/src/result.rs +++ b/gotham_restful/src/result.rs @@ -2,7 +2,7 @@ use crate::{ResponseBody, StatusCode}; #[cfg(feature = "openapi")] use crate::{OpenapiSchema, OpenapiType}; use hyper::Body; -use mime::{Mime, APPLICATION_JSON}; +use mime::{Mime, APPLICATION_JSON, STAR_STAR}; #[cfg(feature = "openapi")] use openapiv3::{SchemaKind, StringFormat, StringType, Type, VariantOrUnknownOrEmpty}; use serde::Serialize; @@ -289,6 +289,11 @@ impl> ResourceResult for Raw Ok(Response::new(StatusCode::OK, self.raw, Some(self.mime.clone()))) } + fn accepted_types() -> Option> + { + Some(vec![STAR_STAR]) + } + #[cfg(feature = "openapi")] fn schema() -> OpenapiSchema { @@ -315,6 +320,11 @@ where } } + fn accepted_types() -> Option> + { + as ResourceResult>::accepted_types() + } + #[cfg(feature = "openapi")] fn schema() -> OpenapiSchema {