From 5c23b1be6071a6e1d66954b2fef5aeb35a9089ce Mon Sep 17 00:00:00 2001 From: Justin Black Date: Fri, 17 Apr 2020 16:44:26 -0700 Subject: [PATCH 1/4] Fixes getParentName function --- .../org/openapitools/codegen/utils/ModelUtils.java | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java index 8dac545365ae..23dbdc9ea08c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java @@ -1165,14 +1165,6 @@ public static String getParentName(ComposedSchema composedSchema, Map refedWithoutDiscriminator = new ArrayList<>(); - String schemaName = ""; - for (String thisSchemaName : allSchemas.keySet()) { - Schema sc = allSchemas.get(thisSchemaName); - if (isComposedSchema(sc) && (ComposedSchema) sc == composedSchema) { - schemaName = thisSchemaName; - break; - } - } if (interfaces != null && !interfaces.isEmpty()) { for (Schema schema : interfaces) { @@ -1189,10 +1181,7 @@ public static String getParentName(ComposedSchema composedSchema, Map Date: Sat, 18 Apr 2020 21:32:06 -0700 Subject: [PATCH 2/4] Updates getChildrenMap to not throw a NPE --- .../main/java/org/openapitools/codegen/utils/ModelUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java index 23dbdc9ea08c..6dbefe36db49 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java @@ -1104,9 +1104,9 @@ public static Header getHeader(OpenAPI openAPI, String name) { public static Map> getChildrenMap(OpenAPI openAPI) { Map allSchemas = getSchemas(openAPI); - // FIXME: The collect here will throw NPE if a spec document has only a single oneOf hierarchy. Map>> groupedByParent = allSchemas.entrySet().stream() .filter(entry -> isComposedSchema(entry.getValue())) + .filter(entry -> getParentName((ComposedSchema) entry.getValue(), allSchemas)!=null) .collect(Collectors.groupingBy(entry -> getParentName((ComposedSchema) entry.getValue(), allSchemas))); return groupedByParent.entrySet().stream() From 3d3e682afaf6ab73dc2ca12d11df5e3efad8ed3b Mon Sep 17 00:00:00 2001 From: Justin Black Date: Sun, 19 Apr 2020 10:00:22 -0700 Subject: [PATCH 3/4] Updates test --- .../java/org/openapitools/codegen/DefaultCodegenTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index e655027890ed..3eb3c3e62c22 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -612,8 +612,8 @@ public void testAllOfSingleRefWithOwnPropsNoDiscriminator() { Schema schema = openAPI.getComponents().getSchemas().get("MessageEventCoreWithTimeListEntries"); codegen.setOpenAPI(openAPI); CodegenModel model = codegen.fromModel("MessageEventCoreWithTimeListEntries", schema); - Assert.assertEquals(model.parent, "MessageEventCore"); - Assert.assertEquals(model.allParents, Collections.singletonList("MessageEventCore")); + Assert.assertEquals(model.parent, null); + Assert.assertEquals(model.allParents, null); } @Test From 161e7593a6fc9ff258cf726240dc6726d90e9242 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Sun, 19 Apr 2020 11:52:26 -0700 Subject: [PATCH 4/4] Runs ensure up to date --- samples/client/petstore/python-experimental/docs/Child.md | 2 +- samples/client/petstore/python-experimental/docs/Parent.md | 2 +- .../python-experimental/petstore_api/models/child.py | 6 +++--- .../python-experimental/petstore_api/models/parent.py | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/samples/client/petstore/python-experimental/docs/Child.md b/samples/client/petstore/python-experimental/docs/Child.md index f208f06a0593..bc3c7f3922d3 100644 --- a/samples/client/petstore/python-experimental/docs/Child.md +++ b/samples/client/petstore/python-experimental/docs/Child.md @@ -3,9 +3,9 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**inter_net** | **bool** | | [optional] **radio_waves** | **bool** | | [optional] **tele_vision** | **bool** | | [optional] +**inter_net** | **bool** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/docs/Parent.md b/samples/client/petstore/python-experimental/docs/Parent.md index 48d2dc6c78f2..2437d3c81ac9 100644 --- a/samples/client/petstore/python-experimental/docs/Parent.md +++ b/samples/client/petstore/python-experimental/docs/Parent.md @@ -3,8 +3,8 @@ ## Properties Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**tele_vision** | **bool** | | [optional] **radio_waves** | **bool** | | [optional] +**tele_vision** | **bool** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/child.py b/samples/client/petstore/python-experimental/petstore_api/models/child.py index 3d3b71839347..501c22427916 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/child.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/child.py @@ -84,9 +84,9 @@ def openapi_types(): and the value is attribute type. """ return { - 'inter_net': (bool,), # noqa: E501 'radio_waves': (bool,), # noqa: E501 'tele_vision': (bool,), # noqa: E501 + 'inter_net': (bool,), # noqa: E501 } @staticmethod @@ -94,9 +94,9 @@ def discriminator(): return None attribute_map = { - 'inter_net': 'interNet', # noqa: E501 'radio_waves': 'radioWaves', # noqa: E501 'tele_vision': 'teleVision', # noqa: E501 + 'inter_net': 'interNet', # noqa: E501 } required_properties = set([ @@ -127,9 +127,9 @@ def __init__(self, _check_type=True, _from_server=False, _path_to_item=(), _conf deserializing a file_type parameter. If passed, type conversion is attempted If omitted no type conversion is done. - inter_net (bool): [optional] # noqa: E501 radio_waves (bool): [optional] # noqa: E501 tele_vision (bool): [optional] # noqa: E501 + inter_net (bool): [optional] # noqa: E501 """ self._data_store = {} diff --git a/samples/client/petstore/python-experimental/petstore_api/models/parent.py b/samples/client/petstore/python-experimental/petstore_api/models/parent.py index 443b134d1cf3..f62abd94ceed 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/parent.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/parent.py @@ -84,8 +84,8 @@ def openapi_types(): and the value is attribute type. """ return { - 'tele_vision': (bool,), # noqa: E501 'radio_waves': (bool,), # noqa: E501 + 'tele_vision': (bool,), # noqa: E501 } @staticmethod @@ -93,8 +93,8 @@ def discriminator(): return None attribute_map = { - 'tele_vision': 'teleVision', # noqa: E501 'radio_waves': 'radioWaves', # noqa: E501 + 'tele_vision': 'teleVision', # noqa: E501 } required_properties = set([ @@ -125,8 +125,8 @@ def __init__(self, _check_type=True, _from_server=False, _path_to_item=(), _conf deserializing a file_type parameter. If passed, type conversion is attempted If omitted no type conversion is done. - tele_vision (bool): [optional] # noqa: E501 radio_waves (bool): [optional] # noqa: E501 + tele_vision (bool): [optional] # noqa: E501 """ self._data_store = {}