-
Notifications
You must be signed in to change notification settings - Fork 270
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
Wrapping serializer data in a response dict #463
Comments
Hi, this is a special have we have dealt with before in issue #49 there is a relatively elegant workaround for these cases: drf-spectacular/tests/test_regressions.py Line 698 in eb02752
for a global solution i would have to give it some more thought |
closing this issue for now. feel free to comment if anything is missing or not working and we will follow-up. |
I am also interested in a general solution to this. I have seen #49 |
This should get you pretty close. The enveloper helper is exactly the same. You just need to write a custom Remember to change from drf_spectacular.plumbing import get_class
def enveloper(serializer_class, many):
component_name = 'Enveloped{}{}'.format(
serializer_class.__name__.replace("Serializer", ""),
"List" if many else "",
)
@extend_schema_serializer(many=False, component_name=component_name)
class EnvelopeSerializer(serializers.Serializer):
status = serializers.BooleanField() # some arbitrary envelope field
data = serializer_class(many=many) # the enveloping part
return EnvelopeSerializer
class CustomAutoSchema(AutoSchema):
def get_response_serializers(self):
""" use envelope on all default responses. @extend_schema will override this change """
serializer_class = get_class(self._get_serializer())
return enveloper(
serializer_class=serializer_class,
many=self._is_list_view(serializer_class)
) |
Thank you! Very helpful A+ |
@tfranzel The enveloper works properly. But it is missing the paginated response. Outer fields are properly shown, but the paginated answer is missing. May be because of explicitly mentioned the Respose i need
Response i getting
|
Hi,
Most of our views return the following results in the following format:
What's the best way to include that in the generated schema? I was able to do it via inline_serializer, but is there a way to do it en masse? Like, via a setting that says surround all returned serializers in another serializer.
The text was updated successfully, but these errors were encountered: