props_ordered does not work for nested fields
0xDAFE opened this issue · 1 comments
0xDAFE commented
Hi everyone,
We are using marshmallow-jsonschema to generate a JSON schema for json-editor.
I noticed that the recently introduced props_ordered
argument does not work for nested schemas.
Extended Test Case:
def test_sorting_properties():
class NestedTestSchema(Schema):
class Meta:
ordered = True
z = fields.Str()
y = fields.Str()
class TestSchema(Schema):
class Meta:
ordered = True
d = fields.Str()
c = fields.Str()
a = fields.Str()
l = fields.Nested(NestedTestSchema)
# Should be sorting of fields
schema = TestSchema()
json_schema = JSONSchema()
dumped = json_schema.dump(schema)
data = dot_data_backwards_compatible(dumped)
sorted_keys = sorted(data["definitions"]["TestSchema"]["properties"].keys())
properties_names = [k for k in sorted_keys]
assert properties_names == ["a", "c", "d", "l"]
sorted_keys = data["definitions"]["NestedTestSchema"]["properties"].keys()
properties_names = [k for k in sorted_keys]
assert properties_names == ["y", "z"]
# Should be saving ordering of fields
schema = TestSchema()
json_schema = JSONSchema(props_ordered=True)
dumped = json_schema.dump(schema)
data = dot_data_backwards_compatible(dumped)
keys = data["definitions"]["TestSchema"]["properties"].keys()
properties_names = [k for k in keys]
assert properties_names == ["d", "c", "a", "l"]
keys = data["definitions"]["NestedTestSchema"]["properties"].keys()
properties_names = [k for k in keys]
# FIXME: Not ordered
assert properties_names == ["z", "y"]
0xDAFE commented
@fuhrysteve Did you have a chance to take a look at this?