-
-
Notifications
You must be signed in to change notification settings - Fork 7k
fix(obtain_auth_token): Fix openapi schema generation #7211
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
fix(obtain_auth_token): Fix openapi schema generation #7211
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, fair, enough. Just one comment:
rest_framework/authtoken/views.py
Outdated
|
||
|
||
class ObtainAuthToken(APIView): | ||
class ObtainAuthToken(GenericAPIView): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this, can you just define get_serializer()
, and then use that in post()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely! This is done :)
9e56c8d
to
b39bde5
Compare
fix(ObtainAuthToken): Fix openapi response type fix(ObtainAuthToken): Use APIView and define get_serializer fix test
b39bde5
to
cb1f762
Compare
Thanks again @gnuletik! Great effort 🔥 |
It's a pleasure :) |
This fix breaks my login view implementation:
AttributeError: 'ObtainAuthToken' object has no attribute 'request' |
This PR fixes the AutoSchema generation for the
obtain_auth_token
view.Here is the invalid (partial) OpenAPI schema currently generated.
As you can see the requestBody's schema and response's schema are empty.
This is because:
ObtainAuthToken
class inherit fromrest_framework.views.APIView
which do not have aget_serializer
method (this is what is used by therest_framework.schemas.openapi.AutoSchema
class to get the serializer).AuthTokenSerializer
did not had the token field.With this PR, the generated schema is
NB: In the
ObtainAuthToken
class, the schema field (ManualSchema
, forcoreapi
only) was override when thecoreapi
dependency was installed.Instead of checking the installed dependency, I replaced the check with
coreapi_schema.is_enabled
.This change enables us to run the test script (where
coreapi
is installed) with the AutoSchema, unlesscoreapi
is explicitly configured.