Partial serializer should not have required fields (OpenAPI) by denisorehovsky · Pull Request #7563 · encode/django-rest-framework (original) (raw)
@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.