From 2512ea071af34e73dbd9d932b5d95a0bad08ba8d Mon Sep 17 00:00:00 2001 From: Erik Seliger Date: Thu, 25 Jul 2019 20:23:25 +0200 Subject: [PATCH] fix(typescript-angular): don't escape properties and operationIds --- .../AbstractTypeScriptClientCodegen.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java index 9e5e01123dfc..8c54c7ff2457 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java @@ -54,6 +54,8 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp protected String npmName = null; protected String npmVersion = "1.0.0"; + private List reservedModelNames = new ArrayList(); + public AbstractTypeScriptClientCodegen() { super(); @@ -70,9 +72,12 @@ public AbstractTypeScriptClientCodegen() { reservedWords.addAll(Arrays.asList( // local variable names used in API methods (endpoints) "varLocalPath", "queryParameters", "headerParams", "formParams", "useFormData", "varLocalDeferred", - "requestOptions", - // Typescript reserved words - "abstract", "await", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "transient", "true", "try", "typeof", "var", "void", "volatile", "while", "with", "yield")); + "requestOptions" + )); + + reservedModelNames.addAll(Arrays.asList( + "abstract", "await", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "transient", "true", "try", "typeof", "var", "void", "volatile", "while", "with", "yield" + )); languageSpecificPrimitives = new HashSet<>(Arrays.asList( "string", @@ -277,7 +282,7 @@ public String toModelName(String name) { } // model name cannot use reserved keyword, e.g. return - if (isReservedWord(name)) { + if (isReservedWord(name) || isReservedModelName(name)) { String modelName = camelize("model_" + name); LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName); return modelName; @@ -434,6 +439,10 @@ protected boolean isReservedWord(String word) { return reservedWords.contains(word); } + private boolean isReservedModelName(String word) { + return reservedModelNames.contains(word); + } + @Override public String getSchemaType(Schema p) { String openAPIType = super.getSchemaType(p);