Ensure pending_schema_names is always cleaned up
This commit is contained in:
parent
803c47bab3
commit
7bcd6a2a65
2 changed files with 24 additions and 39 deletions
|
@ -374,11 +374,29 @@ impl SchemaGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn json_schema_internal<T: ?Sized + JsonSchema>(&mut self, name: &str) -> Schema {
|
fn json_schema_internal<T: ?Sized + JsonSchema>(&mut self, name: &str) -> Schema {
|
||||||
self.pending_schema_names.insert(name.to_owned());
|
struct PendingSchemaState<'a> {
|
||||||
let schema = T::json_schema(self);
|
gen: &'a mut SchemaGenerator,
|
||||||
// FIXME schema name not removed if previous line panics
|
name: &'a str,
|
||||||
self.pending_schema_names.remove(name);
|
did_add: bool,
|
||||||
schema
|
}
|
||||||
|
|
||||||
|
impl<'a> PendingSchemaState<'a> {
|
||||||
|
fn new(gen: &'a mut SchemaGenerator, name: &'a str) -> Self {
|
||||||
|
let did_add = gen.pending_schema_names.insert(name.to_owned());
|
||||||
|
Self { gen, name, did_add }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for PendingSchemaState<'_> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
if self.did_add {
|
||||||
|
self.gen.pending_schema_names.remove(self.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let pss = PendingSchemaState::new(self, name);
|
||||||
|
T::json_schema(pss.gen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,29 +23,7 @@
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"recursive": {
|
"recursive": {
|
||||||
"type": "object",
|
"$ref": "#/definitions/RecursiveOuter"
|
||||||
"properties": {
|
|
||||||
"direct": {
|
|
||||||
"anyOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/definitions/RecursiveOuter"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "null"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"indirect": {
|
|
||||||
"anyOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/definitions/RecursiveInner"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "null"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,17 +57,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"RecursiveInner": {
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"recursive"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"recursive": {
|
|
||||||
"$ref": "#/definitions/RecursiveOuter"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue