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 {
|
||||
self.pending_schema_names.insert(name.to_owned());
|
||||
let schema = T::json_schema(self);
|
||||
// FIXME schema name not removed if previous line panics
|
||||
self.pending_schema_names.remove(name);
|
||||
schema
|
||||
struct PendingSchemaState<'a> {
|
||||
gen: &'a mut SchemaGenerator,
|
||||
name: &'a str,
|
||||
did_add: bool,
|
||||
}
|
||||
|
||||
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": {
|
||||
"recursive": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"direct": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/RecursiveOuter"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"indirect": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/RecursiveInner"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
"$ref": "#/definitions/RecursiveOuter"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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