Skip to content

Commit 189fe4d

Browse files
haraldFMikailBag
authored andcommitted
Escape clashing model names (OpenAPITools#6004)
Closes OpenAPITools#6002
1 parent 550c4b9 commit 189fe4d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java

+15
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,24 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
235235
this.updateOperationParameterEnumInformation(operations);
236236
this.addOperationObjectResponseInformation(operations);
237237
this.addOperationPrefixParameterInterfacesInformation(operations);
238+
this.escapeOperationIds(operations);
238239
return operations;
239240
}
240241

242+
private void escapeOperationIds(Map<String, Object> operations) {
243+
Map<String, Object> _operations = (Map<String, Object>) operations.get("operations");
244+
List<CodegenOperation> operationList = (List<CodegenOperation>) _operations.get("operation");
245+
for (CodegenOperation op : operationList) {
246+
String param = op.operationIdCamelCase + "Request";
247+
if (op.imports.contains(param)) {
248+
// we import a model with the same name as the generated operation, escape it
249+
op.operationIdCamelCase += "Operation";
250+
op.operationIdLowerCase += "operation";
251+
op.operationIdSnakeCase += "_operation";
252+
}
253+
}
254+
}
255+
241256
private void addOperationModelImportInfomation(Map<String, Object> operations) {
242257
// This method will add extra infomation to the operations.imports array.
243258
// The api template uses this infomation to import all the required

0 commit comments

Comments
 (0)