fix: Don't change order of json schema object properties unless prop_order is passed, Closes #1180

This commit is contained in:
Andrei Betlen 2024-02-13 02:44:00 -05:00
parent 5efc45bdfd
commit d1822fed6b

View file

@ -1471,12 +1471,15 @@ class SchemaConverter:
if schema_type == "object" and "properties" in schema:
# TODO: `required` keyword
if self._prop_order:
prop_order = self._prop_order
prop_pairs = sorted(
schema["properties"].items(),
# sort by position in prop_order (if specified) then by key
key=lambda kv: (prop_order.get(kv[0], len(prop_order)), kv[0]),
)
else:
prop_pairs = schema["properties"].items()
rule = '"{" space'
for i, (prop_name, prop_schema) in enumerate(prop_pairs):