Skip to content

Commit

Permalink
Merge pull request #2 from vne/handle-nullable-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
henrycjc authored Dec 21, 2021
2 parents 03ad71b + 801f51a commit 9631d8f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions openapi2jsonschema/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def allow_null_optional_fields(data, parent=None, grand_parent=None, key=None):
def change_dict_values(d, prefix, version):
new = {}
try:
is_nullable = False
for k, v in iteritems(d):
if k == 'nullable':
is_nullable = True
new_v = v
if isinstance(v, dict):
new_v = change_dict_values(v, prefix, version)
Expand All @@ -94,6 +97,10 @@ def change_dict_values(d, prefix, version):
else:
new_v = v
new[k] = new_v
if is_nullable and 'type' in new:
if not isinstance(new['type'], list):
new['type'] = [new['type']]
new['type'].append('null')
return new
except AttributeError:
return d
Expand Down

0 comments on commit 9631d8f

Please sign in to comment.