Skip to content

Commit 8ce0b15

Browse files
committed
fix oneof methods name
When there is a oneof with at least two similar type, ie List<string> and List<int> this cause some conflict.
1 parent 5f14d29 commit 8ce0b15

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,28 @@ public class {{ name }} extends AbstractOpenApiSchema {
139139
super("oneOf", Boolean.{{ "TRUE" if model.nullable else "FALSE" }});
140140
}
141141

142+
{%- set constructor_sigs = [] %}
142143
{%- for oneOf in model.oneOf %}
143-
public {{ name }}({{ get_type(oneOf) }} o) {
144+
{%- set param_type = get_type(oneOf) %}
145+
{%- set unparam_type = param_type|un_parameterize_type %}
146+
{%- 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 %}
151+
public static {{ name }} from{{ param_type.replace('<', '').replace('>', '').replace(' ', '').replace(',', '') }}({{ param_type }} o) {
152+
{%- endif %}
153+
{{ name }} instance = new {{ name }}();
154+
instance.setActualInstance(o);
155+
return instance;
156+
}
157+
{%- else %}
158+
{%- set _ = constructor_sigs.append(unparam_type) %}
159+
public {{ name }}({{ param_type }} o) {
144160
super("oneOf", Boolean.{{ "TRUE" if model.nullable else "FALSE" }});
145161
setActualInstance(o);
146162
}
163+
{%- endif %}
147164
{%- endfor %}
148165

149166
static {
@@ -204,9 +221,28 @@ public class {{ name }} extends AbstractOpenApiSchema {
204221
return super.getActualInstance();
205222
}
206223

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+
207230
{%- for oneOf in model.oneOf %}
208231
{%- set dataType = get_type(oneOf) %}
209232
{%- set unParameterizedDataType = get_type(oneOf)|un_parameterize_type %}
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 %}
240+
{%- set safe_type = dataType.replace('<', '').replace('>', '').replace(' ', '').replace(',', '') %}
241+
{%- set method_name = "get" + safe_type %}
242+
{%- endif %}
243+
{%- else %}
244+
{%- set method_name = base_method_name %}
245+
{%- endif %}
210246

211247
/**
212248
* Get the actual instance of `{{ dataType|escape_html }}`. If the actual instance is not `{{ dataType|escape_html }}`,
@@ -215,7 +251,7 @@ public class {{ name }} extends AbstractOpenApiSchema {
215251
* @return The actual instance of `{{ dataType|escape_html }}`
216252
* @throws ClassCastException if the instance is not `{{ dataType|escape_html }}`
217253
*/
218-
public {{ dataType }} get{{ unParameterizedDataType }}() throws ClassCastException {
254+
public {{ dataType }} {{ method_name }}() throws ClassCastException {
219255
return ({{ dataType }})super.getActualInstance();
220256
}
221257

0 commit comments

Comments
 (0)