From d786fa817f6dea87139b42da350183aa46867acb Mon Sep 17 00:00:00 2001
From: Maaz Ahmed <maaz.a@subcom.tech>
Date: Wed, 14 Feb 2024 16:58:50 +0530
Subject: [PATCH] fix: correctly resolve references in enums and arrays

---
 src/lib.rs | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs
index 187d793..5d777b8 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(())
     }
-- 
GitLab