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

Using form parameters in generated API documentation #62

Closed
ognjenk opened this issue Jan 6, 2021 · 7 comments
Closed

Using form parameters in generated API documentation #62

ognjenk opened this issue Jan 6, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@ognjenk
Copy link

ognjenk commented Jan 6, 2021

Hi,
I'm pretty new to API programming so please bear with me.

I am trying to define login endpoint which will take username and password as form parameters, like this:

@router.post("/token")
def get_token(request, username: str = Form(...), password: str = Form(...)):
    return {username: password}

Generated API docs will display endpoint and form parameters correctly, however when I try using the endpoint through the docs it will generate curl like this:

curl -X POST "http://localhost:8000/api/token" -H  "accept: */*" -d ""

and the error I get is code 422 Undocumented | Error: Unprocessable Entity
with response:

{
  "detail": [
    {
      "loc": [
        "form",
        "username"
      ],
      "msg": "field required",
      "type": "value_error.missing"
    },
    {
      "loc": [
        "form",
        "password"
      ],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]

Looks like the parameters and their values are not passed to the generated API call.

If I do a manual curl call like this:

curl -X POST -F 'username=myusername' -F 'password=mypassword' http://localhost:8000/api/token

everything works as expected.
Thanks in advance!

@vitalik
Copy link
Owner

vitalik commented Jan 6, 2021

Hi @ognjenk

Indeed, seems there is a bug in schema for forms - will check it out

Thanks

@vitalik vitalik added the bug Something isn't working label Jan 6, 2021
@ognjenk
Copy link
Author

ognjenk commented Jan 6, 2021

Thanks a lot for the quick response.

Also thanks for creating this project, I haven't spent too much time on it yet, but so far I am loving it!

vitalik added a commit that referenced this issue Jan 7, 2021
@ognjenk
Copy link
Author

ognjenk commented Jan 13, 2021

Hi, just to let you know I have tried this in 0.10.0 release and it works great.
Thanks for the support!

@vitalik
Copy link
Owner

vitalik commented Jan 13, 2021

great!

@vitalik vitalik closed this as completed Jan 13, 2021
@mohannadirshedat
Copy link

HI , @vitalik
I got this issue on version 0.20.0 too

def update_avatar(request, file: UploadedFile = File(...)):
    pass

could you help plz

@vitalik
Copy link
Owner

vitalik commented Feb 5, 2023

@mohannadirshedat which method do you use ?

My guess is that you use PATCH - in this case you need to patch django with this middlewre - #417 (comment)

@baseplate-admin
Copy link
Contributor

Hey @vitalik

Can we put this middleware in the documentation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants