Skip to content

Commit

Permalink
Merge branch 'pr1139'
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzel committed Jan 6, 2024
2 parents d275fcf + 691ac46 commit aeca119
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
3 changes: 0 additions & 3 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,3 @@ With that out of the way, we hope to hear from you soon.
.. _blueprints: https://drf-spectacular.readthedocs.io/en/latest/blueprints.html
.. _early feedback: https://github.com/tfranzel/drf-spectacular/issues
.. _test_regressions.py: https://github.com/tfranzel/drf-spectacular/blob/master/tests/test_regressions.py



2 changes: 1 addition & 1 deletion drf_spectacular/plumbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def append_meta(schema: _SchemaType, meta: _SchemaType) -> _SchemaType:
schema = {'oneOf': [schema, {'type': 'null'}]}
elif len(schema) == 1 and 'oneOf' in schema:
schema['oneOf'].append({'type': 'null'})
elif not schema and not meta:
elif not schema:
schema = {'oneOf': [{}, {'type': 'null'}]}
else:
assert False, 'Invalid nullable case' # pragma: no cover
Expand Down
2 changes: 2 additions & 0 deletions tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3267,6 +3267,7 @@ def view_func(request, format=None):
def test_basic_oas_3_1_nullable_cases(no_warnings, django_transforms):
class M14(models.Model):
field_json = models.JSONField(null=True) # case 1
field_json2 = models.JSONField(null=True, help_text="field_json desc") # case 3

class XSerializer(serializers.ModelSerializer):

Expand All @@ -3287,6 +3288,7 @@ class XViewset(viewsets.ReadOnlyModelViewSet):
assert schema['components']['schemas']['X']['properties'] == {
'id': {'readOnly': True, 'type': 'integer'},
'field_json': {'oneOf': [{}, {'type': 'null'}]},
'field_json2': {'oneOf': [{}, {'type': 'null'}], 'description': 'field_json desc'},
'field_method_hint': {
'oneOf': [
{'type': 'integer'},
Expand Down

0 comments on commit aeca119

Please sign in to comment.