Skip to content

Commit fa8c7ca

Browse files
FanouZeng-TTclaude
andcommitted
fix: preserve conditional allOf branches
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 340a06b commit fa8c7ca

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

preprocess_schemas.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ def _process_all_of_item(item, node, root, state):
104104
if not isinstance(item, dict):
105105
return
106106

107+
if any(key in item for key in ("if", "then", "else")):
108+
state["remaining_refs"].append(item)
109+
return
110+
107111
# Extract polymorphic branches (anyOf, oneOf) to keep the node flat
108112
for poly_key in ["anyOf", "oneOf"]:
109113
if poly_key in item:

tests/test_codegen_pipeline.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,29 @@ def test_preprocess_flattens_and_distributes_properties(self) -> None:
9191
self.assertEqual(set(branch["required"]), {"id", "kind"})
9292
self.assertEqual(branch["type"], "object")
9393

94+
def test_preprocess_preserves_multiple_conditional_branches(self) -> None:
95+
"""Each conditional allOf branch survives schema flattening."""
96+
negative = {
97+
"if": {"properties": {"type": {"const": "discount"}}},
98+
"then": {"properties": {"amount": {"exclusiveMaximum": 0}}},
99+
}
100+
non_negative = {
101+
"if": {"properties": {"type": {"const": "subtotal"}}},
102+
"then": {"properties": {"amount": {"minimum": 0}}},
103+
}
104+
schema = {
105+
"type": "object",
106+
"properties": {
107+
"type": {"type": "string"},
108+
"amount": {"type": "integer"},
109+
},
110+
"allOf": [negative, non_negative],
111+
}
112+
113+
preprocess_schemas.preprocess_full_schema(schema)
114+
115+
self.assertEqual(schema["allOf"], [negative, non_negative])
116+
94117
def test_preprocess_inlines_entity_fields(self) -> None:
95118
"""The shared entity definition is inlined without its metadata."""
96119
entity = {

0 commit comments

Comments
 (0)