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

Schema field Order is alphabetical, instead of using Marshmallow's order #782

Closed
mkmoisen opened this issue Jul 30, 2022 · 2 comments
Closed
Labels

Comments

@mkmoisen
Copy link

In Marshmallow, you can order the fields by using class Meta: ordered = True, like:

class FooSchema(Schema):
    b = fields.Int()
    a = fields.int()
    class Meta:
        ordered = True

for k in FooSchema.fields():
    print(k)

This will output:

b
a

However, the schema generated by apispec ordered the fields alphabetically.

Shouldn't it default to Marshmallow's natural order?

Is there any workaround to get the fields ordered correctly?

Thank you.

@lafrech
Copy link
Member

lafrech commented Aug 8, 2022

apispec respects schema order.

You may want to double-check your code doesn't force alphabetical order (for instance, by default, Flask sorts keys when serializing json).

@lafrech
Copy link
Member

lafrech commented Sep 13, 2022

Closing for lack of feedback. Free free to bring additional details in comments.

@lafrech lafrech closed this as completed Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants