forked from loafle/openapi-generator-original
[JAVA] Handle camlCase with $ as first char (#13292)
* Lowercase first char and not first letter for variable names * Samples * Limit caml case fix impact with cli a property
This commit is contained in:
parent
8eb3064b2e
commit
574a70c315
@ -7,3 +7,4 @@ additionalProperties:
|
||||
artifactId: springboot
|
||||
snapshotVersion: "true"
|
||||
hideGenerationTimestamp: "true"
|
||||
camelCaseDollarSign: "true"
|
||||
|
@ -26,6 +26,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|legacy|
|
||||
|developerEmail|developer email in generated pom.xml| |team@openapitools.org|
|
||||
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|
||||
|
@ -32,6 +32,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|basePackage|base package (invokerPackage) for generated code| |org.openapitools|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|camelDataformatProperties|list of dataformat properties separated by comma (propertyName1=propertyValue2,...| ||
|
||||
|camelRestBindingMode|binding mode to be used by the REST consumer| |auto|
|
||||
|camelRestClientRequestValidation|enable validation of the client request to check whether the Content-Type and Accept headers from the client is supported by the Rest-DSL configuration| |false|
|
||||
|
@ -28,6 +28,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|legacy|
|
||||
|developerEmail|developer email in generated pom.xml| |team@openapitools.org|
|
||||
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|
||||
|
@ -30,6 +30,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|build|Specify for which build tool to generate files|<dl><dt>**gradle**</dt><dd>Gradle configuration is generated for the project</dd><dt>**all**</dt><dd>Both Gradle and Maven configurations are generated</dd><dt>**maven**</dt><dd>Maven configuration is generated for the project</dd></dl>|all|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|configureAuth|Configure all the authorization methods as specified in the file| |false|
|
||||
|dateFormat|Specify the format pattern of date as a string| |null|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|java8|
|
||||
|
@ -29,6 +29,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|build|Specify for which build tool to generate files|<dl><dt>**gradle**</dt><dd>Gradle configuration is generated for the project</dd><dt>**all**</dt><dd>Both Gradle and Maven configurations are generated</dd><dt>**maven**</dt><dd>Maven configuration is generated for the project</dd></dl>|all|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|controllerPackage|The package in which controllers will be generated| |org.openapitools.api|
|
||||
|dateFormat|Specify the format pattern of date as a string| |null|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|java8|
|
||||
|
@ -28,6 +28,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|legacy|
|
||||
|developerEmail|developer email in generated pom.xml| |team@openapitools.org|
|
||||
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|
||||
|
@ -29,6 +29,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|basePackage|base package for java source code| |null|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|java8|
|
||||
|developerEmail|developer email in generated pom.xml| |team@openapitools.org|
|
||||
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|
||||
|
@ -29,6 +29,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|basePackage|base package for generated code| |org.openapitools|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|configPackage|configuration package for generated code| |org.openapitools.configuration|
|
||||
|controllerOnly|Whether to generate only API interface stubs without the server files.| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|java8|
|
||||
|
@ -28,6 +28,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|legacy|
|
||||
|developerEmail|developer email in generated pom.xml| |team@openapitools.org|
|
||||
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|
||||
|
@ -28,6 +28,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0-SNAPSHOT|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|java8|
|
||||
|developerEmail|developer email in generated pom.xml| |team@openapitools.org|
|
||||
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|
||||
|
@ -28,6 +28,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0-SNAPSHOT|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|java8|
|
||||
|developerEmail|developer email in generated pom.xml| |team@openapitools.org|
|
||||
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|
||||
|
@ -29,6 +29,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|asyncNative|If true, async handlers will be used, instead of the sync version| |false|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|caseInsensitiveResponseHeaders|Make API response's headers case-insensitive. Available on okhttp-gson, jersey2 libraries| |false|
|
||||
|configKey|Config key in @RegisterRestClient. Default to none. Only `microprofile` supports this option.| |null|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|java8|
|
||||
|
@ -28,6 +28,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|legacy|
|
||||
|developerEmail|developer email in generated pom.xml| |team@openapitools.org|
|
||||
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|
||||
|
@ -28,6 +28,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|legacy|
|
||||
|developerEmail|developer email in generated pom.xml| |team@openapitools.org|
|
||||
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|
||||
|
@ -29,6 +29,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|legacy|
|
||||
|developerEmail|developer email in generated pom.xml| |team@openapitools.org|
|
||||
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|
||||
|
@ -29,6 +29,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|legacy|
|
||||
|developerEmail|developer email in generated pom.xml| |team@openapitools.org|
|
||||
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|
||||
|
@ -28,6 +28,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|legacy|
|
||||
|developerEmail|developer email in generated pom.xml| |team@openapitools.org|
|
||||
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|
||||
|
@ -28,6 +28,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|legacy|
|
||||
|developerEmail|developer email in generated pom.xml| |team@openapitools.org|
|
||||
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|
||||
|
@ -28,6 +28,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|legacy|
|
||||
|developerEmail|developer email in generated pom.xml| |team@openapitools.org|
|
||||
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|
||||
|
@ -28,6 +28,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |1.0.0|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|legacy|
|
||||
|developerEmail|developer email in generated pom.xml| |team@openapitools.org|
|
||||
|developerName|developer name in generated pom.xml| |OpenAPI-Generator Contributors|
|
||||
|
@ -32,6 +32,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|basePackage|base package (invokerPackage) for generated code| |org.openapitools|
|
||||
|bigDecimalAsString|Treat BigDecimal values as Strings to avoid precision loss.| |false|
|
||||
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|
||||
|camelCaseDollarSign|Fix camelCase when starting with $ sign. when true : $Value when false : $value| |false|
|
||||
|configPackage|configuration package for generated code| |org.openapitools.configuration|
|
||||
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+)</dd></dl>|java8|
|
||||
|delegatePattern|Whether to generate the server files using the delegate pattern| |false|
|
||||
|
@ -3715,7 +3715,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
} else {
|
||||
property.openApiType = p.getType();
|
||||
}
|
||||
property.nameInCamelCase = camelize(property.name, false);
|
||||
property.nameInCamelCase = camelize(property.name);
|
||||
property.nameInSnakeCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, property.nameInCamelCase);
|
||||
property.description = escapeText(p.getDescription());
|
||||
property.unescapedDescription = p.getDescription();
|
||||
|
@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
abstract public class AbstractAdaCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@ -826,7 +827,7 @@ abstract public class AbstractAdaCodegen extends DefaultCodegen implements Codeg
|
||||
// method with only the scope that it requires. We have to create a new auth method
|
||||
// instance because the original object must not be modified.
|
||||
List<String> opScopes = (scopes == null) ? null : scopes.get(authMethod.name);
|
||||
authMethod.name = camelize(sanitizeName(authMethod.name), true);
|
||||
authMethod.name = camelize(sanitizeName(authMethod.name), LOWERCASE_FIRST_LETTER);
|
||||
if (opScopes != null) {
|
||||
CodegenSecurity opSecurity = new CodegenSecurity();
|
||||
opSecurity.name = authMethod.name;
|
||||
|
@ -33,6 +33,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public abstract class AbstractApexCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@ -111,7 +112,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
@ -422,11 +423,11 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public abstract class AbstractCSharpCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@ -974,7 +975,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
// camelize(lower) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
|
@ -28,6 +28,7 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
|
||||
public abstract class AbstractDartCodegen extends DefaultCodegen {
|
||||
@ -373,7 +374,7 @@ public abstract class AbstractDartCodegen extends DefaultCodegen {
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
|
||||
if (name.matches("^\\d.*")) {
|
||||
name = "n" + name;
|
||||
@ -721,18 +722,18 @@ public abstract class AbstractDartCodegen extends DefaultCodegen {
|
||||
public String toOperationId(String operationId) {
|
||||
operationId = super.toOperationId(operationId);
|
||||
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (starting with a number) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
operationId = newOperationId;
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -343,7 +344,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
|
||||
String sanitizedOperationId = camelize(sanitizeName(operationId), true);
|
||||
String sanitizedOperationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(sanitizedOperationId)) {
|
||||
@ -354,7 +355,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), true);
|
||||
sanitizedOperationId = camelize("call_" + sanitizedOperationId, true);
|
||||
sanitizedOperationId = camelize("call_" + sanitizedOperationId, LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
// method name from updateSomething to update_Something.
|
||||
|
@ -38,6 +38,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -661,7 +662,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
||||
case original:
|
||||
return name;
|
||||
case camelCase:
|
||||
return camelize(name, true);
|
||||
return camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
case PascalCase:
|
||||
return camelize(name);
|
||||
case snake_case:
|
||||
@ -707,7 +708,7 @@ public abstract class AbstractFSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
// camelize(lower) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
|
@ -34,6 +34,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -232,7 +233,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
||||
// params should be lowerCamelCase. E.g. "person Person", instead of
|
||||
// "Person Person".
|
||||
//
|
||||
name = camelize(toVarName(name), true);
|
||||
name = camelize(toVarName(name), LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// REVISIT: Actually, for idiomatic go, the param name should
|
||||
// really should just be a letter, e.g. "p Person"), but we'll get
|
||||
|
@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -160,7 +161,7 @@ public abstract class AbstractGraphQLCodegen extends DefaultCodegen implements C
|
||||
if (name.matches("^[A-Z_]*$"))
|
||||
return name;
|
||||
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name))
|
||||
@ -326,7 +327,7 @@ public abstract class AbstractGraphQLCodegen extends DefaultCodegen implements C
|
||||
sanitizedOperationId = "call_" + sanitizedOperationId;
|
||||
}
|
||||
|
||||
return camelize(sanitizedOperationId, false);
|
||||
return camelize(sanitizedOperationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,6 +40,7 @@ import org.openapitools.codegen.model.ModelMap;
|
||||
import org.openapitools.codegen.model.ModelsMap;
|
||||
import org.openapitools.codegen.model.OperationMap;
|
||||
import org.openapitools.codegen.model.OperationsMap;
|
||||
import org.openapitools.codegen.utils.CamelizeOption;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -55,6 +56,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.*;
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
|
||||
public abstract class AbstractJavaCodegen extends DefaultCodegen implements CodegenConfig,
|
||||
@ -81,6 +83,8 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
public static final String IMPLICIT_HEADERS = "implicitHeaders";
|
||||
public static final String IMPLICIT_HEADERS_REGEX = "implicitHeadersRegex";
|
||||
|
||||
public static final String CAMEL_CASE_DOLLAR_SIGN = "camelCaseDollarSign";
|
||||
|
||||
public static final String DEFAULT_TEST_FOLDER = "${project.build.directory}/generated-test-sources/openapi";
|
||||
|
||||
protected String dateLibrary = "java8";
|
||||
@ -130,6 +134,8 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
protected boolean implicitHeaders = false;
|
||||
protected String implicitHeadersRegex = null;
|
||||
|
||||
protected boolean camelCaseDollarSign = false;
|
||||
|
||||
private Map<String, String> schemaKeyToModelNameCache = new HashMap<>();
|
||||
|
||||
public AbstractJavaCodegen() {
|
||||
@ -262,6 +268,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
cliOptions.add(CliOption.newBoolean(OPENAPI_NULLABLE, "Enable OpenAPI Jackson Nullable library", this.openApiNullable));
|
||||
cliOptions.add(CliOption.newBoolean(IMPLICIT_HEADERS, "Skip header parameters in the generated API methods using @ApiImplicitParams annotation.", implicitHeaders));
|
||||
cliOptions.add(CliOption.newString(IMPLICIT_HEADERS_REGEX, "Skip header parameters that matches given regex in the generated API methods using @ApiImplicitParams annotation. Note: this parameter is ignored when implicitHeaders=true"));
|
||||
cliOptions.add(CliOption.newBoolean(CAMEL_CASE_DOLLAR_SIGN, "Fix camelCase when starting with $ sign. when true : $Value when false : $value"));
|
||||
|
||||
cliOptions.add(CliOption.newString(CodegenConstants.PARENT_GROUP_ID, CodegenConstants.PARENT_GROUP_ID_DESC));
|
||||
cliOptions.add(CliOption.newString(CodegenConstants.PARENT_ARTIFACT_ID, CodegenConstants.PARENT_ARTIFACT_ID_DESC));
|
||||
@ -549,6 +556,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
this.setImplicitHeadersRegex(additionalProperties.get(IMPLICIT_HEADERS_REGEX).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CAMEL_CASE_DOLLAR_SIGN)) {
|
||||
this.setCamelCaseDollarSign(Boolean.parseBoolean(additionalProperties.get(CAMEL_CASE_DOLLAR_SIGN).toString()));
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(parentGroupId) && !StringUtils.isEmpty(parentArtifactId) && !StringUtils.isEmpty(parentVersion)) {
|
||||
additionalProperties.put("parentOverridden", true);
|
||||
}
|
||||
@ -795,7 +806,11 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
if (camelCaseDollarSign) {
|
||||
name = camelize(name, LOWERCASE_FIRST_CHAR);
|
||||
} else {
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
@ -1261,11 +1276,11 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
@ -1273,7 +1288,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize("call_" + operationId), true);
|
||||
operationId = camelize("call_" + operationId, true);
|
||||
operationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
return operationId;
|
||||
@ -1902,6 +1917,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
this.implicitHeadersRegex = implicitHeadersRegex;
|
||||
}
|
||||
|
||||
public void setCamelCaseDollarSign(boolean camelCaseDollarSign) {
|
||||
this.camelCaseDollarSign = camelCaseDollarSign;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
@ -1984,7 +2003,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
*/
|
||||
@Override
|
||||
public String getterAndSetterCapitalize(String name) {
|
||||
boolean lowercaseFirstLetter = false;
|
||||
CamelizeOption camelizeOption = UPPERCASE_FIRST_CHAR;
|
||||
if (name == null || name.length() == 0) {
|
||||
return name;
|
||||
}
|
||||
@ -1996,9 +2015,9 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
// http://download.oracle.com/otn-pub/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/beans.101.pdf)
|
||||
//
|
||||
if (name.length() > 1 && Character.isLowerCase(name.charAt(0)) && Character.isUpperCase(name.charAt(1))) {
|
||||
lowercaseFirstLetter = true;
|
||||
camelizeOption = LOWERCASE_FIRST_LETTER;
|
||||
}
|
||||
return camelize(name, lowercaseFirstLetter);
|
||||
return camelize(name, camelizeOption);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,6 +39,7 @@ import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
|
||||
public abstract class AbstractKotlinCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@ -625,7 +626,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
break;
|
||||
case camelCase:
|
||||
// NOTE: Removes hyphens and underscores
|
||||
modified = camelize(modified, true);
|
||||
modified = camelize(modified, LOWERCASE_FIRST_LETTER);
|
||||
break;
|
||||
case PascalCase:
|
||||
// NOTE: Removes hyphens and underscores
|
||||
@ -755,19 +756,19 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
if (StringUtils.isEmpty(operationId))
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), true);
|
||||
operationId = camelize("call_" + operationId, true);
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), LOWERCASE_FIRST_LETTER);
|
||||
operationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
return operationId;
|
||||
@ -921,7 +922,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
public String toVarName(String name) {
|
||||
name = toVariableName(name);
|
||||
if (propertyAdditionalKeywords.contains(name)) {
|
||||
return camelize("property_" + name, true);
|
||||
return camelize("property_" + name, LOWERCASE_FIRST_LETTER);
|
||||
} else {
|
||||
return name;
|
||||
}
|
||||
@ -959,7 +960,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// for reserved word or word starting with number or containing dollar symbol, escape it
|
||||
if (isReservedWord(name) || name.matches("(^\\d.*)|(.*[$].*)")) {
|
||||
|
@ -35,6 +35,9 @@ import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.UPPERCASE_FIRST_CHAR;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -413,9 +416,9 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
if ("camelCase".equals(variableNamingConvention)) {
|
||||
// return the name in camelCase style
|
||||
// phone_number => phoneNumber
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
} else if ("PascalCase".equals(variableNamingConvention)) {
|
||||
name = camelize(name, false);
|
||||
name = camelize(name, UPPERCASE_FIRST_CHAR);
|
||||
} else { // default to snake case
|
||||
// return the name in underscore style
|
||||
// PhoneNumber => phone_number
|
||||
@ -542,17 +545,17 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, camelize(sanitizeName("call_" + operationId), true));
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, camelize(sanitizeName("call_" + operationId), LOWERCASE_FIRST_LETTER));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn("{} (starting with a number) cannot be used as method name. Renamed to {}", operationId, camelize(sanitizeName("call_" + operationId), true));
|
||||
LOGGER.warn("{} (starting with a number) cannot be used as method name. Renamed to {}", operationId, camelize(sanitizeName("call_" + operationId), LOWERCASE_FIRST_LETTER));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
return camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -313,7 +313,7 @@ public abstract class AbstractPythonConnexionServerCodegen extends AbstractPytho
|
||||
if (name == null || name.length() == 0) {
|
||||
return "DefaultController";
|
||||
}
|
||||
return camelize(name, false) + "Controller";
|
||||
return camelize(name) + "Controller";
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@ package org.openapitools.codegen.languages;
|
||||
|
||||
import com.samskivert.mustache.Escapers;
|
||||
import com.samskivert.mustache.Mustache;
|
||||
import com.samskivert.mustache.Template;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.media.StringSchema;
|
||||
@ -27,15 +28,20 @@ import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.openapitools.codegen.model.ModelsMap;
|
||||
import org.openapitools.codegen.utils.CamelizeOption;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.languages.AbstractJavaCodegen.DATE_LIBRARY;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.UPPERCASE_FIRST_CHAR;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -293,7 +299,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
case original:
|
||||
return name;
|
||||
case camelCase:
|
||||
return camelize(name, true);
|
||||
return camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
case PascalCase:
|
||||
return camelize(name);
|
||||
case snake_case:
|
||||
@ -527,7 +533,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
if (specialCharReplacements.containsKey(name)) {
|
||||
name = specialCharReplacements.get(name);
|
||||
}
|
||||
String identifier = camelize(sanitizeName(name), true);
|
||||
String identifier = camelize(sanitizeName(name), LOWERCASE_FIRST_LETTER);
|
||||
if (capitalized) {
|
||||
identifier = StringUtils.capitalize(identifier);
|
||||
}
|
||||
@ -588,11 +594,11 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
@ -600,7 +606,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), true);
|
||||
operationId = camelize("call_" + operationId, true);
|
||||
operationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
return operationId;
|
||||
@ -614,4 +620,32 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
|
||||
public GeneratorLanguage generatorLanguage() {
|
||||
return GeneratorLanguage.SCALA;
|
||||
}
|
||||
|
||||
protected static abstract class CustomLambda implements Mustache.Lambda {
|
||||
@Override
|
||||
public void execute(Template.Fragment frag, Writer out) throws IOException {
|
||||
final StringWriter tempWriter = new StringWriter();
|
||||
frag.execute(tempWriter);
|
||||
out.write(formatFragment(tempWriter.toString()));
|
||||
}
|
||||
|
||||
public abstract String formatFragment(String fragment);
|
||||
}
|
||||
|
||||
protected static class CamelizeLambda extends CustomLambda {
|
||||
private final CamelizeOption option;
|
||||
|
||||
public CamelizeLambda(boolean capitalizeFirst) {
|
||||
if (capitalizeFirst) {
|
||||
option = UPPERCASE_FIRST_CHAR;
|
||||
} else {
|
||||
option = LOWERCASE_FIRST_LETTER;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatFragment(String fragment) {
|
||||
return camelize(fragment, option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.openapitools.codegen.languages.AbstractTypeScriptClientCodegen.ParameterExpander.ParamStyle.*;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -757,7 +758,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
operationId = toSafeIdentifier(operationId);
|
||||
|
||||
return operationId;
|
||||
@ -802,7 +803,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
case original:
|
||||
return name;
|
||||
case camelCase:
|
||||
return camelize(name, true);
|
||||
return camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
case PascalCase:
|
||||
return camelize(name);
|
||||
case snake_case:
|
||||
@ -820,7 +821,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
case original:
|
||||
return name;
|
||||
case camelCase:
|
||||
return camelize(name, true);
|
||||
return camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
case PascalCase:
|
||||
return camelize(name);
|
||||
case snake_case:
|
||||
@ -911,7 +912,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
case original:
|
||||
return name;
|
||||
case camelCase:
|
||||
return camelize(underscore(name), true);
|
||||
return camelize(underscore(name), LOWERCASE_FIRST_LETTER);
|
||||
case PascalCase:
|
||||
return camelize(underscore(name));
|
||||
case snake_case:
|
||||
|
@ -30,6 +30,7 @@ import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@ -267,7 +268,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
@ -394,11 +395,11 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
|
||||
public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@ -807,7 +808,7 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public String toOperationId(String operationId) {
|
||||
// rename to empty_method_name_1 (e.g.) if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
operationId = camelize("empty_method_name_" + emptyMethodNameCounter++, true);
|
||||
operationId = camelize("empty_method_name_" + emptyMethodNameCounter++, LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("Empty method name (operationId) found. Renamed to {}", operationId);
|
||||
return operationId;
|
||||
}
|
||||
@ -825,7 +826,7 @@ public class BashClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
return camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,6 +32,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -733,19 +734,19 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize(sanitizeName("call_" + operationId), true);
|
||||
String newOperationId = camelize(sanitizeName("call_" + operationId), LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
String newOperationId = camelize(sanitizeName("call_" + operationId), true);
|
||||
String newOperationId = camelize(sanitizeName("call_" + operationId), LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (starting with a number) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
return camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,6 +31,7 @@ import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -835,7 +836,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
case original:
|
||||
return name;
|
||||
case camelCase:
|
||||
return camelize(name, true);
|
||||
return camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
case PascalCase:
|
||||
return camelize(name);
|
||||
case snake_case:
|
||||
|
@ -42,6 +42,7 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -490,7 +491,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
case original:
|
||||
return name;
|
||||
case camelCase:
|
||||
return camelize(name, true);
|
||||
return camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
case PascalCase:
|
||||
return camelize(name);
|
||||
case snake_case:
|
||||
|
@ -37,6 +37,7 @@ import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isEmpty;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -415,7 +416,7 @@ public class CSharpNetCoreReducedClientCodegen extends AbstractCSharpCodegen {
|
||||
case original:
|
||||
return name;
|
||||
case camelCase:
|
||||
return camelize(name, true);
|
||||
return camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
case PascalCase:
|
||||
return camelize(name);
|
||||
case snake_case:
|
||||
|
@ -32,6 +32,7 @@ import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class CppTizenClientCodegen extends AbstractCppCodegen implements CodegenConfig {
|
||||
@ -311,7 +312,7 @@ public class CppTizenClientCodegen extends AbstractCppCodegen implements Codegen
|
||||
}
|
||||
|
||||
// add_pet_by_id => addPetById
|
||||
return camelize(operationId, true);
|
||||
return camelize(operationId, LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
/**
|
||||
* Output the Getter name for boolean property, e.g. getActive
|
||||
|
@ -485,7 +485,7 @@ public class CppUE4ClientCodegen extends AbstractCppCodegen {
|
||||
languageSpecificPrimitives.contains(type)) {
|
||||
return type;
|
||||
} else {
|
||||
return modelNamePrefix + camelize(sanitizeName(type), false);
|
||||
return modelNamePrefix + camelize(sanitizeName(type));
|
||||
}
|
||||
}
|
||||
|
||||
@ -500,7 +500,7 @@ public class CppUE4ClientCodegen extends AbstractCppCodegen {
|
||||
}
|
||||
|
||||
//Unreal variable names are CamelCase
|
||||
String camelCaseName = camelize(name, false);
|
||||
String camelCaseName = camelize(name);
|
||||
|
||||
//Avoid empty variable name at all costs
|
||||
if(!camelCaseName.isEmpty()) {
|
||||
@ -527,7 +527,7 @@ public class CppUE4ClientCodegen extends AbstractCppCodegen {
|
||||
|
||||
@Override
|
||||
public String toApiName(String type) {
|
||||
return modelNamePrefix + camelize(type, false) + "Api";
|
||||
return modelNamePrefix + camelize(type) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,6 +43,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@ -187,11 +188,11 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
@ -199,7 +200,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), true);
|
||||
operationId = camelize("call_" + operationId, true);
|
||||
operationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
return operationId;
|
||||
@ -226,7 +227,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
final String varName = camelize(name.replaceAll("[^a-zA-Z0-9_]", ""), true);
|
||||
final String varName = camelize(name.replaceAll("[^a-zA-Z0-9_]", ""), LOWERCASE_FIRST_LETTER);
|
||||
return isReservedWord(varName) ? escapeReservedWord(name) : varName;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -297,7 +298,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
// underscore the variable name
|
||||
// petId => pet_id
|
||||
name = camelize(dropDots(name), true);
|
||||
name = camelize(dropDots(name), LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
|
@ -41,6 +41,7 @@ import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class GoClientCodegen extends AbstractGoCodegen {
|
||||
@ -392,7 +393,7 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
@Override
|
||||
public CodegenProperty fromProperty(String name, Schema p, boolean required) {
|
||||
CodegenProperty prop = super.fromProperty(name, p, required);
|
||||
String cc = camelize(prop.name, true);
|
||||
String cc = camelize(prop.name, LOWERCASE_FIRST_LETTER);
|
||||
if (isReservedWord(cc)) {
|
||||
cc = escapeReservedWord(cc);
|
||||
}
|
||||
|
@ -43,6 +43,8 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.UPPERCASE_FIRST_CHAR;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -1171,9 +1173,10 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
||||
}
|
||||
|
||||
public String toVarName(String prefix, String name) {
|
||||
Boolean hasPrefix = !StringUtils.isBlank(prefix);
|
||||
boolean hasPrefix = !StringUtils.isBlank(prefix);
|
||||
name = underscore(sanitizeName(name.replaceAll("-", "_")));
|
||||
name = camelize(name, !hasPrefix);
|
||||
name = camelize(name, hasPrefix ? UPPERCASE_FIRST_CHAR : LOWERCASE_FIRST_LETTER);
|
||||
|
||||
if (hasPrefix) {
|
||||
return prefix + name;
|
||||
} else {
|
||||
@ -1227,7 +1230,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
operationId = escapeIdentifier("op", camelize(sanitizeName(operationId), true));
|
||||
operationId = escapeIdentifier("op", camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER));
|
||||
return operationId;
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class HaskellServantCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@ -592,7 +593,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
op.vendorExtensions.put("x-client-type", joinStrings(" -> ", type));
|
||||
op.vendorExtensions.put("x-form-name", "Form" + camelize(op.operationId));
|
||||
for (CodegenParameter param : op.formParams) {
|
||||
param.vendorExtensions.put("x-form-prefix", camelize(op.operationId, true));
|
||||
param.vendorExtensions.put("x-form-prefix", camelize(op.operationId, LOWERCASE_FIRST_LETTER));
|
||||
}
|
||||
return op;
|
||||
}
|
||||
@ -658,7 +659,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
|
||||
// From the model name, compute the prefix for the fields.
|
||||
String prefix = camelize(model.classname, true);
|
||||
String prefix = camelize(model.classname, LOWERCASE_FIRST_LETTER);
|
||||
for (CodegenProperty prop : model.vars) {
|
||||
prop.name = toVarName(prefix + camelize(fixOperatorChars(prop.name)));
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.dashize;
|
||||
|
||||
@ -571,7 +572,7 @@ public class HaskellYesodServerCodegen extends DefaultCodegen implements Codegen
|
||||
}
|
||||
|
||||
// From the model name, compute the prefix for the fields.
|
||||
String prefix = camelize(model.classname, true);
|
||||
String prefix = camelize(model.classname, LOWERCASE_FIRST_LETTER);
|
||||
for (CodegenProperty prop : model.vars) {
|
||||
prop.name = toVarName(prefix + camelize(fixOperatorChars(prop.name)));
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ import java.util.regex.Pattern;
|
||||
import static com.google.common.base.CaseFormat.LOWER_CAMEL;
|
||||
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
|
||||
import static java.util.Collections.sort;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
@ -762,7 +763,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
for (int i = 0; i < items.length; ++i) {
|
||||
if (items[i].matches("^\\{(.*)\\}$")) { // wrap in {}
|
||||
// camelize path variable
|
||||
items[i] = "{" + camelize(items[i].substring(1, items[i].length() - 1), true) + "}";
|
||||
items[i] = "{" + camelize(items[i].substring(1, items[i].length() - 1), LOWERCASE_FIRST_LETTER) + "}";
|
||||
}
|
||||
}
|
||||
op.path = StringUtils.join(items, "/");
|
||||
|
@ -33,6 +33,7 @@ import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
/**
|
||||
@ -512,7 +513,7 @@ public class JavaPKMSTServerCodegen extends AbstractJavaCodegen {
|
||||
title = title.substring(0, title.length() - 3);
|
||||
}
|
||||
|
||||
this.title = camelize(sanitizeName(title), true);
|
||||
this.title = camelize(sanitizeName(title), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
additionalProperties.put(TITLE, this.title);
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements BeanValidationFeatures {
|
||||
@ -330,7 +331,7 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea
|
||||
Matcher match = pathVariableMatcher.matcher(operation.path);
|
||||
while (match.find()) {
|
||||
String completeMatch = match.group();
|
||||
String replacement = ":" + camelize(match.group(1), true);
|
||||
String replacement = ":" + camelize(match.group(1), LOWERCASE_FIRST_LETTER);
|
||||
operation.path = operation.path.replace(completeMatch, replacement);
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
|
||||
public class JavascriptApolloClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@ -507,7 +508,7 @@ public class JavascriptApolloClientCodegen extends DefaultCodegen implements Cod
|
||||
case original:
|
||||
return name;
|
||||
case camelCase:
|
||||
return camelize(name, true);
|
||||
return camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
case PascalCase:
|
||||
return camelize(name);
|
||||
case snake_case:
|
||||
@ -840,18 +841,18 @@ public class JavascriptApolloClientCodegen extends DefaultCodegen implements Cod
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (starting with a number) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
|
||||
public class JavascriptClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@ -492,7 +493,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
case original:
|
||||
return name;
|
||||
case camelCase:
|
||||
return camelize(name, true);
|
||||
return camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
case PascalCase:
|
||||
return camelize(name);
|
||||
case snake_case:
|
||||
@ -825,18 +826,18 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (starting with a number) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@ -179,7 +180,7 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
|
||||
|
||||
// camelize the variable name
|
||||
// pet_id => PetId
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*"))
|
||||
@ -287,11 +288,11 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
|
||||
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
|
||||
}
|
||||
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
String newOperationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.dashize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
@ -708,7 +709,7 @@ public class K6ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
case original:
|
||||
return name;
|
||||
case camelCase:
|
||||
return camelize(name, true);
|
||||
return camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
case PascalCase:
|
||||
return camelize(name);
|
||||
case snake_case:
|
||||
|
@ -42,6 +42,7 @@ import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
@ -643,7 +644,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
if (title.toUpperCase(Locale.ROOT).endsWith("API"))
|
||||
title = title.substring(0, title.length() - 3);
|
||||
|
||||
this.title = camelize(sanitizeName(title), true);
|
||||
this.title = camelize(sanitizeName(title), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
additionalProperties.put(TITLE, this.title);
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class NimClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@ -253,10 +254,10 @@ public class NimClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
String sanitizedOperationId = sanitizeName(operationId);
|
||||
|
||||
if (isReservedWord(sanitizedOperationId)) {
|
||||
sanitizedOperationId = "call" + StringUtils.camelize(sanitizedOperationId, false);
|
||||
sanitizedOperationId = "call" + StringUtils.camelize(sanitizedOperationId);
|
||||
}
|
||||
|
||||
return StringUtils.camelize(sanitizedOperationId, true);
|
||||
return StringUtils.camelize(sanitizedOperationId, LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -320,7 +321,7 @@ public class NimClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name)) {
|
||||
@ -350,7 +351,7 @@ public class NimClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
String name = StringUtils.camelize(property.name, false);
|
||||
String name = StringUtils.camelize(property.name);
|
||||
|
||||
if (name.matches("\\d.*")) { // starts with number
|
||||
return "`" + name + "`";
|
||||
@ -362,7 +363,7 @@ public class NimClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toEnumVarName(String name, String datatype) {
|
||||
name = name.replace(" ", "_");
|
||||
name = StringUtils.camelize(name, false);
|
||||
name = StringUtils.camelize(name);
|
||||
|
||||
if (name.matches("\\d.*")) { // starts with number
|
||||
return "`" + name + "`";
|
||||
|
@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@ -573,7 +574,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// e.g. `pet_id` to `petId`
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// for reserved word or word starting with number, prepend `_`
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
@ -618,11 +619,12 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, camelize(sanitizeName("call_" + operationId), true));
|
||||
operationId = "call_" + operationId;
|
||||
final String newName = "call_" + operationId;
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, newName);
|
||||
operationId = newName;
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
return camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
public void setClassPrefix(String classPrefix) {
|
||||
@ -677,6 +679,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
/**
|
||||
* Return the default value of the schema
|
||||
*
|
||||
* @param p OpenAPI schema object
|
||||
* @return string presentation of the default value of the schema
|
||||
*/
|
||||
@ -795,5 +798,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GeneratorLanguage generatorLanguage() { return GeneratorLanguage.OBJECTIVE_C; }
|
||||
public GeneratorLanguage generatorLanguage() {
|
||||
return GeneratorLanguage.OBJECTIVE_C;
|
||||
}
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ public class PhpLaravelServerCodegen extends AbstractPhpCodegen {
|
||||
return "DefaultController";
|
||||
}
|
||||
|
||||
return camelize(name, false) + "Controller";
|
||||
return camelize(name) + "Controller";
|
||||
}
|
||||
|
||||
protected String controllerFileFolder() {
|
||||
@ -298,7 +298,7 @@ public class PhpLaravelServerCodegen extends AbstractPhpCodegen {
|
||||
return "DefaultController";
|
||||
}
|
||||
|
||||
return camelize(name, false) + "Controller";
|
||||
return camelize(name) + "Controller";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,6 +32,7 @@ import org.openapitools.codegen.meta.Stability;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -273,7 +274,7 @@ public class PhpSilexServerCodegen extends DefaultCodegen implements CodegenConf
|
||||
for (int i = 0; i < items.length; ++i) {
|
||||
if (items[i].matches("^\\{(.*)\\}$")) { // wrap in {}
|
||||
// camelize path variable
|
||||
items[i] = "{" + camelize(items[i].substring(1, items[i].length() - 1), true) + "}";
|
||||
items[i] = "{" + camelize(items[i].substring(1, items[i].length() - 1), LOWERCASE_FIRST_LETTER) + "}";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -613,14 +613,14 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
|
||||
if (name.isEmpty()) {
|
||||
return "DefaultApiInterface";
|
||||
}
|
||||
return camelize(name, false) + "ApiInterface";
|
||||
return camelize(name) + "ApiInterface";
|
||||
}
|
||||
|
||||
protected String toControllerName(String name) {
|
||||
if (name.isEmpty()) {
|
||||
return "DefaultController";
|
||||
}
|
||||
return camelize(name, false) + "Controller";
|
||||
return camelize(name) + "Controller";
|
||||
}
|
||||
|
||||
protected String toSymfonyService(String name) {
|
||||
|
@ -43,6 +43,7 @@ import java.io.Writer;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -566,7 +567,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if ("PascalCase".equals(operationIdNaming)) {
|
||||
return camelize(sanitizedOperationId);
|
||||
} else if ("camelCase".equals(operationIdNaming)) {
|
||||
return camelize(sanitizedOperationId, true);
|
||||
return camelize(sanitizedOperationId, LOWERCASE_FIRST_LETTER);
|
||||
} else if ("snake_case".equals(operationIdNaming)) {
|
||||
return underscore(sanitizedOperationId);
|
||||
} else {
|
||||
|
@ -1275,7 +1275,7 @@ public class RustServerCodegen extends AbstractRustCodegen implements CodegenCon
|
||||
int position = property.dataType.lastIndexOf(":");
|
||||
property.dataType = property.dataType.substring(0, position) + camelize(property.dataType.substring(position));
|
||||
} else {
|
||||
property.dataType = camelize(property.dataType, false);
|
||||
property.dataType = camelize(property.dataType);
|
||||
}
|
||||
property.isPrimitiveType = property.isContainer && languageSpecificPrimitives.contains(typeMapping.get(property.complexType));
|
||||
} else {
|
||||
|
@ -302,16 +302,6 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code
|
||||
}
|
||||
}
|
||||
|
||||
private static abstract class CustomLambda implements Mustache.Lambda {
|
||||
@Override
|
||||
public void execute(Template.Fragment frag, Writer out) throws IOException {
|
||||
final StringWriter tempWriter = new StringWriter();
|
||||
frag.execute(tempWriter);
|
||||
out.write(formatFragment(tempWriter.toString()));
|
||||
}
|
||||
|
||||
public abstract String formatFragment(String fragment);
|
||||
}
|
||||
|
||||
private static class JavadocLambda extends CustomLambda {
|
||||
@Override
|
||||
@ -334,19 +324,6 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code
|
||||
}
|
||||
}
|
||||
|
||||
private static class CamelizeLambda extends CustomLambda {
|
||||
private final boolean capitalizeFirst;
|
||||
|
||||
public CamelizeLambda(boolean capitalizeFirst) {
|
||||
this.capitalizeFirst = capitalizeFirst;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatFragment(String fragment) {
|
||||
return camelize(fragment, !capitalizeFirst);
|
||||
}
|
||||
}
|
||||
|
||||
private class EnumEntryLambda extends CustomLambda {
|
||||
@Override
|
||||
public String formatFragment(String fragment) {
|
||||
|
@ -30,6 +30,7 @@ import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
/*
|
||||
@ -200,7 +201,7 @@ public class ScalaHttpClientCodegen extends AbstractScalaCodegen implements Code
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
return camelize(operationId, true);
|
||||
return camelize(operationId, LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class ScalaLagomServerCodegen extends AbstractScalaCodegen implements CodegenConfig {
|
||||
@ -163,7 +164,7 @@ public class ScalaLagomServerCodegen extends AbstractScalaCodegen implements Cod
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
return camelize(operationId, true);
|
||||
return camelize(operationId, LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,6 +41,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.rightPad;
|
||||
import static org.openapitools.codegen.languages.AbstractJavaCodegen.DATE_LIBRARY;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class ScalaPlayFrameworkServerCodegen extends AbstractScalaCodegen implements CodegenConfig {
|
||||
@ -243,7 +244,7 @@ public class ScalaPlayFrameworkServerCodegen extends AbstractScalaCodegen implem
|
||||
Matcher match = pathVariableMatcher.matcher(operation.path);
|
||||
while (match.find()) {
|
||||
String completeMatch = match.group();
|
||||
String replacement = ":" + camelize(match.group(1), true);
|
||||
String replacement = ":" + camelize(match.group(1), LOWERCASE_FIRST_LETTER);
|
||||
operation.path = operation.path.replace(completeMatch, replacement);
|
||||
}
|
||||
|
||||
@ -265,7 +266,7 @@ public class ScalaPlayFrameworkServerCodegen extends AbstractScalaCodegen implem
|
||||
for (ModelMap mo : outer.getModels()) {
|
||||
CodegenModel cm = mo.getModel();
|
||||
postProcessModelsEnum(outer);
|
||||
cm.classVarName = camelize(cm.classVarName, true);
|
||||
cm.classVarName = camelize(cm.classVarName, LOWERCASE_FIRST_LETTER);
|
||||
modelsByClassName.put(cm.classname, cm);
|
||||
boolean hasFiles = cm.vars.stream().anyMatch(var -> var.isFile);
|
||||
cm.vendorExtensions.put("x-has-files", hasFiles);
|
||||
|
@ -32,6 +32,7 @@ import org.openapitools.codegen.model.ModelMap;
|
||||
import org.openapitools.codegen.model.ModelsMap;
|
||||
import org.openapitools.codegen.model.OperationMap;
|
||||
import org.openapitools.codegen.model.OperationsMap;
|
||||
import org.openapitools.codegen.utils.CamelizeOption;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -44,6 +45,8 @@ import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.*;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class ScalaSttpClientCodegen extends AbstractScalaCodegen implements CodegenConfig {
|
||||
@ -560,17 +563,6 @@ public class ScalaSttpClientCodegen extends AbstractScalaCodegen implements Code
|
||||
}
|
||||
}
|
||||
|
||||
private static abstract class CustomLambda implements Mustache.Lambda {
|
||||
@Override
|
||||
public void execute(Template.Fragment frag, Writer out) throws IOException {
|
||||
final StringWriter tempWriter = new StringWriter();
|
||||
frag.execute(tempWriter);
|
||||
out.write(formatFragment(tempWriter.toString()));
|
||||
}
|
||||
|
||||
public abstract String formatFragment(String fragment);
|
||||
}
|
||||
|
||||
private static class JavadocLambda extends CustomLambda {
|
||||
@Override
|
||||
public String formatFragment(String fragment) {
|
||||
@ -592,19 +584,6 @@ public class ScalaSttpClientCodegen extends AbstractScalaCodegen implements Code
|
||||
}
|
||||
}
|
||||
|
||||
private static class CamelizeLambda extends CustomLambda {
|
||||
private final boolean capitalizeFirst;
|
||||
|
||||
public CamelizeLambda(boolean capitalizeFirst) {
|
||||
this.capitalizeFirst = capitalizeFirst;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatFragment(String fragment) {
|
||||
return camelize(fragment, !capitalizeFirst);
|
||||
}
|
||||
}
|
||||
|
||||
private class EnumEntryLambda extends CustomLambda {
|
||||
@Override
|
||||
public String formatFragment(String fragment) {
|
||||
|
@ -36,6 +36,7 @@ import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -152,7 +153,7 @@ public class ScalazClientCodegen extends AbstractScalaCodegen implements Codegen
|
||||
case original:
|
||||
return name;
|
||||
case camelCase:
|
||||
return camelize(name, true);
|
||||
return camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
case PascalCase:
|
||||
return camelize(name);
|
||||
case snake_case:
|
||||
@ -228,7 +229,7 @@ public class ScalazClientCodegen extends AbstractScalaCodegen implements Codegen
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
return camelize(operationId, true);
|
||||
return camelize(operationId, LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
private static abstract class CustomLambda implements Mustache.Lambda {
|
||||
|
@ -18,6 +18,7 @@
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
import com.samskivert.mustache.Mustache;
|
||||
@ -639,7 +640,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
title = title.substring(0, title.length() - 3);
|
||||
}
|
||||
|
||||
this.title = camelize(sanitizeName(title), true);
|
||||
this.title = camelize(sanitizeName(title), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
additionalProperties.put(TITLE, this.title);
|
||||
}
|
||||
@ -767,7 +768,7 @@ public class SpringCodegen extends AbstractJavaCodegen
|
||||
final List<CodegenSecurity> authMethods = (List<CodegenSecurity>) objs.get("authMethods");
|
||||
if (authMethods != null) {
|
||||
for (final CodegenSecurity authMethod : authMethods) {
|
||||
authMethod.name = camelize(sanitizeName(authMethod.name), true);
|
||||
authMethod.name = camelize(sanitizeName(authMethod.name), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ import java.time.Instant;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@ -827,7 +828,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// Throw exception if method name is empty.
|
||||
// This should not happen but keep the check just in case
|
||||
@ -837,15 +838,15 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize(("call_" + operationId), true);
|
||||
String newOperationId = camelize(("call_" + operationId), LOWERCASE_FIRST_LETTER);
|
||||
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, newOperationId);
|
||||
return newOperationId;
|
||||
}
|
||||
|
||||
// operationId starts with a number
|
||||
if (operationId.matches("^\\d.*")) {
|
||||
LOGGER.warn("{} (starting with a number) cannot be used as method name. Renamed to {}", operationId, camelize(sanitizeName("call_" + operationId), true));
|
||||
operationId = camelize(sanitizeName("call_" + operationId), true);
|
||||
LOGGER.warn("{} (starting with a number) cannot be used as method name. Renamed to {}", operationId, camelize(sanitizeName("call_" + operationId), LOWERCASE_FIRST_LETTER));
|
||||
operationId = camelize(sanitizeName("call_" + operationId), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
|
||||
@ -864,7 +865,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
// camelize the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// for reserved words surround with `` or append _
|
||||
if (isReservedWord(name)) {
|
||||
@ -894,7 +895,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
// camelize(lower) the variable name
|
||||
// pet_id => petId
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
|
||||
// for reserved words surround with ``
|
||||
if (isReservedWord(name)) {
|
||||
@ -1019,7 +1020,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
if (enumUnknownDefaultCase) {
|
||||
if (name.equals(enumUnknownDefaultCaseName)) {
|
||||
return camelize(name, true);
|
||||
return camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1031,18 +1032,18 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
// Prefix with underscore if name starts with number
|
||||
if (name.matches("\\d.*")) {
|
||||
return "_" + replaceSpecialCharacters(camelize(name, true));
|
||||
return "_" + replaceSpecialCharacters(camelize(name, LOWERCASE_FIRST_LETTER));
|
||||
}
|
||||
|
||||
// for symbol, e.g. $, #
|
||||
if (getSymbolName(name) != null) {
|
||||
return camelize(WordUtils.capitalizeFully(getSymbolName(name).toUpperCase(Locale.ROOT)), true);
|
||||
return camelize(WordUtils.capitalizeFully(getSymbolName(name).toUpperCase(Locale.ROOT)), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
// Camelize only when we have a structure defined below
|
||||
Boolean camelized = false;
|
||||
boolean camelized = false;
|
||||
if (name.matches("[A-Z][a-z0-9]+[a-zA-Z0-9]*")) {
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
camelized = true;
|
||||
}
|
||||
|
||||
@ -1062,7 +1063,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
char[] separators = {'-', '_', ' ', ':', '(', ')'};
|
||||
return camelize(replaceSpecialCharacters(WordUtils.capitalizeFully(StringUtils.lowerCase(name), separators)
|
||||
.replaceAll("[-_ :\\(\\)]", "")),
|
||||
true);
|
||||
LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
private String replaceSpecialCharacters(String name) {
|
||||
|
@ -36,6 +36,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.capitalize;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
|
||||
public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||
@ -731,7 +732,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
||||
if ("kebab-case".equals(fileNaming)) {
|
||||
name = dashize(underscore(name));
|
||||
} else {
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
@ -54,6 +54,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
|
||||
@ -588,10 +589,10 @@ public class TypeScriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
// append _ at the beginning, e.g. _return
|
||||
if (isReservedWord(operationId)) {
|
||||
return escapeReservedWord(camelize(sanitizeName(operationId), true));
|
||||
return escapeReservedWord(camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER));
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
return camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
public void setModelPropertyNaming(String naming) {
|
||||
@ -614,7 +615,7 @@ public class TypeScriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
case original:
|
||||
return name;
|
||||
case camelCase:
|
||||
return camelize(name, true);
|
||||
return camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
case PascalCase:
|
||||
return camelize(name);
|
||||
case snake_case:
|
||||
|
@ -31,6 +31,7 @@ import org.openapitools.codegen.model.OperationsMap;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class TypeScriptInversifyClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||
@ -315,7 +316,7 @@ public class TypeScriptInversifyClientCodegen extends AbstractTypeScriptClientCo
|
||||
if (name.length() == 0) {
|
||||
return "default.service";
|
||||
}
|
||||
return camelize(name, true) + ".service";
|
||||
return camelize(name, LOWERCASE_FIRST_LETTER) + ".service";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -325,7 +326,7 @@ public class TypeScriptInversifyClientCodegen extends AbstractTypeScriptClientCo
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
return camelize(toModelName(name), true);
|
||||
return camelize(toModelName(name), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,6 +33,7 @@ import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.capitalize;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
|
||||
public class TypeScriptNestjsClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||
@ -543,7 +544,7 @@ public class TypeScriptNestjsClientCodegen extends AbstractTypeScriptClientCodeg
|
||||
if ("kebab-case".equals(fileNaming)) {
|
||||
name = dashize(underscore(name));
|
||||
} else {
|
||||
name = camelize(name, true);
|
||||
name = camelize(name, LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.capitalize;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||
@ -141,7 +142,7 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
|
||||
if (importMapping.containsKey(name)) {
|
||||
return importMapping.get(name);
|
||||
}
|
||||
return camelize(name, true) + apiSuffix;
|
||||
return camelize(name, LOWERCASE_FIRST_LETTER) + apiSuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -159,7 +160,7 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
|
||||
return importMapping.get(name);
|
||||
}
|
||||
|
||||
return DEFAULT_MODEL_FILENAME_DIRECTORY_PREFIX + camelize(toModelName(name), true);
|
||||
return DEFAULT_MODEL_FILENAME_DIRECTORY_PREFIX + camelize(toModelName(name), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -168,7 +169,7 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
|
||||
return importMapping.get(name);
|
||||
}
|
||||
|
||||
return DEFAULT_MODEL_IMPORT_DIRECTORY_PREFIX + modelPackage() + "/" + camelize(toModelName(name), true);
|
||||
return DEFAULT_MODEL_IMPORT_DIRECTORY_PREFIX + modelPackage() + "/" + camelize(toModelName(name), LOWERCASE_FIRST_LETTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,10 +20,13 @@ package org.openapitools.codegen.templating.mustache;
|
||||
import com.samskivert.mustache.Mustache;
|
||||
import com.samskivert.mustache.Template;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.utils.CamelizeOption;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.UPPERCASE_FIRST_CHAR;
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
|
||||
/**
|
||||
@ -42,10 +45,14 @@ import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
public class CamelCaseLambda implements Mustache.Lambda {
|
||||
private CodegenConfig generator = null;
|
||||
private Boolean escapeParam = false;
|
||||
private Boolean lowercaseFirstLetter = true;
|
||||
private CamelizeOption option = LOWERCASE_FIRST_LETTER;
|
||||
|
||||
public CamelCaseLambda(boolean lowercaseFirstLetter) {
|
||||
this.lowercaseFirstLetter = lowercaseFirstLetter;
|
||||
if (lowercaseFirstLetter) {
|
||||
option = LOWERCASE_FIRST_LETTER;
|
||||
} else {
|
||||
option = UPPERCASE_FIRST_CHAR;
|
||||
}
|
||||
}
|
||||
|
||||
public CamelCaseLambda() {}
|
||||
@ -62,7 +69,7 @@ public class CamelCaseLambda implements Mustache.Lambda {
|
||||
|
||||
@Override
|
||||
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
|
||||
String text = camelize(fragment.execute().replace(" ", "_"), lowercaseFirstLetter);
|
||||
String text = camelize(fragment.execute().replace(" ", "_"), option);
|
||||
if (generator != null) {
|
||||
text = generator.sanitizeName(text);
|
||||
if (generator.reservedWords().contains(text)) {
|
||||
|
@ -0,0 +1,7 @@
|
||||
package org.openapitools.codegen.utils;
|
||||
|
||||
public enum CamelizeOption {
|
||||
UPPERCASE_FIRST_CHAR,
|
||||
LOWERCASE_FIRST_LETTER,
|
||||
LOWERCASE_FIRST_CHAR
|
||||
}
|
@ -17,6 +17,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.UPPERCASE_FIRST_CHAR;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
/**
|
||||
@ -30,7 +32,7 @@ public class StringUtils {
|
||||
|
||||
// A cache of camelized words. The camelize() method is invoked many times with the same
|
||||
// arguments, this cache is used to optimized performance.
|
||||
private static Cache<Pair<String, Boolean>, String> camelizedWordsCache;
|
||||
private static Cache<Pair<String, CamelizeOption>, String> camelizedWordsCache;
|
||||
|
||||
// A cache of underscored words, used to optimize the performance of the underscore() method.
|
||||
private static Cache<String, String> underscoreWordsCache;
|
||||
@ -111,7 +113,7 @@ public class StringUtils {
|
||||
* @return camelized string
|
||||
*/
|
||||
public static String camelize(String word) {
|
||||
return camelize(word, false);
|
||||
return camelize(word, UPPERCASE_FIRST_CHAR);
|
||||
}
|
||||
|
||||
private static Pattern camelizeSlashPattern = Pattern.compile("\\/(.?)");
|
||||
@ -124,16 +126,16 @@ public class StringUtils {
|
||||
/**
|
||||
* Camelize name (parameter, property, method, etc)
|
||||
*
|
||||
* @param inputWord string to be camelize
|
||||
* @param lowercaseFirstLetter lower case for first letter if set to true
|
||||
* @param inputWord string to be camelize
|
||||
* @param camelizeOption option for the camelize result
|
||||
* @return camelized string
|
||||
*/
|
||||
public static String camelize(final String inputWord, boolean lowercaseFirstLetter) {
|
||||
Pair<String, Boolean> key = new ImmutablePair<>(inputWord, lowercaseFirstLetter);
|
||||
public static String camelize(final String inputWord, CamelizeOption camelizeOption) {
|
||||
Pair<String, CamelizeOption> key = new ImmutablePair<>(inputWord, camelizeOption);
|
||||
|
||||
return camelizedWordsCache.get(key, pair -> {
|
||||
String word = pair.getKey();
|
||||
Boolean lowerFirstLetter = pair.getValue();
|
||||
CamelizeOption option = pair.getValue();
|
||||
// Replace all slashes with dots (package separator)
|
||||
Matcher m = camelizeSlashPattern.matcher(word);
|
||||
while (m.find()) {
|
||||
@ -185,15 +187,13 @@ public class StringUtils {
|
||||
m = camelizeHyphenPattern.matcher(word);
|
||||
}
|
||||
|
||||
if (lowerFirstLetter && word.length() > 0) {
|
||||
int i = 0;
|
||||
char charAt = word.charAt(i);
|
||||
while (i + 1 < word.length() && !((charAt >= 'a' && charAt <= 'z') || (charAt >= 'A' && charAt <= 'Z'))) {
|
||||
i = i + 1;
|
||||
charAt = word.charAt(i);
|
||||
}
|
||||
i = i + 1;
|
||||
word = word.substring(0, i).toLowerCase(Locale.ROOT) + word.substring(i);
|
||||
switch (option) {
|
||||
case LOWERCASE_FIRST_LETTER:
|
||||
word = lowercaseFirstLetter(word);
|
||||
break;
|
||||
case LOWERCASE_FIRST_CHAR:
|
||||
word = word.substring(0, 1).toLowerCase(Locale.ROOT) + word.substring(1);
|
||||
break;
|
||||
}
|
||||
|
||||
// remove all underscore
|
||||
@ -202,6 +202,20 @@ public class StringUtils {
|
||||
});
|
||||
}
|
||||
|
||||
private static String lowercaseFirstLetter(String word) {
|
||||
if (word.length() > 0) {
|
||||
int i = 0;
|
||||
char charAt = word.charAt(i);
|
||||
while (i + 1 < word.length() && !((charAt >= 'a' && charAt <= 'z') || (charAt >= 'A' && charAt <= 'Z'))) {
|
||||
i = i + 1;
|
||||
charAt = word.charAt(i);
|
||||
}
|
||||
i = i + 1;
|
||||
word = word.substring(0, i).toLowerCase(Locale.ROOT) + word.substring(i);
|
||||
}
|
||||
return word;
|
||||
}
|
||||
|
||||
private static class EscapedNameOptions {
|
||||
public EscapedNameOptions(String name, Set<String> specialChars, List<String> charactersToAllow, String appendToReplacement) {
|
||||
this.name = name;
|
||||
|
@ -103,7 +103,7 @@ public class AbstractJavaCodegenTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertVarName() throws Exception {
|
||||
public void convertVarName() {
|
||||
Assert.assertEquals(fakeJavaCodegen.toVarName("name"), "name");
|
||||
Assert.assertEquals(fakeJavaCodegen.toVarName("$name"), "$name");
|
||||
Assert.assertEquals(fakeJavaCodegen.toVarName("nam$$e"), "nam$$e");
|
||||
@ -119,10 +119,15 @@ public class AbstractJavaCodegenTest {
|
||||
Assert.assertEquals(fakeJavaCodegen.toVarName("1A"), "_1A");
|
||||
Assert.assertEquals(fakeJavaCodegen.toVarName("1AAAA"), "_1AAAA");
|
||||
Assert.assertEquals(fakeJavaCodegen.toVarName("1AAaa"), "_1aAaa");
|
||||
|
||||
AbstractJavaCodegen withCaml = new P_AbstractJavaCodegen();
|
||||
withCaml.setCamelCaseDollarSign(true);
|
||||
Assert.assertEquals(withCaml.toVarName("$name"), "$Name");
|
||||
Assert.assertEquals(withCaml.toVarName("1AAaa"), "_1AAaa");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertModelName() throws Exception {
|
||||
public void convertModelName() {
|
||||
Assert.assertEquals(fakeJavaCodegen.toModelName("name"), "Name");
|
||||
Assert.assertEquals(fakeJavaCodegen.toModelName("$name"), "Name");
|
||||
Assert.assertEquals(fakeJavaCodegen.toModelName("nam#e"), "Name");
|
||||
|
@ -66,7 +66,7 @@ public class KotlinReservedWordsTest {
|
||||
final DefaultCodegen codegen = new KotlinClientCodegen();
|
||||
final Schema schema = new Schema();
|
||||
final String escaped = "`" + reservedWord + "`";
|
||||
final String titleCased = StringUtils.camelize(reservedWord, false);
|
||||
final String titleCased = StringUtils.camelize(reservedWord);
|
||||
|
||||
codegen.setOpenAPI(openAPI);
|
||||
CodegenModel model = codegen.fromModel(reservedWord, schema);
|
||||
@ -106,7 +106,7 @@ public class KotlinReservedWordsTest {
|
||||
final DefaultCodegen codegen = new KotlinClientCodegen();
|
||||
|
||||
final String escaped = "`" + reservedWord + "`";
|
||||
final String titleCased = StringUtils.camelize(reservedWord, false);
|
||||
final String titleCased = StringUtils.camelize(reservedWord);
|
||||
|
||||
Schema linked = openAPI.getComponents().getSchemas().get("Linked");
|
||||
|
||||
|
@ -3,6 +3,8 @@ package org.openapitools.codegen.utils;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_CHAR;
|
||||
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
|
||||
import static org.openapitools.codegen.utils.StringUtils.*;
|
||||
|
||||
public class StringUtilsTest {
|
||||
@ -21,14 +23,18 @@ public class StringUtilsTest {
|
||||
Assert.assertEquals(camelize("some_value"), "SomeValue");
|
||||
Assert.assertEquals(camelize("$type"), "$Type");
|
||||
|
||||
Assert.assertEquals(camelize("abcd", true), "abcd");
|
||||
Assert.assertEquals(camelize("some-value", true), "someValue");
|
||||
Assert.assertEquals(camelize("some_value", true), "someValue");
|
||||
Assert.assertEquals(camelize("Abcd", true), "abcd");
|
||||
Assert.assertEquals(camelize("$type", true), "$type");
|
||||
Assert.assertEquals(camelize("abcd", LOWERCASE_FIRST_LETTER), "abcd");
|
||||
Assert.assertEquals(camelize("some-value", LOWERCASE_FIRST_LETTER), "someValue");
|
||||
Assert.assertEquals(camelize("some_value", LOWERCASE_FIRST_LETTER), "someValue");
|
||||
Assert.assertEquals(camelize("Abcd", LOWERCASE_FIRST_LETTER), "abcd");
|
||||
Assert.assertEquals(camelize("$type", LOWERCASE_FIRST_LETTER), "$type");
|
||||
|
||||
Assert.assertEquals(camelize("123", true), "123");
|
||||
Assert.assertEquals(camelize("$123", true), "$123");
|
||||
Assert.assertEquals(camelize("123", LOWERCASE_FIRST_LETTER), "123");
|
||||
Assert.assertEquals(camelize("$123", LOWERCASE_FIRST_LETTER), "$123");
|
||||
|
||||
|
||||
Assert.assertEquals(camelize("some-value", LOWERCASE_FIRST_CHAR), "someValue");
|
||||
Assert.assertEquals(camelize("$type", LOWERCASE_FIRST_CHAR), "$Type");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -77,9 +77,9 @@ public class Model200Response {
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Model200Response _200response = (Model200Response) o;
|
||||
return Objects.equals(this.name, _200response.name) &&
|
||||
Objects.equals(this.propertyClass, _200response.propertyClass);
|
||||
Model200Response _200Response = (Model200Response) o;
|
||||
return Objects.equals(this.name, _200Response.name) &&
|
||||
Objects.equals(this.propertyClass, _200Response.propertyClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,25 +25,25 @@ import javax.annotation.Generated;
|
||||
public class ModelList {
|
||||
|
||||
@JsonProperty("123-list")
|
||||
private String _123list;
|
||||
private String _123List;
|
||||
|
||||
public ModelList _123list(String _123list) {
|
||||
this._123list = _123list;
|
||||
public ModelList _123List(String _123List) {
|
||||
this._123List = _123List;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get _123list
|
||||
* @return _123list
|
||||
* Get _123List
|
||||
* @return _123List
|
||||
*/
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
public String get123list() {
|
||||
return _123list;
|
||||
public String get123List() {
|
||||
return _123List;
|
||||
}
|
||||
|
||||
public void set123list(String _123list) {
|
||||
this._123list = _123list;
|
||||
public void set123List(String _123List) {
|
||||
this._123List = _123List;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,19 +55,19 @@ public class ModelList {
|
||||
return false;
|
||||
}
|
||||
ModelList _list = (ModelList) o;
|
||||
return Objects.equals(this._123list, _list._123list);
|
||||
return Objects.equals(this._123List, _list._123List);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(_123list);
|
||||
return Objects.hash(_123List);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class ModelList {\n");
|
||||
sb.append(" _123list: ").append(toIndentedString(_123list)).append("\n");
|
||||
sb.append(" _123List: ").append(toIndentedString(_123List)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class Name {
|
||||
private String property;
|
||||
|
||||
@JsonProperty("123Number")
|
||||
private Integer _123number;
|
||||
private Integer _123Number;
|
||||
|
||||
public Name name(Integer name) {
|
||||
this.name = name;
|
||||
@ -92,23 +92,23 @@ public class Name {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
public Name _123number(Integer _123number) {
|
||||
this._123number = _123number;
|
||||
public Name _123Number(Integer _123Number) {
|
||||
this._123Number = _123Number;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get _123number
|
||||
* @return _123number
|
||||
* Get _123Number
|
||||
* @return _123Number
|
||||
*/
|
||||
|
||||
@ApiModelProperty(readOnly = true, value = "")
|
||||
public Integer get123number() {
|
||||
return _123number;
|
||||
public Integer get123Number() {
|
||||
return _123Number;
|
||||
}
|
||||
|
||||
public void set123number(Integer _123number) {
|
||||
this._123number = _123number;
|
||||
public void set123Number(Integer _123Number) {
|
||||
this._123Number = _123Number;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -123,12 +123,12 @@ public class Name {
|
||||
return Objects.equals(this.name, name.name) &&
|
||||
Objects.equals(this.snakeCase, name.snakeCase) &&
|
||||
Objects.equals(this.property, name.property) &&
|
||||
Objects.equals(this._123number, name._123number);
|
||||
Objects.equals(this._123Number, name._123Number);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, snakeCase, property, _123number);
|
||||
return Objects.hash(name, snakeCase, property, _123Number);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -138,7 +138,7 @@ public class Name {
|
||||
sb.append(" name: ").append(toIndentedString(name)).append("\n");
|
||||
sb.append(" snakeCase: ").append(toIndentedString(snakeCase)).append("\n");
|
||||
sb.append(" property: ").append(toIndentedString(property)).append("\n");
|
||||
sb.append(" _123number: ").append(toIndentedString(_123number)).append("\n");
|
||||
sb.append(" _123Number: ").append(toIndentedString(_123Number)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -25,25 +25,25 @@ import javax.annotation.Generated;
|
||||
public class SpecialModelName {
|
||||
|
||||
@JsonProperty("$special[property.name]")
|
||||
private Long $specialPropertyName;
|
||||
private Long $SpecialPropertyName;
|
||||
|
||||
public SpecialModelName $specialPropertyName(Long $specialPropertyName) {
|
||||
this.$specialPropertyName = $specialPropertyName;
|
||||
public SpecialModelName $SpecialPropertyName(Long $SpecialPropertyName) {
|
||||
this.$SpecialPropertyName = $SpecialPropertyName;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get $specialPropertyName
|
||||
* @return $specialPropertyName
|
||||
* Get $SpecialPropertyName
|
||||
* @return $SpecialPropertyName
|
||||
*/
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
public Long get$SpecialPropertyName() {
|
||||
return $specialPropertyName;
|
||||
return $SpecialPropertyName;
|
||||
}
|
||||
|
||||
public void set$SpecialPropertyName(Long $specialPropertyName) {
|
||||
this.$specialPropertyName = $specialPropertyName;
|
||||
public void set$SpecialPropertyName(Long $SpecialPropertyName) {
|
||||
this.$SpecialPropertyName = $SpecialPropertyName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -54,20 +54,20 @@ public class SpecialModelName {
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
SpecialModelName $specialModelName = (SpecialModelName) o;
|
||||
return Objects.equals(this.$specialPropertyName, $specialModelName.$specialPropertyName);
|
||||
SpecialModelName $SpecialModelName = (SpecialModelName) o;
|
||||
return Objects.equals(this.$SpecialPropertyName, $SpecialModelName.$SpecialPropertyName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash($specialPropertyName);
|
||||
return Objects.hash($SpecialPropertyName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class SpecialModelName {\n");
|
||||
sb.append(" $specialPropertyName: ").append(toIndentedString($specialPropertyName)).append("\n");
|
||||
sb.append(" $SpecialPropertyName: ").append(toIndentedString($SpecialPropertyName)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user