Repository: oxidecomputer/typify
Pull request #460 (2023-12-16 02:18:44)

schemas aren't being properly preserved
We aren't preserving some schemas end-to-end.


Patch:
diff --git a/typify-impl/src/convert.rs b/typify-impl/src/convert.rs
index 7a61588..f85a106 100644
--- a/typify-impl/src/convert.rs
+++ b/typify-impl/src/convert.rs
@@ -487,7 +487,8 @@ impl TypeSpace {
                     schema.subschemas.as_deref(),
                     &self.definitions,
                 );
-                let (type_entry, _) = self.convert_schema(type_name, &merged_schema.into())?;
+                let (type_entry, _) =
+                    self.convert_schema_object(type_name, original_schema, &merged_schema)?;
                 Ok((type_entry, &None))
             }
 


Test patch:
diff --git a/typify/tests/schemas/merged-schemas.rs b/typify/tests/schemas/merged-schemas.rs
index c2cee73..fd5f3d3 100644
--- a/typify/tests/schemas/merged-schemas.rs
+++ b/typify/tests/schemas/merged-schemas.rs
@@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
 #[doc = r" <details><summary>JSON schema</summary>"]
 #[doc = r""]
 #[doc = r" ```json"]
-#[doc = "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"this\": {}\n  }\n}"]
+#[doc = "{\n  \"type\": \"object\",\n  \"not\": {\n    \"required\": [\n      \"that\"\n    ]\n  },\n  \"properties\": {\n    \"that\": {},\n    \"this\": {}\n  }\n}"]
 #[doc = r" ```"]
 #[doc = r" </details>"]
 #[derive(Clone, Debug, Deserialize, Serialize)]
@@ -242,7 +242,7 @@ impl ToString for NarrowNumber {
 #[doc = r" <details><summary>JSON schema</summary>"]
 #[doc = r""]
 #[doc = r" ```json"]
-#[doc = "{\n  \"type\": \"object\",\n  \"required\": [\n    \"a\"\n  ],\n  \"properties\": {\n    \"a\": {}\n  }\n}"]
+#[doc = "{\n  \"type\": \"object\",\n  \"not\": {\n    \"anyOf\": [\n      {\n        \"required\": [\n          \"b\"\n        ]\n      },\n      {\n        \"required\": [\n          \"c\"\n        ]\n      }\n    ]\n  },\n  \"required\": [\n    \"a\"\n  ],\n  \"properties\": {\n    \"a\": {},\n    \"b\": {},\n    \"c\": {}\n  }\n}"]
 #[doc = r" ```"]
 #[doc = r" </details>"]
 #[derive(Clone, Debug, Deserialize, Serialize)]
@@ -447,7 +447,7 @@ impl std::convert::TryFrom<String> for Unsatisfiable3C {
 #[doc = r" <details><summary>JSON schema</summary>"]
 #[doc = r""]
 #[doc = r" ```json"]
-#[doc = "{\n  \"oneOf\": [\n    {\n      \"allOf\": [\n        {\n          \"type\": \"object\",\n          \"properties\": {\n            \"pattern\": {\n              \"type\": \"string\"\n            },\n            \"pattern-either\": {\n              \"type\": \"string\"\n            },\n            \"pattern-regex\": {\n              \"type\": \"string\"\n            },\n            \"patterns\": {\n              \"type\": \"string\"\n            }\n          }\n        },\n        {\n          \"not\": {\n            \"anyOf\": [\n              {\n                \"required\": [\n                  \"patterns\"\n                ]\n              },\n              {\n                \"required\": [\n                  \"pattern-either\"\n                ]\n              },\n              {\n                \"required\": [\n                  \"pattern-regex\"\n                ]\n              }\n            ]\n          },\n          \"required\": [\n            \"pattern\"\n          ]\n        }\n      ]\n    },\n    {\n      \"allOf\": [\n        {\n          \"type\": \"object\",\n          \"properties\": {\n            \"pattern\": {\n              \"type\": \"string\"\n            },\n            \"pattern-either\": {\n              \"type\": \"string\"\n            },\n            \"pattern-regex\": {\n              \"type\": \"string\"\n            },\n            \"patterns\": {\n              \"type\": \"string\"\n            }\n          }\n        },\n        {\n          \"not\": {\n            \"anyOf\": [\n              {\n                \"required\": [\n                  \"pattern\"\n                ]\n              },\n              {\n                \"required\": [\n                  \"pattern-either\"\n                ]\n              },\n              {\n                \"required\": [\n                  \"pattern-regex\"\n                ]\n              }\n            ]\n          },\n          \"required\": [\n            \"patterns\"\n          ]\n        }\n      ]\n    },\n    {\n      \"allOf\": [\n        {\n          \"type\": \"object\",\n          \"properties\": {\n            \"pattern\": {\n              \"type\": \"string\"\n            },\n            \"pattern-either\": {\n              \"type\": \"string\"\n            },\n            \"pattern-regex\": {\n              \"type\": \"string\"\n            },\n            \"patterns\": {\n              \"type\": \"string\"\n            }\n          }\n        },\n        {\n          \"not\": {\n            \"anyOf\": [\n              {\n                \"required\": [\n                  \"pattern\"\n                ]\n              },\n              {\n                \"required\": [\n                  \"patterns\"\n                ]\n              },\n              {\n                \"required\": [\n                  \"pattern-regex\"\n                ]\n              }\n            ]\n          },\n          \"required\": [\n            \"pattern-either\"\n          ]\n        }\n      ]\n    },\n    {\n      \"allOf\": [\n        {\n          \"type\": \"object\",\n          \"properties\": {\n            \"pattern\": {\n              \"type\": \"string\"\n            },\n            \"pattern-either\": {\n              \"type\": \"string\"\n            },\n            \"pattern-regex\": {\n              \"type\": \"string\"\n            },\n            \"patterns\": {\n              \"type\": \"string\"\n            }\n          }\n        },\n        {\n          \"not\": {\n            \"anyOf\": [\n              {\n                \"required\": [\n                  \"pattern\"\n                ]\n              },\n              {\n                \"required\": [\n                  \"patterns\"\n                ]\n              },\n              {\n                \"required\": [\n                  \"pattern-either\"\n                ]\n              }\n            ]\n          },\n          \"required\": [\n            \"pattern-regex\"\n          ]\n        }\n      ]\n    }\n  ]\n}"]
+#[doc = "{\n  \"type\": \"object\",\n  \"oneOf\": [\n    {\n      \"not\": {\n        \"anyOf\": [\n          {\n            \"required\": [\n              \"patterns\"\n            ]\n          },\n          {\n            \"required\": [\n              \"pattern-either\"\n            ]\n          },\n          {\n            \"required\": [\n              \"pattern-regex\"\n            ]\n          }\n        ]\n      },\n      \"required\": [\n        \"pattern\"\n      ]\n    },\n    {\n      \"not\": {\n        \"anyOf\": [\n          {\n            \"required\": [\n              \"pattern\"\n            ]\n          },\n          {\n            \"required\": [\n              \"pattern-either\"\n            ]\n          },\n          {\n            \"required\": [\n              \"pattern-regex\"\n            ]\n          }\n        ]\n      },\n      \"required\": [\n        \"patterns\"\n      ]\n    },\n    {\n      \"not\": {\n        \"anyOf\": [\n          {\n            \"required\": [\n              \"pattern\"\n            ]\n          },\n          {\n            \"required\": [\n              \"patterns\"\n            ]\n          },\n          {\n            \"required\": [\n              \"pattern-regex\"\n            ]\n          }\n        ]\n      },\n      \"required\": [\n        \"pattern-either\"\n      ]\n    },\n    {\n      \"not\": {\n        \"anyOf\": [\n          {\n            \"required\": [\n              \"pattern\"\n            ]\n          },\n          {\n            \"required\": [\n              \"patterns\"\n            ]\n          },\n          {\n            \"required\": [\n              \"pattern-either\"\n            ]\n          }\n        ]\n      },\n      \"required\": [\n        \"pattern-regex\"\n      ]\n    }\n  ],\n  \"properties\": {\n    \"pattern\": {\n      \"type\": \"string\"\n    },\n    \"pattern-either\": {\n      \"type\": \"string\"\n    },\n    \"pattern-regex\": {\n      \"type\": \"string\"\n    },\n    \"patterns\": {\n      \"type\": \"string\"\n    }\n  }\n}"]
 #[doc = r" ```"]
 #[doc = r" </details>"]
 #[derive(Clone, Debug, Deserialize, Serialize)]