-
Notifications
You must be signed in to change notification settings - Fork 277
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
Inconsistency between [AllowAny] and [] with permission_classes in schema generation #1382
Comments
likely duplicate of #328 tldr, this is a design choice of SwaggerUI and is counter-intuitive. It is correct as is.
check this with: https://editor-next.swagger.io/ |
Found the root cause: swagger-api/swagger-ui#4402 |
maybe you mistyped but you need to have the If you have However, only having |
Yes, correct, only exception would be this icon issue with Swagger UI. But in general, there's an inconsistency between [AllowAny] and [] in the schema generation, and in my opinion omitting the security section should be prefered where possible because it results in a cleaner generated yaml. |
I've renamed the issue after your helpful insight |
Describe the bug
When using AllowAny or IsAuthenticatedOrReadOnly, opening the openapi doc using swagger looks like this:
To Reproduce
Create an APIView or an @api_view that overrides the permission_classes with [AllowAny]
Expected behavior
Instead, the swagger page should look like this for those endpoints, because they don't require any authentication:
Workaround
In Django, omitting AllowAny when it's the only permission_class doesn't change any behavior, but in drf-spectacular fixes this issue and properly displays the open lock icon in swagger.
Insight
I think the issue comes from these lines:
drf-spectacular/drf_spectacular/openapi.py
Lines 365 to 368 in 205f898
where adding {} as schemes has the effect to require auth in swagger
The text was updated successfully, but these errors were encountered: