mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-02-23 13:02:28 +00:00
improve option handling
This commit is contained in:
parent
50ed2411c9
commit
74ea1b820b
2 changed files with 10 additions and 14 deletions
|
@ -132,22 +132,20 @@ impl<T : OpenapiType> OpenapiType for Option<T>
|
||||||
fn to_schema() -> OpenapiSchema
|
fn to_schema() -> OpenapiSchema
|
||||||
{
|
{
|
||||||
let schema = T::to_schema();
|
let schema = T::to_schema();
|
||||||
let mut dependencies : IndexMap<String, OpenapiSchema> = IndexMap::new();
|
let mut dependencies = schema.dependencies.clone();
|
||||||
let refor = if let Some(name) = schema.name.clone()
|
let schema = match schema.name.clone() {
|
||||||
{
|
Some(name) => {
|
||||||
let reference = Reference { reference: format!("#/components/schemas/{}", name) };
|
let reference = Reference { reference: format!("#/components/schemas/{}", name) };
|
||||||
dependencies.insert(name, schema);
|
dependencies.insert(name, schema);
|
||||||
reference
|
SchemaKind::AllOf { all_of: vec![reference] }
|
||||||
}
|
},
|
||||||
else
|
None => schema.schema
|
||||||
{
|
|
||||||
Item(schema.to_schema())
|
|
||||||
};
|
};
|
||||||
|
|
||||||
OpenapiSchema {
|
OpenapiSchema {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
name: None,
|
name: None,
|
||||||
schema: SchemaKind::AllOf { all_of: vec![refor] },
|
schema,
|
||||||
dependencies
|
dependencies
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,8 +78,6 @@ fn expand_field(field : &Field) -> TokenStream2
|
||||||
if schema.nullable
|
if schema.nullable
|
||||||
{
|
{
|
||||||
schema.nullable = false;
|
schema.nullable = false;
|
||||||
schema.name = schema.name.map(|name|
|
|
||||||
if name.ends_with("OrNull") { name[..(name.len()-6)].to_string() } else { name });
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -97,7 +95,7 @@ fn expand_field(field : &Field) -> TokenStream2
|
||||||
None => {
|
None => {
|
||||||
properties.insert(
|
properties.insert(
|
||||||
stringify!(#ident).to_string(),
|
stringify!(#ident).to_string(),
|
||||||
ReferenceOr::Item(Box::new(<#ty>::to_schema().to_schema()))
|
ReferenceOr::Item(Box::new(schema.to_schema()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue