forked from loafle/openapi-generator-original
Fixes issue 5876 (#5977)
* Fixes getParentName function * Updates getChildrenMap to not throw a NPE * Updates test * Runs ensure up to date
This commit is contained in:
parent
4818644278
commit
1766279916
@ -1104,9 +1104,9 @@ public class ModelUtils {
|
|||||||
public static Map<String, List<String>> getChildrenMap(OpenAPI openAPI) {
|
public static Map<String, List<String>> getChildrenMap(OpenAPI openAPI) {
|
||||||
Map<String, Schema> allSchemas = getSchemas(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()
|
Map<String, List<Entry<String, Schema>>> groupedByParent = allSchemas.entrySet().stream()
|
||||||
.filter(entry -> isComposedSchema(entry.getValue()))
|
.filter(entry -> isComposedSchema(entry.getValue()))
|
||||||
|
.filter(entry -> getParentName((ComposedSchema) entry.getValue(), allSchemas)!=null)
|
||||||
.collect(Collectors.groupingBy(entry -> getParentName((ComposedSchema) entry.getValue(), allSchemas)));
|
.collect(Collectors.groupingBy(entry -> getParentName((ComposedSchema) entry.getValue(), allSchemas)));
|
||||||
|
|
||||||
return groupedByParent.entrySet().stream()
|
return groupedByParent.entrySet().stream()
|
||||||
@ -1165,14 +1165,6 @@ public class ModelUtils {
|
|||||||
int nullSchemaChildrenCount = 0;
|
int nullSchemaChildrenCount = 0;
|
||||||
boolean hasAmbiguousParents = false;
|
boolean hasAmbiguousParents = false;
|
||||||
List<String> refedWithoutDiscriminator = new ArrayList<>();
|
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()) {
|
if (interfaces != null && !interfaces.isEmpty()) {
|
||||||
for (Schema schema : interfaces) {
|
for (Schema schema : interfaces) {
|
||||||
@ -1189,10 +1181,7 @@ public class ModelUtils {
|
|||||||
} else {
|
} else {
|
||||||
// not a parent since discriminator.propertyName is not set
|
// not a parent since discriminator.propertyName is not set
|
||||||
hasAmbiguousParents = true;
|
hasAmbiguousParents = true;
|
||||||
boolean isNotExtractedInlineSchema = !parentName.equals(schemaName+"_allOf");
|
refedWithoutDiscriminator.add(parentName);
|
||||||
if (isNotExtractedInlineSchema) {
|
|
||||||
refedWithoutDiscriminator.add(parentName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// not a ref, doing nothing, except counting the number of times the 'null' type
|
// not a ref, doing nothing, except counting the number of times the 'null' type
|
||||||
|
@ -612,8 +612,8 @@ public class DefaultCodegenTest {
|
|||||||
Schema schema = openAPI.getComponents().getSchemas().get("MessageEventCoreWithTimeListEntries");
|
Schema schema = openAPI.getComponents().getSchemas().get("MessageEventCoreWithTimeListEntries");
|
||||||
codegen.setOpenAPI(openAPI);
|
codegen.setOpenAPI(openAPI);
|
||||||
CodegenModel model = codegen.fromModel("MessageEventCoreWithTimeListEntries", schema);
|
CodegenModel model = codegen.fromModel("MessageEventCoreWithTimeListEntries", schema);
|
||||||
Assert.assertEquals(model.parent, "MessageEventCore");
|
Assert.assertEquals(model.parent, null);
|
||||||
Assert.assertEquals(model.allParents, Collections.singletonList("MessageEventCore"));
|
Assert.assertEquals(model.allParents, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
## Properties
|
## Properties
|
||||||
Name | Type | Description | Notes
|
Name | Type | Description | Notes
|
||||||
------------ | ------------- | ------------- | -------------
|
------------ | ------------- | ------------- | -------------
|
||||||
**inter_net** | **bool** | | [optional]
|
|
||||||
**radio_waves** | **bool** | | [optional]
|
**radio_waves** | **bool** | | [optional]
|
||||||
**tele_vision** | **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)
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
## Properties
|
## Properties
|
||||||
Name | Type | Description | Notes
|
Name | Type | Description | Notes
|
||||||
------------ | ------------- | ------------- | -------------
|
------------ | ------------- | ------------- | -------------
|
||||||
**tele_vision** | **bool** | | [optional]
|
|
||||||
**radio_waves** | **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)
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
@ -84,9 +84,9 @@ class Child(ModelComposed):
|
|||||||
and the value is attribute type.
|
and the value is attribute type.
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
'inter_net': (bool,), # noqa: E501
|
|
||||||
'radio_waves': (bool,), # noqa: E501
|
'radio_waves': (bool,), # noqa: E501
|
||||||
'tele_vision': (bool,), # noqa: E501
|
'tele_vision': (bool,), # noqa: E501
|
||||||
|
'inter_net': (bool,), # noqa: E501
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -94,9 +94,9 @@ class Child(ModelComposed):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
attribute_map = {
|
attribute_map = {
|
||||||
'inter_net': 'interNet', # noqa: E501
|
|
||||||
'radio_waves': 'radioWaves', # noqa: E501
|
'radio_waves': 'radioWaves', # noqa: E501
|
||||||
'tele_vision': 'teleVision', # noqa: E501
|
'tele_vision': 'teleVision', # noqa: E501
|
||||||
|
'inter_net': 'interNet', # noqa: E501
|
||||||
}
|
}
|
||||||
|
|
||||||
required_properties = set([
|
required_properties = set([
|
||||||
@ -127,9 +127,9 @@ class Child(ModelComposed):
|
|||||||
deserializing a file_type parameter.
|
deserializing a file_type parameter.
|
||||||
If passed, type conversion is attempted
|
If passed, type conversion is attempted
|
||||||
If omitted no type conversion is done.
|
If omitted no type conversion is done.
|
||||||
inter_net (bool): [optional] # noqa: E501
|
|
||||||
radio_waves (bool): [optional] # noqa: E501
|
radio_waves (bool): [optional] # noqa: E501
|
||||||
tele_vision (bool): [optional] # noqa: E501
|
tele_vision (bool): [optional] # noqa: E501
|
||||||
|
inter_net (bool): [optional] # noqa: E501
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._data_store = {}
|
self._data_store = {}
|
||||||
|
@ -84,8 +84,8 @@ class Parent(ModelComposed):
|
|||||||
and the value is attribute type.
|
and the value is attribute type.
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
'tele_vision': (bool,), # noqa: E501
|
|
||||||
'radio_waves': (bool,), # noqa: E501
|
'radio_waves': (bool,), # noqa: E501
|
||||||
|
'tele_vision': (bool,), # noqa: E501
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -93,8 +93,8 @@ class Parent(ModelComposed):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
attribute_map = {
|
attribute_map = {
|
||||||
'tele_vision': 'teleVision', # noqa: E501
|
|
||||||
'radio_waves': 'radioWaves', # noqa: E501
|
'radio_waves': 'radioWaves', # noqa: E501
|
||||||
|
'tele_vision': 'teleVision', # noqa: E501
|
||||||
}
|
}
|
||||||
|
|
||||||
required_properties = set([
|
required_properties = set([
|
||||||
@ -125,8 +125,8 @@ class Parent(ModelComposed):
|
|||||||
deserializing a file_type parameter.
|
deserializing a file_type parameter.
|
||||||
If passed, type conversion is attempted
|
If passed, type conversion is attempted
|
||||||
If omitted no type conversion is done.
|
If omitted no type conversion is done.
|
||||||
tele_vision (bool): [optional] # noqa: E501
|
|
||||||
radio_waves (bool): [optional] # noqa: E501
|
radio_waves (bool): [optional] # noqa: E501
|
||||||
|
tele_vision (bool): [optional] # noqa: E501
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._data_store = {}
|
self._data_store = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user