Skip to content
Merged
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
6 changes: 5 additions & 1 deletion preprocess_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ def iter_nodes(root):
# Identify children for the next iteration
children = []
if isinstance(curr, dict):
children = curr.values()
for k, v in curr.items():
if k == "properties" and isinstance(v, dict):
children.extend(v.values())
else:
children.append(v)
elif isinstance(curr, list):
children = curr

Expand Down
24 changes: 23 additions & 1 deletion tests/test_codegen_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@
class SchemaNormalizationTest(unittest.TestCase):
"""Tests schema flattening and reference normalization."""

def test_iter_nodes_expands_properties_without_yielding_container(
self,
) -> None:
"""iter_nodes yields "properties" map values directly rather than the "properties" map as a container. Avoids traversal of property names that match json schema keywords."""
schema = {
"type": "object",
"properties": {
"user": {"type": "string", "$ref": "user.json"},
"allOf": {"type": "object"},
},
}
nodes = list(preprocess_schemas.iter_nodes(schema))

# The root object is yielded
self.assertIn(schema, nodes)
# The property subschemas are yielded
self.assertIn(schema["properties"]["user"], nodes)
self.assertIn(schema["properties"]["allOf"], nodes)
# The container map {"user": ..., "allOf": ...} itself is NOT yielded
self.assertNotIn(schema["properties"], nodes)

def test_resolve_local_ref_supports_objects_and_arrays(self) -> None:
"""Local JSON pointers resolve object keys and array indexes."""
schema = {"$defs": {"choices": [{"const": "first"}]}}
Expand Down Expand Up @@ -1665,7 +1686,8 @@ def test_injects_cleanly_when_annotated_is_line_wrapped(self):
wrap the annotation onto multiple lines with a trailing comma; a
naive "insert before the closing bracket" splice then lands after
that comma and produces "Field(...),\\n, AfterValidator(...)]" -
two commas with nothing between them, a SyntaxError)."""
two commas with nothing between them, a SyntaxError).
"""
out = postprocess_models.inject_array_contains(
self.MODULE_LINE_WRAPPED, "TotalsCreateRequest", self.GROUPS
)
Expand Down
Loading