From 801f51a070ab50210477f18e39ddc9a4103c6ad4 Mon Sep 17 00:00:00 2001 From: Vladimir Neverov Date: Tue, 19 Oct 2021 18:35:10 +0300 Subject: [PATCH] Add 'null' type to type list for fields marked as nullable in OpenAPI spec --- openapi2jsonschema/util.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/openapi2jsonschema/util.py b/openapi2jsonschema/util.py index 34270d2..929a385 100644 --- a/openapi2jsonschema/util.py +++ b/openapi2jsonschema/util.py @@ -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) @@ -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