From 0f8e7c6581b2e3717a0abd26ee9fd3d74a5a4a21 Mon Sep 17 00:00:00 2001 From: Gareth Rushgrove Date: Sun, 4 Aug 2019 19:12:23 +0100 Subject: [PATCH] Fix catching too broad a set of fields Only need to expand type fields, not everything. --- openapi2jsonschema/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openapi2jsonschema/util.py b/openapi2jsonschema/util.py index 1250f70..34270d2 100644 --- a/openapi2jsonschema/util.py +++ b/openapi2jsonschema/util.py @@ -61,12 +61,12 @@ def allow_null_optional_fields(data, parent=None, grand_parent=None, key=None): for x in v: new_v.append(allow_null_optional_fields(x, v, parent, k)) elif isinstance(v, str): - is_null = k == "type" and v == "null" + is_non_null_type = k == "type" and v != "null" has_required_fields = grand_parent and "required" in grand_parent is_required_field = ( has_required_fields and key in grand_parent["required"] ) - if not is_null and not is_required_field: + if is_non_null_type and not is_required_field: new_v = [v, "null"] new[k] = new_v return new