Skip to content

Commit 0a78374

Browse files
committed
Better oneOf generation
1 parent 229baea commit 0a78374

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

.generator/src/generator/templates/modelOneOf.j2

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,12 @@ public class {{ name }} extends AbstractOpenApiSchema {
144144
{%- set param_type = get_type(oneOf) %}
145145
{%- set unparam_type = param_type|un_parameterize_type %}
146146
{%- if unparam_type in constructor_sigs %}
147+
{%- if param_type.startswith('List<') %}
148+
{%- set inner_type = param_type[5:-1] %}
149+
public static {{ name }} from{{ inner_type }}List({{ param_type }} o) {
150+
{%- else %}
147151
public static {{ name }} from{{ param_type.replace('<', '').replace('>', '').replace(' ', '').replace(',', '') }}({{ param_type }} o) {
152+
{%- endif %}
148153
{{ name }} instance = new {{ name }}();
149154
instance.setActualInstance(o);
150155
return instance;
@@ -216,16 +221,28 @@ public class {{ name }} extends AbstractOpenApiSchema {
216221
return super.getActualInstance();
217222
}
218223

219-
{%- set method_names = [] %}
224+
{%- set unparam_types = [] %}
225+
{%- for oneOf in model.oneOf %}
226+
{%- set unparam_type = get_type(oneOf)|un_parameterize_type %}
227+
{%- set _ = unparam_types.append(unparam_type) %}
228+
{%- endfor %}
229+
220230
{%- for oneOf in model.oneOf %}
221231
{%- set dataType = get_type(oneOf) %}
222232
{%- set unParameterizedDataType = get_type(oneOf)|un_parameterize_type %}
223-
{%- set method_name = "get" + unParameterizedDataType %}
224-
{%- if method_name in method_names %}
233+
{%- set base_method_name = "get" + unParameterizedDataType %}
234+
235+
{%- if unparam_types.count(unParameterizedDataType) > 1 %}
236+
{%- if dataType.startswith('List<') %}
237+
{%- set inner_type = dataType[5:-1] %}
238+
{%- set method_name = "get" + inner_type + "List" %}
239+
{%- else %}
225240
{%- set safe_type = dataType.replace('<', '').replace('>', '').replace(' ', '').replace(',', '') %}
226241
{%- set method_name = "get" + safe_type %}
227242
{%- endif %}
228-
{%- set _ = method_names.append(method_name) %}
243+
{%- else %}
244+
{%- set method_name = base_method_name %}
245+
{%- endif %}
229246

230247
/**
231248
* Get the actual instance of `{{ dataType|escape_html }}`. If the actual instance is not `{{ dataType|escape_html }}`,

0 commit comments

Comments
 (0)