Prevent possibility of infinite loop

This commit is contained in:
Graham Esau 2019-09-14 20:36:59 +01:00
parent b9e9360b5c
commit d7a214526f

View file

@ -149,7 +149,7 @@ impl SchemaGenerator {
} }
pub fn get_schema_object(&self, mut schema: Schema) -> Result<SchemaObject> { pub fn get_schema_object(&self, mut schema: Schema) -> Result<SchemaObject> {
loop { for _ in 0..100 {
match schema { match schema {
Schema::Object(obj) => return Ok(obj), Schema::Object(obj) => return Ok(obj),
Schema::Bool(true) => return Ok(Default::default()), Schema::Bool(true) => return Ok(Default::default()),
@ -189,5 +189,9 @@ impl SchemaGenerator {
} }
} }
} }
Err(JsonSchemaError::new(
"Failed to dereference schema after 100 iterations - reference may be cyclic.",
schema,
))
} }
} }