Skip to content

Commit

Permalink
Fixes issue 5876 (#5977)
Browse files Browse the repository at this point in the history
* Fixes getParentName function

* Updates getChildrenMap to not throw a NPE

* Updates test

* Runs ensure up to date
  • Loading branch information
spacether authored Apr 20, 2020
1 parent 4818644 commit 1766279
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1104,9 +1104,9 @@ public static Header getHeader(OpenAPI openAPI, String name) {
public static Map<String, List<String>> getChildrenMap(OpenAPI openAPI) {
Map<String, Schema> allSchemas = getSchemas(openAPI);

// FIXME: The collect here will throw NPE if a spec document has only a single oneOf hierarchy.
Map<String, List<Entry<String, Schema>>> 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()
Expand Down Expand Up @@ -1165,14 +1165,6 @@ public static String getParentName(ComposedSchema composedSchema, Map<String, Sc
int nullSchemaChildrenCount = 0;
boolean hasAmbiguousParents = false;
List<String> 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) {
Expand All @@ -1189,10 +1181,7 @@ public static String getParentName(ComposedSchema composedSchema, Map<String, Sc
} else {
// not a parent since discriminator.propertyName is not set
hasAmbiguousParents = true;
boolean isNotExtractedInlineSchema = !parentName.equals(schemaName+"_allOf");
if (isNotExtractedInlineSchema) {
refedWithoutDiscriminator.add(parentName);
}
refedWithoutDiscriminator.add(parentName);
}
} else {
// not a ref, doing nothing, except counting the number of times the 'null' type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/python-experimental/docs/Child.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/python-experimental/docs/Parent.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ 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
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([
Expand Down Expand Up @@ -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 = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ 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
def discriminator():
return None

attribute_map = {
'tele_vision': 'teleVision', # noqa: E501
'radio_waves': 'radioWaves', # noqa: E501
'tele_vision': 'teleVision', # noqa: E501
}

required_properties = set([
Expand Down Expand Up @@ -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 = {}
Expand Down

0 comments on commit 1766279

Please sign in to comment.