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

rest-auth responses #113

Closed
jayvdb opened this issue Jul 8, 2020 · 2 comments · Fixed by #125
Closed

rest-auth responses #113

jayvdb opened this issue Jul 8, 2020 · 2 comments · Fixed by #125

Comments

@jayvdb
Copy link
Contributor

jayvdb commented Jul 8, 2020

Likely rest-auth will be full of oddities, because it is highly configurable, and also it interfaces with other highly configurable apps.

Note there is a very serious fork at https://github.com/jazzband/dj-rest-auth - I expect we and many ppl will switch soon, and I am also expecting there to be a lot of similarities, so many of fixers will likely be common, but in this case (unlike drf-jwt), the package module name was modified.

Excerpt below for one fixer.

Note UserSerializer in it isnt included as mine is local in the same file - that would be another fetch from a settings module.

from django.conf import settings as global_settings

from allauth.account import app_settings as allauth_settings

from rest_auth.serializers import JWTSerializer, TokenSerializer

from rest_framework import serializers


class SignupResponseSerializer(serializers.Serializer):
    if allauth_settings.EMAIL_VERIFICATION == \
                allauth_settings.EmailVerificationMethod.MANDATORY:
        detail = serializers.CharField(read_only=True, required=False)
    else:
        user = UserSerializer(read_only=True)
        if getattr(global_settings, 'REST_USE_JWT', False):
            token = JWTSerializer(read_only=True)
        else:
            token = TokenSerializer(read_only=True)

class OpenAPI_Fix_RestAuth_Registration(OpenApiViewExtension):
    target_class = 'rest_auth.registration.views.RegisterView'

    def view_replacement(self):

        class Fixed(self.target_class):

            @extend_schema(
                responses=SignupResponseSerializer,
            )
            def post(self, request, *args, **kwargs):
                pass

        return Fixed
@jayvdb
Copy link
Contributor Author

jayvdb commented Jul 11, 2020

#119 is relevant here, as the detail field used throughout rest-auth is "piggy-backing" on the DRF core default response structure.

@jayvdb jayvdb changed the title rest-auth registration response rest-auth responses Jul 14, 2020
@jayvdb
Copy link
Contributor Author

jayvdb commented Jul 14, 2020

rest_auth.views.LogoutView and rest_auth.registration.views.VerifyEmailView also both have responses of only the DRF core default response field detail.

LoginView has a method get_response_serializer, which returns JWTSerializer or TokenSerializer, similar to RegisterView/SignupResponseSerializer above. That method only exists on that one class.
However it is copied a lot. If generically supported, we'd need to be careful as that name is also used (slightly differently) by other apps such as drf-crud-proxy.

jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue Jul 14, 2020
jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue Jul 14, 2020
jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue Jul 14, 2020
jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue Jul 14, 2020
jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue Jul 14, 2020
jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue Jul 14, 2020
jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue Jul 14, 2020
Dark-217 added a commit to Dark-217/drf-spectacular that referenced this issue Oct 7, 2024
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

Successfully merging a pull request may close this issue.

1 participant