From 63b442977597bb049f4e1ec89bfb293d42324828 Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Wed, 22 Apr 2020 14:23:24 +0200 Subject: [PATCH] Escape clashing model names (#6004) Closes #6002 --- .../languages/TypeScriptFetchClientCodegen.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java index b1ab5e4fa818..a2f03cfdd3fa 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java @@ -235,9 +235,24 @@ public Map postProcessOperationsWithModels(Map o this.updateOperationParameterEnumInformation(operations); this.addOperationObjectResponseInformation(operations); this.addOperationPrefixParameterInterfacesInformation(operations); + this.escapeOperationIds(operations); return operations; } + private void escapeOperationIds(Map operations) { + Map _operations = (Map) operations.get("operations"); + List operationList = (List) _operations.get("operation"); + for (CodegenOperation op : operationList) { + String param = op.operationIdCamelCase + "Request"; + if (op.imports.contains(param)) { + // we import a model with the same name as the generated operation, escape it + op.operationIdCamelCase += "Operation"; + op.operationIdLowerCase += "operation"; + op.operationIdSnakeCase += "_operation"; + } + } + } + private void addOperationModelImportInfomation(Map operations) { // This method will add extra infomation to the operations.imports array. // The api template uses this infomation to import all the required