django-rest-swagger icon indicating copy to clipboard operation
django-rest-swagger copied to clipboard

Nested serialization shown as string in Swagger UI

Open korbinianfritsch opened this issue 7 years ago • 5 comments

I am currently on 2.1.2 and experiencing an issue very much alike https://github.com/marcgibbons/django-rest-swagger/issues/568 and https://github.com/marcgibbons/django-rest-swagger/issues/663.

# serializers.py

class NestedObjectSerializer(serializers.Serializer):

    key = serializers.CharField(
        max_length=200,
    )
    value = serializers.DecimalField(
        max_digits=3,
        decimal_places=2,
    )


class RequestSerializer(serializers.Serializer):

    dictionary = serializers.DictField()
    nested_object = NestedObjectSerializer(
        many=True,
    )
# views.py

class SomeView(GenericAPIView):

    permission_classes = []
    serializer_class = RequestSerializer

    def post(self, request):
        request_serializer = RequestSerializer(data=request.data)
        request_serializer.is_valid(raise_exception=True)

        ...

        return Response(response_serializer.data)

Although I am using a DictField in the Request Serializer, Swagger UI shows the data type of the field as string in both the Model & Example Value:

# Swagger UI

{                           |
  "dictionary": "string",   |   inline_model {
  "nested_object": [        |     lead_profile (string): ,
    "string"                |     data_point_requests (Array[string]):
  ]                         |   }
}                           |   

Same applies for the nested serialized object.

I am thankful for any hints!

korbinianfritsch avatar Jun 27 '17 19:06 korbinianfritsch

Today I digged a little deeper into this and found out that both OpenAPI Codec and CoreJSON Codec do not support this although schemas are generated correctly by SchemaGenerator, so I assume this is not an issue that can be resolved within the scope of this project.

korbinianfritsch avatar Jun 30 '17 14:06 korbinianfritsch

I experience the same Problem. @korbinianfritsch this might seam out of scope but none the less it should be fixed somehow, because projects need the depiction of cross table relations in the docs.

+1

chgad avatar Sep 15 '17 16:09 chgad

Since this project seems dead I made an attempt at rolling my own to solve this and other problems I encountered... see here https://github.com/axnsan12/drf-yasg/ 😄

axnsan12 avatar Dec 13 '17 10:12 axnsan12

Is there any updates regarding this issue?

mhamzawey avatar Oct 14 '18 11:10 mhamzawey

any update on this ?

Ali-aqrabawi avatar Oct 23 '18 12:10 Ali-aqrabawi