Open zahraaalizadeh opened 4 months ago
Hi, this is actually intended behavior as it closely resembles what DRF is actually doing. On response, those "not required" fields are basically always present. The required
property of DRF refers rather to the request than the response.
Turn of the heuristic with setting the var True
:
True! Thanks for the clue!
Describe the bug Read-only fields in serializers are being marked as required in the generated OpenAPI schema, even when explicitly defined with
read_only=True
andrequired=False
.To Reproduce Steps to reproduce the behavior:
Using DRF Spectacular to generate the schema results in
message
andstatus
being marked as required, even though they are explicitly defined withread_only=True
andrequired=False
.Expected behavior Read-only fields on the response should not be marked as required in the generated OpenAPI schema. The fields should be optional in the schema, reflecting their
read_only=True
andrequired=False
status.