diff --git a/gotham_restful/src/openapi/types.rs b/gotham_restful/src/openapi/types.rs index 5e08d60..69f4adc 100644 --- a/gotham_restful/src/openapi/types.rs +++ b/gotham_restful/src/openapi/types.rs @@ -132,22 +132,20 @@ impl OpenapiType for Option fn to_schema() -> OpenapiSchema { let schema = T::to_schema(); - let mut dependencies : IndexMap = IndexMap::new(); - let refor = if let Some(name) = schema.name.clone() - { - let reference = Reference { reference: format!("#/components/schemas/{}", name) }; - dependencies.insert(name, schema); - reference - } - else - { - Item(schema.to_schema()) + let mut dependencies = schema.dependencies.clone(); + let schema = match schema.name.clone() { + Some(name) => { + let reference = Reference { reference: format!("#/components/schemas/{}", name) }; + dependencies.insert(name, schema); + SchemaKind::AllOf { all_of: vec![reference] } + }, + None => schema.schema }; OpenapiSchema { nullable: true, name: None, - schema: SchemaKind::AllOf { all_of: vec![refor] }, + schema, dependencies } } diff --git a/gotham_restful_derive/src/openapi_type.rs b/gotham_restful_derive/src/openapi_type.rs index d4df178..f041d5b 100644 --- a/gotham_restful_derive/src/openapi_type.rs +++ b/gotham_restful_derive/src/openapi_type.rs @@ -78,8 +78,6 @@ fn expand_field(field : &Field) -> TokenStream2 if schema.nullable { schema.nullable = false; - schema.name = schema.name.map(|name| - if name.ends_with("OrNull") { name[..(name.len()-6)].to_string() } else { name }); } else { @@ -97,7 +95,7 @@ fn expand_field(field : &Field) -> TokenStream2 None => { properties.insert( stringify!(#ident).to_string(), - ReferenceOr::Item(Box::new(<#ty>::to_schema().to_schema())) + ReferenceOr::Item(Box::new(schema.to_schema())) ); } }