Skip to content

Commit

Permalink
JSONField may also be a non-object/primitive #1095
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzel committed Nov 2, 2023
1 parent 41fef03 commit edce053
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
4 changes: 2 additions & 2 deletions drf_spectacular/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def _map_model_field(self, model_field, direction):
return self._map_model_field(model_field.target_field, direction)
elif hasattr(models, 'JSONField') and isinstance(model_field, models.JSONField):
# fix for DRF==3.11 with django>=3.1 as it is not yet represented in the field_mapping
return build_basic_type(OpenApiTypes.OBJECT)
return build_basic_type(OpenApiTypes.ANY)
elif isinstance(model_field, models.BinaryField):
return build_basic_type(OpenApiTypes.BYTE)
elif hasattr(models, model_field.get_internal_type()):
Expand Down Expand Up @@ -847,7 +847,7 @@ def _map_serializer_field(self, field, direction, bypass_extensions=False):
return append_meta(build_basic_type(OpenApiTypes.BOOL), meta)

if isinstance(field, serializers.JSONField):
return append_meta(build_basic_type(OpenApiTypes.OBJECT), meta)
return append_meta(build_basic_type(OpenApiTypes.ANY), meta)

if isinstance(field, (serializers.DictField, serializers.HStoreField)):
content = build_basic_type(OpenApiTypes.OBJECT)
Expand Down
4 changes: 1 addition & 3 deletions tests/test_extend_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,7 @@ components:
type: string
field_b:
type: integer
field_c:
type: object
additionalProperties: {}
field_c: {}
required:
- field_a
- field_b
Expand Down
4 changes: 1 addition & 3 deletions tests/test_fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@ components:
type: object
additionalProperties:
type: integer
field_json:
type: object
additionalProperties: {}
field_json: {}
field_sub_object_calculated:
type: integer
description: My calculated property
Expand Down

0 comments on commit edce053

Please sign in to comment.