Skip to content

Maintain order in which methods are added to endpoint #189

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

Merged
merged 2 commits into from
Apr 4, 2018
Merged

Maintain order in which methods are added to endpoint #189

merged 2 commits into from
Apr 4, 2018

Conversation

lafrech
Copy link
Member

@lafrech lafrech commented Mar 29, 2018

Similar to #86 and #87.

@lafrech lafrech changed the title Dev endpoint method order Maintain endpoint method order Mar 29, 2018
@lafrech lafrech changed the title Maintain endpoint method order Maintain order in which methods are added to endpoint Mar 29, 2018
@lafrech lafrech changed the title Maintain order in which methods are added to endpoint WIP - Maintain order in which methods are added to endpoint Apr 4, 2018
@lafrech lafrech changed the title WIP - Maintain order in which methods are added to endpoint Maintain order in which methods are added to endpoint Apr 4, 2018
@lafrech
Copy link
Member Author

lafrech commented Apr 4, 2018

Rebasing this on #190 assuming it would be merged as is. If not, I'll rebase again.

This change is useful to me because I'm enforcing the order of the methods for each endpoint in the spec:

['OPTIONS', 'HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'TRACE']

I find it nice to have a consistent method order.

It works because I'm iterating on the methods in my lib, not in apispec.


For people using apispec.ext.flask.path_from_view, it would take another modification in there:

HTTP_METHODS = ['OPTIONS', 'HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'TRACE']

def path_from_view(spec, view, **kwargs):
    [...]
    operations = OrderedDict()
    for method in HTTP_METHODS:
        if method in view.methods and method in rule.methods:
            [...]

Likewise for tornado and the others.

This means hardcoding the method order. The user could mutate the global method list to control the order, though.

I think this can be done in another PR without holding this one.

@sloria
Copy link
Member

sloria commented Apr 4, 2018

Thanks @lafrech . #190 is merged, but it looks like this needs to be rebased one more time. Also, would you mind opening an issue for the Flask/Tornado issue you mentioned?

@lafrech
Copy link
Member Author

lafrech commented Apr 4, 2018

Great. I just rebased and opened #193.

@sloria sloria merged commit ea55ad0 into marshmallow-code:dev Apr 4, 2018
@lafrech lafrech deleted the dev_endpoint_method_order branch April 5, 2018 07:10
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

Successfully merging this pull request may close these issues.

2 participants