diff --git a/docs/generators/javascript-flowtyped.md b/docs/generators/javascript-flowtyped.md index 3b3bb77331c3..6ecd6654d10d 100644 --- a/docs/generators/javascript-flowtyped.md +++ b/docs/generators/javascript-flowtyped.md @@ -9,7 +9,7 @@ sidebar_label: javascript-flowtyped |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |enumNameSuffix|Suffix that will be appended to all enum names. A special 'v4-compat' value enables the backward-compatible behavior (as pre v4.2.3)| |v4-compat| |enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |PascalCase| -|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase| +|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name. Only change it if you provide your own run-time code for (de-)serialization of models| |original| |npmName|The name under which you want to publish generated npm package. Required to generate a full package| |null| |npmRepository|Use this property to set an url your private npmRepo in the package.json| |null| |npmVersion|The version of your npm package. If not provided, using the version from the OpenAPI specification file.| |1.0.0| diff --git a/docs/generators/typescript-angular.md b/docs/generators/typescript-angular.md index d83b524042cd..f382194df4ab 100644 --- a/docs/generators/typescript-angular.md +++ b/docs/generators/typescript-angular.md @@ -12,7 +12,7 @@ sidebar_label: typescript-angular |enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |PascalCase| |fileNaming|Naming convention for the output files: 'camelCase', 'kebab-case'.| |camelCase| |modelFileSuffix|The suffix of the file of the generated model (model<suffix>.ts).| |null| -|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase| +|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name. Only change it if you provide your own run-time code for (de-)serialization of models| |original| |modelSuffix|The suffix of the generated model.| |null| |ngVersion|The version of Angular.| |9.0.0| |npmName|The name under which you want to publish generated npm package. Required to generate a full package| |null| diff --git a/docs/generators/typescript-angularjs.md b/docs/generators/typescript-angularjs.md index e66164fa1eb6..fbfd828ba323 100644 --- a/docs/generators/typescript-angularjs.md +++ b/docs/generators/typescript-angularjs.md @@ -9,7 +9,7 @@ sidebar_label: typescript-angularjs |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |enumNameSuffix|Suffix that will be appended to all enum names. A special 'v4-compat' value enables the backward-compatible behavior (as pre v4.2.3)| |v4-compat| |enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |PascalCase| -|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase| +|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name. Only change it if you provide your own run-time code for (de-)serialization of models| |original| |nullSafeAdditionalProps|Set to make additional properties types declare that their indexer may return undefined| |false| |prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false| |sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true| diff --git a/docs/generators/typescript-aurelia.md b/docs/generators/typescript-aurelia.md index d0278734f7be..955079117b0e 100644 --- a/docs/generators/typescript-aurelia.md +++ b/docs/generators/typescript-aurelia.md @@ -9,7 +9,7 @@ sidebar_label: typescript-aurelia |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |enumNameSuffix|Suffix that will be appended to all enum names. A special 'v4-compat' value enables the backward-compatible behavior (as pre v4.2.3)| |v4-compat| |enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |PascalCase| -|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase| +|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name. Only change it if you provide your own run-time code for (de-)serialization of models| |original| |npmName|The name under which you want to publish generated npm package. Required to generate a full package| |null| |npmVersion|The version of your npm package. If not provided, using the version from the OpenAPI specification file.| |1.0.0| |nullSafeAdditionalProps|Set to make additional properties types declare that their indexer may return undefined| |false| diff --git a/docs/generators/typescript-axios.md b/docs/generators/typescript-axios.md index 1b7fae3d145a..5e65684a0e6e 100644 --- a/docs/generators/typescript-axios.md +++ b/docs/generators/typescript-axios.md @@ -9,7 +9,7 @@ sidebar_label: typescript-axios |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |enumNameSuffix|Suffix that will be appended to all enum names. A special 'v4-compat' value enables the backward-compatible behavior (as pre v4.2.3)| |v4-compat| |enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |PascalCase| -|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase| +|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name. Only change it if you provide your own run-time code for (de-)serialization of models| |original| |npmName|The name under which you want to publish generated npm package. Required to generate a full package| |null| |npmRepository|Use this property to set an url of your private npmRepo in the package.json| |null| |npmVersion|The version of your npm package. If not provided, using the version from the OpenAPI specification file.| |1.0.0| diff --git a/docs/generators/typescript-inversify.md b/docs/generators/typescript-inversify.md index c6657b5b5f70..5d68c9f08399 100644 --- a/docs/generators/typescript-inversify.md +++ b/docs/generators/typescript-inversify.md @@ -9,7 +9,7 @@ sidebar_label: typescript-inversify |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |enumNameSuffix|Suffix that will be appended to all enum names. A special 'v4-compat' value enables the backward-compatible behavior (as pre v4.2.3)| |v4-compat| |enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |PascalCase| -|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase| +|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name. Only change it if you provide your own run-time code for (de-)serialization of models| |original| |npmName|The name under which you want to publish generated npm package. Required to generate a full package| |null| |npmRepository|Use this property to set an url your private npmRepo in the package.json| |null| |npmVersion|The version of your npm package. If not provided, using the version from the OpenAPI specification file.| |1.0.0| diff --git a/docs/generators/typescript-jquery.md b/docs/generators/typescript-jquery.md index f5f40aaa6424..91d61cf31e10 100644 --- a/docs/generators/typescript-jquery.md +++ b/docs/generators/typescript-jquery.md @@ -10,7 +10,7 @@ sidebar_label: typescript-jquery |enumNameSuffix|Suffix that will be appended to all enum names. A special 'v4-compat' value enables the backward-compatible behavior (as pre v4.2.3)| |v4-compat| |enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |PascalCase| |jqueryAlreadyImported|When using this in legacy app using mix of typescript and javascript, this will only declare jquery and not import it| |false| -|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase| +|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name. Only change it if you provide your own run-time code for (de-)serialization of models| |original| |npmName|The name under which you want to publish generated npm package. Required to generate a full package| |null| |npmRepository|Use this property to set an url your private npmRepo in the package.json| |null| |npmVersion|The version of your npm package. If not provided, using the version from the OpenAPI specification file.| |1.0.0| diff --git a/docs/generators/typescript-rxjs.md b/docs/generators/typescript-rxjs.md index a2a3c09c6005..9a210f4934b9 100644 --- a/docs/generators/typescript-rxjs.md +++ b/docs/generators/typescript-rxjs.md @@ -9,7 +9,7 @@ sidebar_label: typescript-rxjs |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |enumNameSuffix|Suffix that will be appended to all enum names. A special 'v4-compat' value enables the backward-compatible behavior (as pre v4.2.3)| |v4-compat| |enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |PascalCase| -|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name| |camelCase| +|modelPropertyNaming|Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name. Only change it if you provide your own run-time code for (de-)serialization of models| |original| |npmName|The name under which you want to publish generated npm package. Required to generate a full package| |null| |npmRepository|Use this property to set an url your private npmRepo in the package.json| |null| |npmVersion|The version of your npm package. If not provided, using the version from the OpenAPI specification file.| |1.0.0| 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 6fa57faf5a24..6ae71b01e3b3 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 @@ -25,6 +25,7 @@ import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.CodegenConstants.ENUM_PROPERTY_NAMING_TYPE; +import org.openapitools.codegen.CodegenConstants.MODEL_PROPERTY_NAMING_TYPE; import org.openapitools.codegen.*; import org.openapitools.codegen.meta.features.*; import org.openapitools.codegen.utils.ModelUtils; @@ -55,6 +56,9 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp public static final String ENUM_NAME_SUFFIX_DESC_CUSTOMIZED = CodegenConstants.ENUM_NAME_SUFFIX_DESC + " A special '" + ENUM_NAME_SUFFIX_V4_COMPAT + "' value enables the backward-compatible behavior (as pre v4.2.3)"; + public static final String MODEL_PROPERTY_NAMING_DESC_WITH_WARNING = CodegenConstants.MODEL_PROPERTY_NAMING_DESC + + ". Only change it if you provide your own run-time code for (de-)serialization of models"; + public static final String NULL_SAFE_ADDITIONAL_PROPS = "nullSafeAdditionalProps"; public static final String NULL_SAFE_ADDITIONAL_PROPS_DESC = "Set to make additional properties types declare that their indexer may return undefined"; @@ -62,7 +66,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp @SuppressWarnings("squid:S5164") protected static final ThreadLocal SNAPSHOT_SUFFIX_FORMAT = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyyMMddHHmm", Locale.ROOT)); - protected String modelPropertyNaming = "camelCase"; + protected MODEL_PROPERTY_NAMING_TYPE modelPropertyNaming = MODEL_PROPERTY_NAMING_TYPE.original; protected ENUM_PROPERTY_NAMING_TYPE enumPropertyNaming = ENUM_PROPERTY_NAMING_TYPE.PascalCase; protected Boolean supportsES6 = false; protected Boolean nullSafeAdditionalProps = false; @@ -170,7 +174,7 @@ public AbstractTypeScriptClientCodegen() { cliOptions.add(new CliOption(CodegenConstants.ENUM_NAME_SUFFIX, ENUM_NAME_SUFFIX_DESC_CUSTOMIZED).defaultValue(this.enumSuffix)); cliOptions.add(new CliOption(CodegenConstants.ENUM_PROPERTY_NAMING, CodegenConstants.ENUM_PROPERTY_NAMING_DESC).defaultValue(this.enumPropertyNaming.name())); - cliOptions.add(new CliOption(CodegenConstants.MODEL_PROPERTY_NAMING, CodegenConstants.MODEL_PROPERTY_NAMING_DESC).defaultValue(this.modelPropertyNaming)); + cliOptions.add(new CliOption(CodegenConstants.MODEL_PROPERTY_NAMING, MODEL_PROPERTY_NAMING_DESC_WITH_WARNING).defaultValue(this.modelPropertyNaming.name())); cliOptions.add(new CliOption(CodegenConstants.SUPPORTS_ES6, CodegenConstants.SUPPORTS_ES6_DESC).defaultValue(String.valueOf(this.getSupportsES6()))); this.cliOptions.add(new CliOption(NPM_NAME, "The name under which you want to publish generated npm package." + " Required to generate a full package")); @@ -179,7 +183,12 @@ public AbstractTypeScriptClientCodegen() { "When setting this property to true, the version will be suffixed with -SNAPSHOT." + this.SNAPSHOT_SUFFIX_FORMAT.get().toPattern(), false)); this.cliOptions.add(new CliOption(NULL_SAFE_ADDITIONAL_PROPS, NULL_SAFE_ADDITIONAL_PROPS_DESC).defaultValue(String.valueOf(this.getNullSafeAdditionalProps()))); + } + protected void supportModelPropertyNaming(MODEL_PROPERTY_NAMING_TYPE defaultModelPropertyNaming) { + removeOption(CodegenConstants.MODEL_PROPERTY_NAMING); + modelPropertyNaming = defaultModelPropertyNaming; + cliOptions.add(new CliOption(CodegenConstants.MODEL_PROPERTY_NAMING, CodegenConstants.MODEL_PROPERTY_NAMING_DESC).defaultValue(modelPropertyNaming.name())); } @Override @@ -274,52 +283,37 @@ public String modelFileFolder() { @Override public String toParamName(String name) { - // sanitize name name = sanitizeName(name, "[^\\w$]"); if ("_".equals(name)) { name = "_u"; } - // if it's all uppper case, do nothing - if (name.matches("^[A-Z_]*$")) { - return name; - } - - name = getNameUsingModelPropertyNaming(name); - - // for reserved word or word starting with number, append _ - if (isReservedWord(name) || name.matches("^\\d.*")) { - name = escapeReservedWord(name); - } + name = camelize(name, true); + name = toSafeIdentifier(name); return name; } @Override public String toVarName(String name) { - name = this.toParamName(name); - - // if the property name has any breaking characters such as :, ;, . etc. - // then wrap the name within single quotes. - // my:interface:property: string; => 'my:interface:property': string; - if (propertyHasBreakingCharacters(name)) { - name = "\'" + name + "\'"; + name = sanitizeName(name, "[^\\w$]"); + + if ("_".equals(name)) { + name = "_u"; } + name = getNameUsingModelPropertyNaming(name); + name = toSafeIdentifier(name); + return name; } - /** - * Checks whether property names have breaking characters like ':', '-'. - * @param str string to check for breaking characters - * @return true if breaking characters are present and false if not - */ - private boolean propertyHasBreakingCharacters(String str) { - final String regex = "^.*[+*:;,.()-]+.*$"; - final Pattern pattern = Pattern.compile(regex); - final Matcher matcher = pattern.matcher(str); - return matcher.matches(); + private String toSafeIdentifier(String name) { + if (isReservedWord(name) || name.matches("^\\d.*")) { + name = escapeReservedWord(name); + } + return name; } @Override @@ -533,32 +527,31 @@ public String toOperationId(String operationId) { throw new RuntimeException("Empty method name (operationId) not allowed"); } - // method name cannot use reserved keyword or word starting with number, e.g. return or 123return - // append _ at the beginning, e.g. _return or _123return - if (isReservedWord(operationId) || operationId.matches("^\\d.*")) { - return escapeReservedWord(camelize(sanitizeName(operationId), true)); - } + operationId = camelize(sanitizeName(operationId), true); + operationId = toSafeIdentifier(operationId); - return camelize(sanitizeName(operationId), true); + return operationId; } public void setModelPropertyNaming(String naming) { - if ("original".equals(naming) || "camelCase".equals(naming) || - "PascalCase".equals(naming) || "snake_case".equals(naming)) { - this.modelPropertyNaming = naming; - } else { - throw new IllegalArgumentException("Invalid model property naming '" + - naming + "'. Must be 'original', 'camelCase', " + - "'PascalCase' or 'snake_case'"); + try { + modelPropertyNaming = MODEL_PROPERTY_NAMING_TYPE.valueOf(naming); + } catch (IllegalArgumentException e) { + String values = Stream.of(MODEL_PROPERTY_NAMING_TYPE.values()) + .map(value -> "'" + value.name() + "'") + .collect(Collectors.joining(", ")); + + String msg = String.format(Locale.ROOT, "Invalid model property naming '%s'. Must be one of %s.", naming, values); + throw new IllegalArgumentException(msg); } } - public String getModelPropertyNaming() { - return this.modelPropertyNaming; + public MODEL_PROPERTY_NAMING_TYPE getModelPropertyNaming() { + return modelPropertyNaming; } private String getNameUsingModelPropertyNaming(String name) { - switch (CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.valueOf(getModelPropertyNaming())) { + switch (getModelPropertyNaming()) { case original: return name; case camelCase: diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java index 99dfa285bbbd..d9b8994463cc 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java @@ -456,7 +456,7 @@ public Map postProcessOperationsWithModels(Map o // Add the more complicated component instead of just the brace. CodegenParameter parameter = findPathParameterByName(op, parameterName.toString()); - pathBuffer.append(toVarName(parameterName.toString())); + pathBuffer.append(toParamName(parameterName.toString())); if (parameter != null && parameter.isDateTime) { pathBuffer.append(".toISOString()"); } 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 9ea63beb2cf7..4e15c4bd2ff8 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 @@ -66,6 +66,7 @@ public TypeScriptFetchClientCodegen() { typeMapping.put("date", "Date"); typeMapping.put("DateTime", "Date"); + supportModelPropertyNaming(CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.camelCase); this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json")); this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(USE_SINGLE_REQUEST_PARAMETER, "Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.TRUE.toString())); @@ -102,8 +103,8 @@ public void setTypescriptThreePlus(Boolean typescriptThreePlus) { @Override public void processOpts() { super.processOpts(); - additionalProperties.put("isOriginalModelPropertyNaming", getModelPropertyNaming().equals("original")); - additionalProperties.put("modelPropertyNaming", getModelPropertyNaming()); + additionalProperties.put("isOriginalModelPropertyNaming", getModelPropertyNaming() == CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.original); + additionalProperties.put("modelPropertyNaming", getModelPropertyNaming().name()); String sourceDir = ""; if (additionalProperties.containsKey(NPM_NAME)) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java index 75b91392fa1a..5255753c4d41 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java @@ -225,7 +225,7 @@ public Map postProcessOperationsWithModels(Map o insideCurly--; // Add the more complicated component instead of just the brace. - pathBuffer.append(toVarName(parameterName.toString())); + pathBuffer.append(toParamName(parameterName.toString())); pathBuffer.append("))}"); parameterName.setLength(0); break; diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java index a56ae5ce7c98..6a46fbc78dd0 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java @@ -64,6 +64,7 @@ public TypeScriptNodeClientCodegen() { modelPackage = "model"; apiPackage = "api"; + supportModelPropertyNaming(CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.camelCase); this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json")); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptReduxQueryClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptReduxQueryClientCodegen.java index 33e82b8e87b8..26f6fb6f06b3 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptReduxQueryClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptReduxQueryClientCodegen.java @@ -61,6 +61,7 @@ public TypeScriptReduxQueryClientCodegen() { typeMapping.put("date", "Date"); typeMapping.put("DateTime", "Date"); + supportModelPropertyNaming(CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.camelCase); this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json")); this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(USE_SINGLE_REQUEST_PARAMETER, "Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.", SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(Boolean.TRUE.toString())); @@ -87,8 +88,8 @@ public void setNpmRepository(String npmRepository) { @Override public void processOpts() { super.processOpts(); - additionalProperties.put("isOriginalModelPropertyNaming", getModelPropertyNaming().equals("original")); - additionalProperties.put("modelPropertyNaming", getModelPropertyNaming()); + additionalProperties.put("isOriginalModelPropertyNaming", getModelPropertyNaming() == CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.original); + additionalProperties.put("modelPropertyNaming", getModelPropertyNaming().name()); supportingFiles.add(new SupportingFile("index.mustache", "src", "index.ts")); supportingFiles.add(new SupportingFile("runtime.mustache", "src", "runtime.ts")); supportingFiles.add(new SupportingFile("tsconfig.mustache", "", "tsconfig.json")); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java index 13a17b5f518c..2247164c894b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptRxjsClientCodegen.java @@ -89,8 +89,6 @@ public void setNpmRepository(String npmRepository) { @Override public void processOpts() { super.processOpts(); - additionalProperties.put("isOriginalModelPropertyNaming", getModelPropertyNaming().equals("original")); - additionalProperties.put("modelPropertyNaming", getModelPropertyNaming()); supportingFiles.add(new SupportingFile("index.mustache", "", "index.ts")); supportingFiles.add(new SupportingFile("runtime.mustache", "", "runtime.ts")); supportingFiles.add(new SupportingFile("apis.index.mustache", apiPackage().replace('.', File.separatorChar), "index.ts")); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java index 2e18afea218f..a72a93de9d81 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/fetch/TypeScriptFetchClientCodegenTest.java @@ -1,6 +1,7 @@ package org.openapitools.codegen.typescript.fetch; import io.swagger.v3.oas.models.OpenAPI; +import org.openapitools.codegen.CodegenConstants; import org.openapitools.codegen.TestUtils; import org.openapitools.codegen.languages.TypeScriptFetchClientCodegen; import org.testng.Assert; @@ -56,4 +57,16 @@ public void testWithoutSnapshotVersion() { } + @Test + public void toVarName() { + TypeScriptFetchClientCodegen codegen = new TypeScriptFetchClientCodegen(); + codegen.processOpts(); + Assert.assertEquals(codegen.toVarName("valid_var"), "validVar"); + + codegen = new TypeScriptFetchClientCodegen(); + codegen.additionalProperties().put(CodegenConstants.MODEL_PROPERTY_NAMING, "original"); + codegen.processOpts(); + Assert.assertEquals(codegen.toVarName("valid_var"), "valid_var"); + } + } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java index a1a07d28aa68..c1646fcdc609 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptangular/TypeScriptAngularClientCodegenTest.java @@ -18,6 +18,18 @@ public class TypeScriptAngularClientCodegenTest { + @Test + public void toVarName() { + TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen(); + codegen.processOpts(); + Assert.assertEquals(codegen.toVarName("valid_var"), "valid_var"); + + codegen = new TypeScriptAngularClientCodegen(); + codegen.additionalProperties().put(CodegenConstants.MODEL_PROPERTY_NAMING, "camelCase"); + codegen.processOpts(); + Assert.assertEquals(codegen.toVarName("valid_var"), "validVar"); + } + @Test public void toEnumVarName() { TypeScriptAngularClientCodegen codegen = new TypeScriptAngularClientCodegen();