Skip to content
Snippets Groups Projects
Commit d786fa81 authored by Maaz Ahmed's avatar Maaz Ahmed
Browse files

fix: correctly resolve references in enums and arrays

parent 23cf2eaa
No related branches found
No related tags found
1 merge request!1Resolve "References remain unresolved when nested within enums and arrays"
......@@ -21,6 +21,8 @@ impl SchemaInspector {
const PROP: &'static str = "properties";
const REF: &'static str = "$ref";
const AOF: &'static str = "allOf";
const OOF: &'static str = "oneOf";
const ITM: &'static str = "items";
/// Initialize the `SchemaInspector` using the name of the type provided to the function using the turbofish syntax instead of using a string
///
......@@ -116,9 +118,24 @@ impl SchemaInspector {
.get(schema)
.ok_or_else(|| InitError::ResolutionFailure(schema.to_owned()))?
.to_owned();
if let Some(Value::Object(inner_props)) = inner.get_mut(Self::PROP) {
Self::resolve_references(schemas, inner_props)?;
}
props
.values_mut()
.try_for_each(|obj| Self::resolve_nested(schemas, obj))
}
fn resolve_nested(schemas: &Map<String, Value>, val: &mut Value) -> Result<(), InitError> {
if let Some(Value::Object(inner_props)) = val.get_mut(Self::PROP) {
Self::resolve_references(schemas, inner_props)?;
} else if val.get(Self::ITM).is_some() {
// Rewrite - manually insert schema instead of calling resolve_references ?
if let Value::Object(false_props) = val {
Self::resolve_references(schemas, false_props)?;
}
} else if let Some(Value::Array(enum_arr)) = val.get_mut(Self::OOF) {
return enum_arr
.iter_mut()
.try_for_each(|obj| Self::resolve_nested(schemas, obj));
}
Ok(())
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment