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

UrlFor fields include all passed params in url. #52

Open
tinproject opened this issue Nov 16, 2016 · 6 comments
Open

UrlFor fields include all passed params in url. #52

tinproject opened this issue Nov 16, 2016 · 6 comments

Comments

@tinproject
Copy link

UrlFor fields use all the passed parameters of the field in construct the url, this makes those fields unsuitable to use with apispec in the same way as other marshmallow fields, or with any information at all.

Example:

    image_url = URLFor(
        endpoint='return_image_file',
        id='<id>',
        required=True,
        description='url location of the image file.',
    )

Result:

"image_url": "/api/image/191.png?description=url+location+of+the+image+file.&required=True",

Perhaps the best way to avoid this is define a new argument in the fields: endpoint_params, for example, to store a dict with all the endpoint parameters. For backward compatibility it can look for the existence of that argument and if exists use the parameters of the dict inside, if not use the parameters of the field as is currently done.

@dhofstetter
Copy link

Totally agree with that ...

Is there a special reason for this behaviour?

@sloria
Copy link
Member

sloria commented Dec 1, 2017

I agree that the current behavior isn't ideal. I would certainly review and merge a PR fixing this. I like @tinproject 's idea of using a different argument to specify url_for arguments. Perhaps it should be named values for consistency with the url_for API.

@dhofstetter
Copy link

Something like that I actually used now within my project, just inherited the existing fields and adding a dict parameter that takes all the arguments for url_for.

That is good so far, and now I'm perfectly fine with defining all the stuff I need to document my stuff as expected without getting this weird params within the url.

@AlrasheedA
Copy link
Contributor

A temporary solution that I followed was using "post_dump" decorator to remove the params. Not an ideal solution but gets the job done. @sloria can you share the relevant PR

@alexschoeberl
Copy link

Any updates on this issue?

@sloria
Copy link
Member

sloria commented Sep 15, 2020

No updates from me. I won't have time to work on this myself in the near future, but I would review and merge a PR implementing the behavior described above.

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

5 participants