Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

props_ordered does not work for nested fields #109

Open
0xDAFE opened this issue Mar 16, 2020 · 1 comment
Open

props_ordered does not work for nested fields #109

0xDAFE opened this issue Mar 16, 2020 · 1 comment

Comments

@0xDAFE
Copy link

0xDAFE commented Mar 16, 2020

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
Copy link
Author

0xDAFE commented Jun 15, 2020

@fuhrysteve Did you have a chance to take a look at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant