axnsan12 / drf-yasg

Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.
https://drf-yasg.readthedocs.io/en/stable/
Other
3.42k stars 438 forks source link

swagger_schema_fields examples in nested serializers #365

Open K0Te opened 5 years ago

K0Te commented 5 years ago

Hi,

At the moment drf-yasg uses swagger_schema_fields->example only from top-level serializer, so that child's serializers examples are lost. Thus code duplication is required for full example documentation in case of nested serializers. Is it possible to change behavior, so that parent serializers swagger_schema_fields would be extended with child's ones, unless matching field is explicitly set ? I will be happy to create PR for this change.

axnsan12 commented 5 years ago

Nested serializers probably work just fine, but it's the swagger UI that only shows the example object of the root model on the request. If you look in the models section at the nested serializers you should also see its example.

Is it possible to change behavior, so that parent serializers swagger_schema_fields would be extended with child's ones

While it might make sense for the particular case of example, I don't think it would be a good idea in general..