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

Partial serializer should not have required fields (OpenAPI)

Open denisorehovsky opened this issue 4 years ago • 4 comments

denisorehovsky avatar Sep 30 '20 05:09 denisorehovsky

Plaese provide more explanation of this issue - e.g. a link to the relevant decsription in the Open API spec, what issues you're facing, ...

adamchainz avatar Oct 06 '20 10:10 adamchainz

@adamchainz Hi, Adam. Here's the problem. Let's say we have this serializer:

class ExampleSerializer(serializers.Serializer):
    field_a = serializers.CharField()
    field_b = serializers.CharField()

And a ViewSet:

class ExampleViewSet:
    serializer_class = ExampleSerializer

    def partial_update(self, ...):
        pass

Since the request is partial, all the fields are not required. In a request body, we can send:

  • Only field_a
  • Only field_b
  • Both field_a and field_b

And it should work. However, DRF's OpenAPI generated documentation will show that both field_a and field_b are required, even though they're not.

denisorehovsky avatar Oct 06 '20 10:10 denisorehovsky

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 01 '22 08:05 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 12 '22 01:08 stale[bot]

@adamchainz So what do you think?

denisorehovsky avatar Oct 16 '22 03:10 denisorehovsky

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 16 '22 09:12 stale[bot]

can you please share the relevant part of the spec to verify?

auvipy avatar Dec 17 '22 16:12 auvipy

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 18 '23 04:02 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 12 '23 22:08 stale[bot]