diff --git a/Cargo.toml b/Cargo.toml index a8db2bbb26559e71b6d046d4fa324f61b11e75d2..36b35c237e3c869c032cf8b277e9c847d9809f9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "schema-police" -version = "0.1.0" +version = "0.1.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/lib.rs b/src/lib.rs index 187d793547e7049c012008246f43a9b21a247bec..5d777b86e0a0790ad0221c33df15be44910a1d39 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(()) }