Skip to content

Commit

Permalink
fix(typescript-angular): don't escape properties and operationIds
Browse files Browse the repository at this point in the history
  • Loading branch information
eseliger committed Jul 25, 2019
1 parent 5775813 commit 2512ea0
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
protected String npmName = null;
protected String npmVersion = "1.0.0";

private List<String> reservedModelNames = new ArrayList<String>();

public AbstractTypeScriptClientCodegen() {
super();

Expand All @@ -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",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2512ea0

Please sign in to comment.