Fix Option<T> schema generation sometimes producing a schema that is not referenced
This commit is contained in:
parent
717e3baed9
commit
c2e8389e93
2 changed files with 16 additions and 40 deletions
|
@ -272,9 +272,11 @@ impl<T: JsonSchema> JsonSchema for Option<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn json_schema(gen: &mut SchemaGenerator) -> Result {
|
fn json_schema(gen: &mut SchemaGenerator) -> Result {
|
||||||
// FIXME this may produce a subschema that is not referenced in the final schema,
|
let mut schema = if gen.settings().option_nullable {
|
||||||
// e.g. SingleOrVec_For_InstanceType in schema-openapi3.json
|
T::json_schema(gen)?
|
||||||
let mut schema = gen.subschema_for::<T>()?;
|
} else {
|
||||||
|
gen.subschema_for::<T>()?
|
||||||
|
};
|
||||||
if gen.settings().option_add_null_type {
|
if gen.settings().option_add_null_type {
|
||||||
schema = match schema {
|
schema = match schema {
|
||||||
Schema::Bool(true) => Schema::Bool(true),
|
Schema::Bool(true) => Schema::Bool(true),
|
||||||
|
|
|
@ -24,6 +24,17 @@
|
||||||
"integer"
|
"integer"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"Ref": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"$ref": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"$ref"
|
||||||
|
]
|
||||||
|
},
|
||||||
"Schema": {
|
"Schema": {
|
||||||
"anyOf": [
|
"anyOf": [
|
||||||
{
|
{
|
||||||
|
@ -144,43 +155,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": true
|
"additionalProperties": true
|
||||||
},
|
|
||||||
"Ref": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"$ref": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"$ref"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"SingleOrVec_For_InstanceType": {
|
|
||||||
"anyOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/components/schemas/InstanceType"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"$ref": "#/components/schemas/InstanceType"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"SingleOrVec_For_Schema": {
|
|
||||||
"anyOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/components/schemas/Schema"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"$ref": "#/components/schemas/Schema"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue