-
Notifications
You must be signed in to change notification settings - Fork 271
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
input request on schema generator shadows actual required request #370
Comments
Looks like #250 might fix this, I'll try it out first |
most recent release should also be fine for testing this, as master does not contain any related changes. at least it looks like #250 addressed this issue. i believe there are still ways to break it so we may have to still iterate. |
Tested on 0.15.1 and this version does not fix it, unfortunately :( it is using the |
It's a tricky one, since you want the input request with the actual authenticated user if you only want to display API documentation they have access to. Perhaps you could grab the
Overriding that setting doesn't work as a workaround, because the mock request function is only called if there's no So I propose:
I'd be fine with just 1. as well, since then I can just provide my own callable |
haha, wishful thinking didn't help. 😄
the solution is most likely something to that effect. i'll also look into it. fyi: you should update in any case as we had dozens of fixes/features since |
I've edited by previous comment, but it seems that we're roughly on the same line :)
done that just now, and it went pretty smooth thanks to |
This is a bug in drf-spectacular, issue created on github: tfranzel/drf-spectacular#370
we now always generate a mocked request, not just when schema is genenerated over CLI. use incoming request as reference if available.
@sergei-maertens the change was a bit more involved, but overall reduced complexity imho. this should now behave exactly as one would supect.
please check if that works for you. |
@sergei-maertens did you have time to give this a try? i would like to have someone else check this before i do a release. |
I haven't had time yet! Maybe next week I can try it out, but no guarantees since I'm involved with other projects atm :P |
@tfranzel just checked out 0.16.0 locally and it appears to work as intended! I'll create a new issue if I spot any new bugs :) |
drf-spectacular/drf_spectacular/generators.py
Line 185 in 8b9d0ca
Note that this is untested on the current master branch, but I believe the same problem exists since the method signature hasn't really changed from 0.12.0 (which I'm on):
This is causing our generated API spec (interactively) to be wrong, because of the different request serializer class based on HTTP method:
When you generate the schema from the CLI, a mock request is present with the correct method, from:
However, if you are using the schema view (hooked up in
urls.py
), thenrequest
inis actually the GET request to
/api
in our case, i.e. the request that fetches/renders the schema.So, we have a mismatch here, because of:
->
method
isPATCH
, butrequest.method
isGET
This causes the API schema to pick up the
AddZaakDocumentSerializer
instead of theUpdateZaakDocumentSerializer
. Of course, we can fix this with@extend_schema
, but that's a bit of a shame.Is there a reason we cannot always use the mock request for schema generation?
The text was updated successfully, but these errors were encountered: