Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions preprocess_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ def _process_all_of_item(item, node, root, state):
if not isinstance(item, dict):
return

if any(key in item for key in ("if", "then", "else")):
state["remaining_refs"].append(item)
return

# Extract polymorphic branches (anyOf, oneOf) to keep the node flat
for poly_key in ["anyOf", "oneOf"]:
if poly_key in item:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_codegen_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,29 @@ def test_preprocess_flattens_and_distributes_properties(self) -> None:
self.assertEqual(set(branch["required"]), {"id", "kind"})
self.assertEqual(branch["type"], "object")

def test_preprocess_preserves_multiple_conditional_branches(self) -> None:
"""Each conditional allOf branch survives schema flattening."""
negative = {
"if": {"properties": {"type": {"const": "discount"}}},
"then": {"properties": {"amount": {"exclusiveMaximum": 0}}},
}
non_negative = {
"if": {"properties": {"type": {"const": "subtotal"}}},
"then": {"properties": {"amount": {"minimum": 0}}},
}
schema = {
"type": "object",
"properties": {
"type": {"type": "string"},
"amount": {"type": "integer"},
},
"allOf": [negative, non_negative],
}

preprocess_schemas.preprocess_full_schema(schema)

self.assertEqual(schema["allOf"], [negative, non_negative])

def test_preprocess_inlines_entity_fields(self) -> None:
"""The shared entity definition is inlined without its metadata."""
entity = {
Expand Down
Loading