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

Swagger does not reflect changes from the overwritten serializer #688

Open
mglowinski93 opened this issue Aug 25, 2022 · 4 comments
Open

Comments

@mglowinski93
Copy link

mglowinski93 commented Aug 25, 2022

Hi,
I've problem with swagger not being updated after overwriting current_user serializer in settings.

I've modified current_user serializer to be able to update also user's first_name and last_name, like below:

from djoser import serializers


class UserSerializer(serializers.UserSerializer):
    class Meta(serializers.UserSerializer.Meta):
        fields = serializers.UserSerializer.Meta.fields + (
            "first_name",
            "last_name",
        )

Settings:

DJOSER = {
    ...
    "SERIALIZERS": {
        "current_user": "users.serializers.UserSerializer",
    },
}

Those changes are applied to API, but are not reflected in swagger output:
image

Do you have any tip how can i adjust swagger to custom serializer?

@abdelbaki1
Copy link

have you tried to replace the user parameter to your current serializer instead of current-user ?

@mglowinski93
Copy link
Author

mglowinski93 commented Aug 26, 2022

@abdelbaki1
That is for '/users/<user_id>' endpoint, isn't it?
In the end it doesn't matter, since still the same problem :)

@abdelbaki1
Copy link

@mglowinski93
you're right, i didn't pay attention to the get_serializer_class() method conditions.
why don 't you override the retrieve() method of UserViewSet class , try to adjust it according to your situation ?.
I am sorry but it 's the only i can come with it right now .

@mglowinski93
Copy link
Author

mglowinski93 commented Aug 28, 2022

@abdelbaki1
Well, I did not decide to overwrite retrieve method in UserViewSet, since functionality works correctly.
There is only problem with generated swagger.
According to me, it should be generated out of the box.
Since, there are two possibilities:

  1. I did something wrong
  2. there is a bug

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

No branches or pull requests

2 participants