From 314b4cc54f68c32552901ad872615b56119ce9a9 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 6 Dec 2018 16:17:32 +0800 Subject: [PATCH 1/2] remove deprecated methods in default codegen (#1031) --- .../openapitools/codegen/DefaultCodegen.java | 85 +------------------ .../codegen/languages/AbstractAdaCodegen.java | 3 +- .../languages/AbstractApexCodegen.java | 14 +-- .../languages/AbstractCSharpCodegen.java | 25 +++--- .../languages/AbstractEiffelCodegen.java | 10 ++- .../codegen/languages/AbstractGoCodegen.java | 27 +++--- .../languages/AbstractGraphQLCodegen.java | 3 + .../languages/AbstractJavaCodegen.java | 21 ++--- .../AbstractJavaJAXRSServerCodegen.java | 3 +- .../languages/AbstractKotlinCodegen.java | 13 +-- .../codegen/languages/AbstractPhpCodegen.java | 35 +++++--- .../languages/AbstractRubyCodegen.java | 7 +- .../languages/AbstractScalaCodegen.java | 3 +- .../AbstractTypeScriptClientCodegen.java | 24 +++--- .../languages/AndroidClientCodegen.java | 9 +- .../codegen/languages/ApexClientCodegen.java | 3 +- .../languages/CLibcurlClientCodegen.java | 5 +- .../languages/CSharpClientCodegen.java | 12 +-- .../languages/CSharpNancyFXServerCodegen.java | 6 +- .../CSharpRefactorClientCodegen.java | 3 + .../languages/ClojureClientCodegen.java | 12 +-- .../languages/CppPistacheServerCodegen.java | 5 +- .../languages/CppQt5ClientCodegen.java | 8 ++ .../CppQt5QHttpEngineServerCodegen.java | 10 +++ .../languages/CppTizenClientCodegen.java | 3 +- .../codegen/languages/DartClientCodegen.java | 21 +++-- .../languages/DartJaguarClientCodegen.java | 2 + .../languages/ElixirClientCodegen.java | 28 +++--- .../codegen/languages/ElmClientCodegen.java | 11 +-- .../languages/ErlangClientCodegen.java | 21 ++--- .../languages/ErlangProperCodegen.java | 3 + .../languages/ErlangServerCodegen.java | 12 +-- .../codegen/languages/FlashClientCodegen.java | 18 ++-- .../languages/GroovyClientCodegen.java | 3 +- .../languages/HaskellHttpClientCodegen.java | 14 +-- .../languages/HaskellServantCodegen.java | 13 +-- .../codegen/languages/JavaClientCodegen.java | 3 +- .../languages/JavaInflectorServerCodegen.java | 3 +- .../languages/JavaJAXRSSpecServerCodegen.java | 3 +- .../languages/JavaPKMSTServerCodegen.java | 5 +- .../languages/JavaPlayFrameworkCodegen.java | 3 +- .../languages/JavaUndertowServerCodegen.java | 3 +- .../languages/JavascriptClientCodegen.java | 24 +++--- ...JavascriptClosureAngularClientCodegen.java | 12 +-- .../JavascriptFlowtypedClientCodegen.java | 3 +- .../languages/KotlinSpringServerCodegen.java | 1 + .../codegen/languages/LuaClientCodegen.java | 20 +++-- .../codegen/languages/ObjcClientCodegen.java | 22 ++--- .../codegen/languages/PerlClientCodegen.java | 27 +++--- .../languages/PhpLaravelServerCodegen.java | 5 +- .../languages/PhpSilexServerCodegen.java | 10 ++- .../languages/PhpSymfonyServerCodegen.java | 5 +- .../languages/PowerShellClientCodegen.java | 11 +-- .../languages/PythonClientCodegen.java | 26 +++--- .../PythonFlaskConnexionServerCodegen.java | 20 +++-- .../codegen/languages/RClientCodegen.java | 24 +++--- .../codegen/languages/RubyClientCodegen.java | 31 ++++--- .../languages/RubyOnRailsServerCodegen.java | 17 ++-- .../languages/RubySinatraServerCodegen.java | 14 +-- .../codegen/languages/RustClientCodegen.java | 14 +-- .../codegen/languages/RustServerCodegen.java | 41 ++++----- .../languages/ScalaAkkaClientCodegen.java | 3 +- .../languages/ScalaHttpClientCodegen.java | 12 +-- .../languages/ScalaLagomServerCodegen.java | 13 +-- .../languages/ScalazClientCodegen.java | 12 +-- .../codegen/languages/SpringCodegen.java | 7 +- .../languages/StaticHtml2Generator.java | 7 +- .../codegen/languages/Swift3Codegen.java | 27 +++--- .../codegen/languages/Swift4Codegen.java | 27 +++--- .../codegen/languages/SwiftClientCodegen.java | 22 ++--- .../TypeScriptAngularClientCodegen.java | 5 +- .../TypeScriptInversifyClientCodegen.java | 8 +- .../TypeScriptNodeClientCodegen.java | 7 +- .../codegen/mustache/CamelCaseLambda.java | 1 - 74 files changed, 524 insertions(+), 469 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 232bd021497..f66fb7e7e59 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -875,23 +875,6 @@ public class DefaultCodegen implements CodegenConfig { throw new RuntimeException("reserved word " + name + " not allowed"); } - /** - * Return the name with escaped characters. - * - * @param name the name to be escaped - * @param charactersToAllow characters that are not escaped - * @param appdendixToReplacement String to append to replaced characters. - * @return the escaped word - *

- * throws Runtime exception as word is not escaped properly. - * @see org.openapitools.codegen.utils.StringUtils#escape directly instead - * @deprecated since version 3.2.3, may be removed with the next major release (4.0) - */ - @Deprecated - public String escapeSpecialCharacters(String name, List charactersToAllow, String appdendixToReplacement) { - return escape(name, specialCharReplacements, charactersToAllow, appdendixToReplacement); - } - /** * Return the fully-qualified "Model" name for import * @@ -1788,7 +1771,7 @@ public class DefaultCodegen implements CodegenConfig { if (name == null || name.length() == 0) { return name; } - return org.openapitools.codegen.utils.StringUtils.camelize(toVarName(name)); + return camelize(toVarName(name)); } @@ -1812,7 +1795,7 @@ public class DefaultCodegen implements CodegenConfig { CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY); property.name = toVarName(name); property.baseName = name; - property.nameInCamelCase = org.openapitools.codegen.utils.StringUtils.camelize(property.name, false); + property.nameInCamelCase = camelize(property.name, false); property.nameInSnakeCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, property.nameInCamelCase); property.description = escapeText(p.getDescription()); property.unescapedDescription = p.getDescription(); @@ -3309,8 +3292,8 @@ public class DefaultCodegen implements CodegenConfig { } co.operationId = uniqueName; co.operationIdLowerCase = uniqueName.toLowerCase(Locale.ROOT); - co.operationIdCamelCase = org.openapitools.codegen.utils.StringUtils.camelize(uniqueName); - co.operationIdSnakeCase = org.openapitools.codegen.utils.StringUtils.underscore(uniqueName); + co.operationIdCamelCase = camelize(uniqueName); + co.operationIdSnakeCase = underscore(uniqueName); opList.add(co); co.baseName = tag; } @@ -3332,35 +3315,6 @@ public class DefaultCodegen implements CodegenConfig { } } - /** - * Underscore the given word. - * Copied from Twitter elephant bird - * https://github.com/twitter/elephant-bird/blob/master/core/src/main/java/com/twitter/elephantbird/util/Strings.java - * - * @param word The word - * @return The underscored version of the word - * @see org.openapitools.codegen.utils.StringUtils#underscore - * @deprecated since version 3.2.3, may be removed with the next major release (4.0) - */ - @Deprecated - public static String underscore(String word) { - return org.openapitools.codegen.utils.StringUtils.underscore(word); - } - - /** - * Dashize the given word. - * - * @param word The word - * @return The dashized version of the word, e.g. "my-name" - * @see org.openapitools.codegen.utils.StringUtils#dashize - * @deprecated since version 3.2.3, may be removed with the next major release (4.0) - */ - @SuppressWarnings("static-method") - @Deprecated - protected String dashize(String word) { - return org.openapitools.codegen.utils.StringUtils.dashize(word); - } - /** * Generate the next name for the given name, i.e. append "2" to the base name if not ending with a number, * otherwise increase the number by 1. For example: @@ -3560,37 +3514,6 @@ public class DefaultCodegen implements CodegenConfig { return result; } - - /** - * Camelize name (parameter, property, method, etc) with upper case for first letter - * copied from Twitter elephant bird - * https://github.com/twitter/elephant-bird/blob/master/core/src/main/java/com/twitter/elephantbird/util/Strings.java - * - * @param word string to be camelize - * @return camelized string - * @see org.openapitools.codegen.utils.StringUtils#camelize(String) - * @deprecated since version 3.2.3, may be removed with the next major release (4.0) - */ - @Deprecated - public static String camelize(String word) { - return org.openapitools.codegen.utils.StringUtils.camelize(word); - } - - /** - * Camelize name (parameter, property, method, etc) - * - * @param word string to be camelize - * @param lowercaseFirstLetter lower case for first letter if set to true - * @return camelized string - * @see org.openapitools.codegen.utils.StringUtils#camelize(String, boolean) - * @deprecated since version 3.2.3, may be removed with the next major release (4.0) - */ - @Deprecated - public static String camelize(String word, boolean lowercaseFirstLetter) { - return org.openapitools.codegen.utils.StringUtils.camelize(word, lowercaseFirstLetter); - } - - public String apiFilename(String templateName, String tag) { String suffix = apiTemplateFiles().get(templateName); return apiFileFolder() + File.separator + toApiFilename(tag) + suffix; diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractAdaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractAdaCodegen.java index 02e193d8f47..e58e2075e83 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractAdaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractAdaCodegen.java @@ -46,6 +46,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import static org.openapitools.codegen.utils.StringUtils.camelize; abstract public class AbstractAdaCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractAdaCodegen.class); @@ -666,7 +667,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 opScopes = (scopes == null) ? null : scopes.get(authMethod.name); - authMethod.name = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(authMethod.name), true); + authMethod.name = camelize(sanitizeName(authMethod.name), true); if (opScopes != null) { CodegenSecurity opSecurity = new CodegenSecurity(); opSecurity.name = authMethod.name; diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractApexCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractApexCodegen.java index 17febd23680..6d2493a6ee0 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractApexCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractApexCodegen.java @@ -36,6 +36,8 @@ import io.swagger.v3.oas.models.responses.ApiResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.openapitools.codegen.utils.StringUtils.camelize; + public abstract class AbstractApexCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractApexCodegen.class); @@ -112,7 +114,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code // camelize (lower first character) the variable name // pet_id => petId - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); // for reserved word or word starting with number, append _ if (isReservedWord(name) || name.matches("^\\d.*")) { @@ -159,7 +161,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code // camelize the model name // phone_number => PhoneNumber - final String camelizedName = org.openapitools.codegen.utils.StringUtils.camelize(nameWithPrefixSuffix); + final String camelizedName = camelize(nameWithPrefixSuffix); // model name cannot use reserved keyword, e.g. return if (isReservedWord(camelizedName)) { @@ -422,11 +424,11 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code throw new RuntimeException("Empty method/operation name (operationId) not allowed"); } - operationId = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true); + operationId = camelize(sanitizeName(operationId), true); // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - String newOperationId = org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId, true); + String newOperationId = camelize("call_" + operationId, true); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId); return newOperationId; } @@ -515,7 +517,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code @Override public String toEnumName(CodegenProperty property) { - return sanitizeName(org.openapitools.codegen.utils.StringUtils.camelize(property.name)) + "Enum"; + return sanitizeName(camelize(property.name)) + "Enum"; } @Override @@ -669,7 +671,7 @@ public abstract class AbstractApexCodegen extends DefaultCodegen implements Code @Override public String sanitizeTag(String tag) { - return org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(tag)); + return camelize(sanitizeName(tag)); } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java index 02e5213d266..83bd5ad6966 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java @@ -40,6 +40,7 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.util.*; +import static org.openapitools.codegen.utils.StringUtils.camelize; public abstract class AbstractCSharpCodegen extends DefaultCodegen implements CodegenConfig { @@ -635,17 +636,17 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId))); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId))); operationId = "call_" + operationId; } // operationId starts with a number if (operationId.matches("^\\d.*")) { - LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId))); + LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId))); operationId = "call_" + operationId; } - return org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId)); + return camelize(sanitizeName(operationId)); } @Override @@ -660,7 +661,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co // camelize the variable name // pet_id => PetId - name = org.openapitools.codegen.utils.StringUtils.camelize(name); + name = camelize(name); // for reserved word or word starting with number, append _ if (isReservedWord(name) || name.matches("^\\d.*")) { @@ -683,9 +684,9 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co return name; } - // org.openapitools.codegen.utils.StringUtils.camelize(lower) the variable name + // camelize(lower) the variable name // pet_id => petId - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); // for reserved word or word starting with number, append _ if (isReservedWord(name) || name.matches("^\\d.*")) { @@ -870,19 +871,19 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. return => ModelReturn (after camelize) } // model name starts with number if (name.matches("^\\d.*")) { - LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. 200Response => Model200Response (after camelize) } // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override @@ -970,7 +971,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co // for symbol, e.g. $, # if (getSymbolName(name) != null) { - return org.openapitools.codegen.utils.StringUtils.camelize(getSymbolName(name)); + return camelize(getSymbolName(name)); } String enumName = sanitizeName(name); @@ -978,7 +979,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co enumName = enumName.replaceFirst("^_", ""); enumName = enumName.replaceFirst("_$", ""); - enumName = org.openapitools.codegen.utils.StringUtils.camelize(enumName) + "Enum"; + enumName = camelize(enumName) + "Enum"; if (enumName.matches("\\d.*")) { // starts with number return "_" + enumName; @@ -989,7 +990,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co @Override public String toEnumName(CodegenProperty property) { - return sanitizeName(org.openapitools.codegen.utils.StringUtils.camelize(property.name)) + "Enum"; + return sanitizeName(camelize(property.name)) + "Enum"; } public String testPackageName() { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractEiffelCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractEiffelCodegen.java index a9ad50d4b67..7aa13fdd665 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractEiffelCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractEiffelCodegen.java @@ -49,6 +49,8 @@ import java.util.Map; import java.util.Set; import static com.google.common.base.Strings.isNullOrEmpty; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public abstract class AbstractEiffelCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractEiffelCodegen.class); @@ -206,7 +208,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co // (after camelize) } - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); } @Override @@ -217,7 +219,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co // methods parameters as 'final'. // e.g. PetApi.go => pet_api.go - return org.openapitools.codegen.utils.StringUtils.underscore(name) + "_api"; + return underscore(name) + "_api"; } @Override @@ -335,7 +337,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co // method name cannot use reserved keyword, e.g. return if (isReservedWord(sanitizedOperationId)) { LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " - + org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId)); + + camelize("call_" + operationId)); sanitizedOperationId = "call_" + sanitizedOperationId; } // method name from updateSomething to update_Something. @@ -353,7 +355,7 @@ public abstract class AbstractEiffelCodegen extends DefaultCodegen implements Co for (CodegenOperation operation : operations) { // http method verb conversion (e.g. PUT => Put) - operation.httpMethod = org.openapitools.codegen.utils.StringUtils.camelize(operation.httpMethod.toLowerCase(Locale.ROOT)); + operation.httpMethod = camelize(operation.httpMethod.toLowerCase(Locale.ROOT)); } // remove model imports to avoid error diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java index 49aa9fe342d..78fcb088650 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java @@ -30,6 +30,9 @@ import java.io.File; import java.io.IOException; import java.util.*; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; + public abstract class AbstractGoCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGoCodegen.class); @@ -147,7 +150,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege if (this.reservedWordsMappings().containsKey(name)) { return this.reservedWordsMappings().get(name); } - return org.openapitools.codegen.utils.StringUtils.camelize(name) + '_'; + return camelize(name) + '_'; } @Override @@ -162,7 +165,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege // camelize (lower first character) the variable name // pet_id => PetId - name = org.openapitools.codegen.utils.StringUtils.camelize(name); + name = camelize(name); // for reserved word append _ if (isReservedWord(name)) { @@ -187,7 +190,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege // params should be lowerCamelCase. E.g. "person Person", instead of // "Person Person". // - name = org.openapitools.codegen.utils.StringUtils.camelize(toVarName(name), true); + name = camelize(toVarName(name), true); // REVISIT: Actually, for idiomatic go, the param name should // really should just be a letter, e.g. "p Person"), but we'll get @@ -204,7 +207,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege public String toModelName(String name) { // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(toModel(name)); + return camelize(toModel(name)); } @Override @@ -241,7 +244,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege name = "model_" + name; // e.g. 200Response => Model200Response (after camelize) } - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); } @Override @@ -250,7 +253,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. // e.g. PetApi.go => pet_api.go - name = "api_" + org.openapitools.codegen.utils.StringUtils.underscore(name); + name = "api_" + underscore(name); if (name.endsWith("_test")) { LOGGER.warn(name + ".go with `_test.go` suffix (reserved word) cannot be used as filename. Renamed to " + name + "_.go"); name += "_"; @@ -321,17 +324,17 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege // method name cannot use reserved keyword, e.g. return if (isReservedWord(sanitizedOperationId)) { LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " - + org.openapitools.codegen.utils.StringUtils.camelize("call_" + sanitizedOperationId)); + + camelize("call_" + sanitizedOperationId)); sanitizedOperationId = "call_" + sanitizedOperationId; } // operationId starts with a number if (sanitizedOperationId.matches("^\\d.*")) { - LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("call_" + sanitizedOperationId)); + LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize("call_" + sanitizedOperationId)); sanitizedOperationId = "call_" + sanitizedOperationId; } - return org.openapitools.codegen.utils.StringUtils.camelize(sanitizedOperationId); + return camelize(sanitizedOperationId); } @Override @@ -342,7 +345,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege List operations = (List) objectMap.get("operation"); for (CodegenOperation operation : operations) { // http method verb conversion (e.g. PUT => Put) - operation.httpMethod = org.openapitools.codegen.utils.StringUtils.camelize(operation.httpMethod.toLowerCase(Locale.ROOT)); + operation.httpMethod = camelize(operation.httpMethod.toLowerCase(Locale.ROOT)); } // remove model imports to avoid error @@ -573,7 +576,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege } // string - String enumName = sanitizeName(org.openapitools.codegen.utils.StringUtils.underscore(name).toUpperCase(Locale.ROOT)); + String enumName = sanitizeName(underscore(name).toUpperCase(Locale.ROOT)); enumName = enumName.replaceFirst("^_", ""); enumName = enumName.replaceFirst("_$", ""); @@ -588,7 +591,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege @Override public String toEnumName(CodegenProperty property) { - String enumName = org.openapitools.codegen.utils.StringUtils.underscore(toModelName(property.name)).toUpperCase(Locale.ROOT); + String enumName = underscore(toModelName(property.name)).toUpperCase(Locale.ROOT); // remove [] for array or map of enum enumName = enumName.replace("[]", ""); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGraphQLCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGraphQLCodegen.java index fad8c3a3c8f..57e2d71663b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGraphQLCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGraphQLCodegen.java @@ -27,6 +27,9 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.util.*; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; + public abstract class AbstractGraphQLCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGraphQLCodegen.class); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java index b400d31c6b6..146ef634b56 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java @@ -55,7 +55,8 @@ import java.util.Map; import java.util.regex.Pattern; import static org.openapitools.codegen.utils.StringUtils.escape; - +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public abstract class AbstractJavaCodegen extends DefaultCodegen implements CodegenConfig { @@ -584,7 +585,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code if (name.length() == 0) { return "DefaultApi"; } - return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Api"; + return camelize(name) + "Api"; } @Override @@ -624,7 +625,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code // camelize (lower first character) the variable name // pet_id => petId - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); // for reserved word or word starting with number, append _ if (isReservedWord(name) || name.matches("^\\d.*")) { @@ -676,7 +677,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code // camelize the model name // phone_number => PhoneNumber - final String camelizedName = org.openapitools.codegen.utils.StringUtils.camelize(nameWithPrefixSuffix); + final String camelizedName = camelize(nameWithPrefixSuffix); // model name cannot use reserved keyword, e.g. return if (isReservedWord(camelizedName)) { @@ -919,19 +920,19 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code throw new RuntimeException("Empty method/operation name (operationId) not allowed"); } - operationId = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true); + operationId = camelize(sanitizeName(operationId), true); // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - String newOperationId = org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId, true); + String newOperationId = camelize("call_" + operationId, true); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + 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 " + org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId), true); - operationId = org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId, true); + LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), true); + operationId = camelize("call_" + operationId, true); } return operationId; @@ -1082,7 +1083,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code @Override public String toEnumName(CodegenProperty property) { - return sanitizeName(org.openapitools.codegen.utils.StringUtils.camelize(property.name)) + "Enum"; + return sanitizeName(camelize(property.name)) + "Enum"; } @Override @@ -1378,7 +1379,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code @Override public String sanitizeTag(String tag) { - tag = org.openapitools.codegen.utils.StringUtils.camelize(org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName(tag))); + tag = camelize(underscore(sanitizeName(tag))); // tag starts with numbers if (tag.matches("^\\d.*")) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaJAXRSServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaJAXRSServerCodegen.java index b57ca9e244e..1e01b5a9de8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaJAXRSServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaJAXRSServerCodegen.java @@ -40,6 +40,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.openapitools.codegen.utils.StringUtils.camelize; public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen implements BeanValidationFeatures { public static final String SERVER_PORT = "serverPort"; @@ -251,7 +252,7 @@ public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen return "DefaultApi"; } computed = sanitizeName(computed); - return org.openapitools.codegen.utils.StringUtils.camelize(computed) + "Api"; + return camelize(computed) + "Api"; } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java index 7de4d874d29..8b64f3c1b43 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java @@ -32,6 +32,9 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.util.*; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.escape; +import static org.openapitools.codegen.utils.StringUtils.underscore; public abstract class AbstractKotlinCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractKotlinCodegen.class); @@ -431,16 +434,16 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co break; case camelCase: // NOTE: Removes hyphens and underscores - modified = org.openapitools.codegen.utils.StringUtils.camelize(modified, true); + modified = camelize(modified, true); break; case PascalCase: // NOTE: Removes hyphens and underscores - String result = org.openapitools.codegen.utils.StringUtils.camelize(modified); + String result = camelize(modified); modified = titleCase(result); break; case snake_case: // NOTE: Removes hyphens - modified = org.openapitools.codegen.utils.StringUtils.underscore(modified); + modified = underscore(modified); break; case UPPERCASE: modified = modified.toUpperCase(Locale.ROOT); @@ -502,7 +505,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co modifiedName = sanitizeKotlinSpecificNames(modifiedName); // Camelize name of nested properties - modifiedName = org.openapitools.codegen.utils.StringUtils.camelize(modifiedName); + modifiedName = camelize(modifiedName); // model name cannot use reserved keyword, e.g. return if (isReservedWord(modifiedName)) { @@ -687,7 +690,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co List allowedCharacters = new ArrayList<>(); allowedCharacters.add("_"); allowedCharacters.add("$"); - name = escapeSpecialCharacters(name, allowedCharacters, "_"); + name = escape(name, specialCharReplacements, allowedCharacters, "_"); } // camelize (lower first character) the variable name diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java index 967fd8357ae..150b56ebd92 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java @@ -41,6 +41,13 @@ import java.util.Locale; import java.util.Map; import java.util.regex.Matcher; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; + public abstract class AbstractPhpCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractPhpCodegen.class); @@ -425,11 +432,11 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg if ("camelCase".equals(variableNamingConvention)) { // return the name in camelCase style // phone_number => phoneNumber - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); } else { // default to snake case // return the name in underscore style // PhoneNumber => phone_number - name = org.openapitools.codegen.utils.StringUtils.underscore(name); + name = underscore(name); } // parameter name starting with number won't compile @@ -460,13 +467,13 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg // model name cannot use reserved keyword if (isReservedWord(name)) { - LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. return => ModelReturn (after camelize) } // model name starts with number if (name.matches("^\\d.*")) { - LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. 200Response => Model200Response (after camelize) } @@ -483,7 +490,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override @@ -505,7 +512,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg * @return capitalized model name */ public String toInterfaceName(final String name) { - return org.openapitools.codegen.utils.StringUtils.camelize(interfaceNamePrefix + name + interfaceNameSuffix); + return camelize(interfaceNamePrefix + name + interfaceNameSuffix); } /** @@ -515,7 +522,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg * @return capitalized abstract class name */ public String toAbstractName(final String name) { - return org.openapitools.codegen.utils.StringUtils.camelize(abstractNamePrefix + name + abstractNameSuffix); + return camelize(abstractNamePrefix + name + abstractNameSuffix); } /** @@ -525,7 +532,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg * @return capitalized trait name */ public String toTraitName(final String name) { - return org.openapitools.codegen.utils.StringUtils.camelize(traitNamePrefix + name + traitNameSuffix); + return camelize(traitNamePrefix + name + traitNameSuffix); } @Override @@ -537,17 +544,17 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId), true)); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true)); operationId = "call_" + operationId; } // operationId starts with a number if (operationId.matches("^\\d.*")) { - LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId), true)); + LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true)); operationId = "call_" + operationId; } - return org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true); + return camelize(sanitizeName(operationId), true); } /** @@ -685,7 +692,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg } // string - String enumName = sanitizeName(org.openapitools.codegen.utils.StringUtils.underscore(name).toUpperCase(Locale.ROOT)); + String enumName = sanitizeName(underscore(name).toUpperCase(Locale.ROOT)); enumName = enumName.replaceFirst("^_", ""); enumName = enumName.replaceFirst("_$", ""); @@ -698,7 +705,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg @Override public String toEnumName(CodegenProperty property) { - String enumName = org.openapitools.codegen.utils.StringUtils.underscore(toModelName(property.name)).toUpperCase(Locale.ROOT); + String enumName = underscore(toModelName(property.name)).toUpperCase(Locale.ROOT); // remove [] for array or map of enum enumName = enumName.replace("[]", ""); @@ -723,7 +730,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg for (CodegenOperation op : operationList) { // for API test method name // e.g. public function test{{vendorExtensions.x-testOperationId}}() - op.vendorExtensions.put("x-testOperationId", org.openapitools.codegen.utils.StringUtils.camelize(op.operationId)); + op.vendorExtensions.put("x-testOperationId", camelize(op.operationId)); } return objs; } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRubyCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRubyCodegen.java index 7b32b989bd7..7c5c4bf601d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRubyCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRubyCodegen.java @@ -31,6 +31,7 @@ import java.io.File; import java.util.Arrays; import java.util.Locale; +import static org.openapitools.codegen.utils.StringUtils.underscore; abstract class AbstractRubyCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractRubyCodegen.class); @@ -136,7 +137,7 @@ abstract class AbstractRubyCodegen extends DefaultCodegen implements CodegenConf // camelize (lower first character) the variable name // petId => pet_id - name = org.openapitools.codegen.utils.StringUtils.underscore(name); + name = underscore(name); // for reserved word or word starting with number, append _ if (isReservedWord(name) || name.matches("^\\d.*")) { @@ -160,12 +161,12 @@ abstract class AbstractRubyCodegen extends DefaultCodegen implements CodegenConf public String toOperationId(String operationId) { // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - String newOperationId = org.openapitools.codegen.utils.StringUtils.underscore("call_" + operationId); + String newOperationId = underscore("call_" + operationId); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId); return newOperationId; } - return org.openapitools.codegen.utils.StringUtils.underscore(operationId); + return underscore(operationId); } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractScalaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractScalaCodegen.java index ebfd0330ff1..1e5f9e1867b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractScalaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractScalaCodegen.java @@ -36,6 +36,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import static org.openapitools.codegen.utils.StringUtils.camelize; public abstract class AbstractScalaCodegen extends DefaultCodegen { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractScalaCodegen.class); @@ -280,7 +281,7 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen { } protected String formatIdentifier(String name, boolean capitalized) { - String identifier = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(name), true); + String identifier = camelize(sanitizeName(name), true); if (capitalized) { identifier = StringUtils.capitalize(identifier); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java index 3023e83afcf..6e178de0cc9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java @@ -32,6 +32,8 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(AbstractTypeScriptClientCodegen.class); @@ -221,27 +223,27 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - String modelName = org.openapitools.codegen.utils.StringUtils.camelize("model_" + name); + String modelName = camelize("model_" + name); LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName); return modelName; } // model name starts with number if (name.matches("^\\d.*")) { - String modelName = org.openapitools.codegen.utils.StringUtils.camelize("model_" + name); // e.g. 200Response => Model200Response (after camelize) + String modelName = camelize("model_" + name); // e.g. 200Response => Model200Response (after camelize) LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + modelName); return modelName; } if (languageSpecificPrimitives.contains(name)) { - String modelName = org.openapitools.codegen.utils.StringUtils.camelize("model_" + name); + String modelName = camelize("model_" + name); LOGGER.warn(name + " (model name matches existing language type) cannot be used as a model name. Renamed to " + modelName); return modelName; } // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override @@ -405,10 +407,10 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp // method name cannot use reserved keyword, e.g. return // append _ at the beginning, e.g. _return if (isReservedWord(operationId)) { - return escapeReservedWord(org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true)); + return escapeReservedWord(camelize(sanitizeName(operationId), true)); } - return org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true); + return camelize(sanitizeName(operationId), true); } public void setModelPropertyNaming(String naming) { @@ -431,11 +433,11 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp case original: return name; case camelCase: - return org.openapitools.codegen.utils.StringUtils.camelize(name, true); + return camelize(name, true); case PascalCase: - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); case snake_case: - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); default: throw new IllegalArgumentException("Invalid model property naming '" + name + "'. Must be 'original', 'camelCase', " + @@ -466,7 +468,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp // for symbol, e.g. $, # if (getSymbolName(name) != null) { - return org.openapitools.codegen.utils.StringUtils.camelize(getSymbolName(name)); + return camelize(getSymbolName(name)); } // number @@ -486,7 +488,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp // camelize the enum variable name // ref: https://basarat.gitbooks.io/typescript/content/docs/enums.html - enumName = org.openapitools.codegen.utils.StringUtils.camelize(enumName); + enumName = camelize(enumName); if (enumName.matches("\\d.*")) { // starts with number return "_" + enumName; diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AndroidClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AndroidClientCodegen.java index 6c2a10ce57c..73e359075d7 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AndroidClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AndroidClientCodegen.java @@ -36,6 +36,7 @@ import java.io.File; import java.util.Arrays; import java.util.HashSet; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(AndroidClientCodegen.class); @@ -229,7 +230,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi // camelize (lower first character) the variable name // pet_id => petId - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); // for reserved word or word starting with number, append _ if (isReservedWord(name) || name.matches("^\\d.*")) { @@ -258,7 +259,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi // camelize the model name // phone_number => PhoneNumber - name = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(name)); + name = camelize(sanitizeName(name)); // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { @@ -355,11 +356,11 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi throw new RuntimeException("Empty method name (operationId) not allowed"); } - operationId = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true); + operationId = camelize(sanitizeName(operationId), true); // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - String newOperationId = org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId, true); + String newOperationId = camelize("call_" + operationId, true); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId); return newOperationId; } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ApexClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ApexClientCodegen.java index cb52abd1cad..d37dee2b193 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ApexClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ApexClientCodegen.java @@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.util.*; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class ApexClientCodegen extends AbstractApexCodegen { @@ -193,7 +194,7 @@ public class ApexClientCodegen extends AbstractApexCodegen { @Override public String toApiName(String name) { - return org.openapitools.codegen.utils.StringUtils.camelize(classPrefix + super.toApiName(name)); + return camelize(classPrefix + super.toApiName(name)); } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java index 4dac2b13a44..9a41db790e8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java @@ -16,7 +16,6 @@ package org.openapitools.codegen.languages; -import io.swagger.v3.oas.models.media.ArraySchema; import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; @@ -26,7 +25,6 @@ import org.openapitools.codegen.utils.ModelUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.io.FilenameUtils; import java.io.File; @@ -37,6 +35,9 @@ import java.util.Locale; import java.util.Map; import java.util.Set; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; + public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(CLibcurlClientCodegen.class); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java index f17c354de74..d672320d1d9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java @@ -42,6 +42,8 @@ import java.util.Locale; import java.util.Map; import static org.apache.commons.lang3.StringUtils.isEmpty; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class CSharpClientCodegen extends AbstractCSharpCodegen { @SuppressWarnings({"hiding"}) @@ -704,7 +706,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen { // for symbol, e.g. $, # if (getSymbolName(value) != null) { - return org.openapitools.codegen.utils.StringUtils.camelize(getSymbolName(value)); + return camelize(getSymbolName(value)); } // number @@ -720,7 +722,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen { // string String var = value.replaceAll("_", " "); //var = WordUtils.capitalizeFully(var); - var = org.openapitools.codegen.utils.StringUtils.camelize(var); + var = camelize(var); var = var.replaceAll("\\W+", ""); if (var.matches("\\d.*")) { @@ -755,11 +757,11 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen { case original: return name; case camelCase: - return org.openapitools.codegen.utils.StringUtils.camelize(name, true); + return camelize(name, true); case PascalCase: - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); case snake_case: - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); default: throw new IllegalArgumentException("Invalid model property naming '" + name + "'. Must be 'original', 'camelCase', " + diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNancyFXServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNancyFXServerCodegen.java index ed8b197c1b8..9c2499cb733 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNancyFXServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNancyFXServerCodegen.java @@ -36,7 +36,6 @@ import org.openapitools.codegen.utils.URLPathUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import java.io.File; import java.net.URL; import java.util.ArrayList; @@ -72,6 +71,7 @@ import static org.openapitools.codegen.CodegenConstants.USE_COLLECTION_DESC; import static org.openapitools.codegen.CodegenConstants.USE_DATETIME_OFFSET; import static org.openapitools.codegen.CodegenConstants.USE_DATETIME_OFFSET_DESC; import static org.openapitools.codegen.CodegenType.SERVER; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen { private static final Logger LOGGER = LoggerFactory.getLogger(CSharpNancyFXServerCodegen.class); @@ -335,7 +335,7 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen { return "Empty"; } - final String enumName = org.openapitools.codegen.utils.StringUtils.camelize( + final String enumName = camelize( sanitizeName(name) .replaceFirst("^_", "") .replaceFirst("_$", "") @@ -402,7 +402,7 @@ public class CSharpNancyFXServerCodegen extends AbstractCSharpCodegen { @Override public String toEnumName(final CodegenProperty property) { - return sanitizeName(org.openapitools.codegen.utils.StringUtils.camelize(property.name)) + "Enum"; + return sanitizeName(camelize(property.name)) + "Enum"; } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpRefactorClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpRefactorClientCodegen.java index 71d6bb7bf43..27489eddee0 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpRefactorClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpRefactorClientCodegen.java @@ -43,6 +43,9 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; + public class CSharpRefactorClientCodegen extends AbstractCSharpCodegen { @SuppressWarnings({"hiding"}) private static final Logger LOGGER = LoggerFactory.getLogger(CSharpClientCodegen.class); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ClojureClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ClojureClientCodegen.java index f9c360845dd..bfb074d33fc 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ClojureClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ClojureClientCodegen.java @@ -28,6 +28,8 @@ import org.openapitools.codegen.utils.ModelUtils; import java.io.File; import java.util.*; +import static org.openapitools.codegen.utils.StringUtils.dashize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfig { private static final String PROJECT_NAME = "projectName"; @@ -215,7 +217,7 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi Info info = openAPI.getInfo(); if (projectName == null && info.getTitle() != null) { // when projectName is not specified, generate it from info.title - projectName = org.openapitools.codegen.utils.StringUtils.dashize(info.getTitle()); + projectName = dashize(info.getTitle()); } if (projectVersion == null) { // when projectVersion is not specified, use info.version @@ -254,7 +256,7 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi projectDescription = "Client library of " + projectName; } if (baseNamespace == null) { - baseNamespace = org.openapitools.codegen.utils.StringUtils.dashize(projectName); + baseNamespace = dashize(projectName); } apiPackage = baseNamespace + ".api"; modelPackage = baseNamespace + ".specs"; @@ -295,12 +297,12 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi throw new RuntimeException("Empty method/operation name (operationId) not allowed"); } - return org.openapitools.codegen.utils.StringUtils.dashize(sanitizeName(operationId)); + return dashize(sanitizeName(operationId)); } @Override public String toApiFilename(String name) { - return org.openapitools.codegen.utils.StringUtils.underscore(toApiName(name)); + return underscore(toApiName(name)); } @Override @@ -310,7 +312,7 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi @Override public String toApiName(String name) { - return org.openapitools.codegen.utils.StringUtils.dashize(name); + return dashize(name); } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java index 272e6966a00..8f6648978df 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java @@ -41,6 +41,7 @@ import java.util.Locale; import java.util.Map; import java.util.Set; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class CppPistacheServerCodegen extends AbstractCppCodegen { protected String implFolder = "impl"; @@ -214,8 +215,8 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen { public Map postProcessOperationsWithModels(Map objs, List allModels) { Map operations = (Map) objs.get("operations"); String classname = (String) operations.get("classname"); - operations.put("classnameSnakeUpperCase", org.openapitools.codegen.utils.StringUtils.underscore(classname).toUpperCase(Locale.ROOT)); - operations.put("classnameSnakeLowerCase", org.openapitools.codegen.utils.StringUtils.underscore(classname).toLowerCase(Locale.ROOT)); + operations.put("classnameSnakeUpperCase", underscore(classname).toUpperCase(Locale.ROOT)); + operations.put("classnameSnakeLowerCase", underscore(classname).toLowerCase(Locale.ROOT)); List operationList = (List) operations.get("operation"); for (CodegenOperation op : operationList) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java index 0f663d05831..fbe2a19a9b6 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java @@ -23,6 +23,14 @@ import org.openapitools.codegen.CodegenType; import org.openapitools.codegen.SupportingFile; import java.io.File; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import static org.openapitools.codegen.utils.StringUtils.underscore; public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements CodegenConfig { public static final String OPTIONAL_PROJECT_FILE_DESC = "Generate client.pri."; diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5QHttpEngineServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5QHttpEngineServerCodegen.java index a20a5af3574..d83fb0603b8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5QHttpEngineServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5QHttpEngineServerCodegen.java @@ -22,6 +22,16 @@ import org.openapitools.codegen.CodegenType; import org.openapitools.codegen.SupportingFile; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import static org.openapitools.codegen.utils.StringUtils.underscore; public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implements CodegenConfig { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppTizenClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppTizenClientCodegen.java index 7033661bdd4..f9575c81724 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppTizenClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppTizenClientCodegen.java @@ -32,6 +32,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class CppTizenClientCodegen extends AbstractCppCodegen implements CodegenConfig { protected static String PREFIX = "ArtikCloud"; @@ -284,7 +285,7 @@ public class CppTizenClientCodegen extends AbstractCppCodegen implements Codegen } // add_pet_by_id => addPetById - return org.openapitools.codegen.utils.StringUtils.camelize(operationId, true); + return camelize(operationId, true); } /** * Output the Getter name for boolean property, e.g. getActive diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java index 2c09ce148ef..4ef3879a000 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java @@ -42,6 +42,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; + public class DartClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(DartClientCodegen.class); @@ -263,7 +266,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig { // camelize (lower first character) the variable name // pet_id => petId - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); if (name.matches("^\\d.*")) { name = "n" + name; @@ -286,23 +289,23 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig { public String toModelName(String name) { // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. return => ModelReturn (after camelize) } // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override public String toModelFilename(String name) { - return org.openapitools.codegen.utils.StringUtils.underscore(toModelName(name)); + return underscore(toModelName(name)); } @Override public String toApiFilename(String name) { - return org.openapitools.codegen.utils.StringUtils.underscore(toApiName(name)); + return underscore(toApiName(name)); } @Override @@ -424,7 +427,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig { new ArrayList>(); for (Map value : values) { Map enumVar = new HashMap(); - String name = org.openapitools.codegen.utils.StringUtils.camelize((String) value.get("identifier"), true); + String name = camelize((String) value.get("identifier"), true); if (isReservedWord(name)) { name = escapeReservedWord(name); } @@ -450,7 +453,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig { "int".equalsIgnoreCase(datatype)) { var = "Number" + var; } - return escapeReservedWord(org.openapitools.codegen.utils.StringUtils.camelize(var, true)); + return escapeReservedWord(camelize(var, true)); } @Override @@ -467,12 +470,12 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig { public String toOperationId(String operationId) { // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - String newOperationId = org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId, true); + String newOperationId = camelize("call_" + operationId, true); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId); return newOperationId; } - return org.openapitools.codegen.utils.StringUtils.camelize(operationId, true); + return camelize(operationId, true); } public void setBrowserClient(boolean browserClient) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java index 9ca833b5f31..0a2d3444771 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartJaguarClientCodegen.java @@ -33,6 +33,8 @@ import java.util.Locale; import java.util.Map; import java.util.Set; +import static org.openapitools.codegen.utils.StringUtils.underscore; + public class DartJaguarClientCodegen extends DartClientCodegen { private static Set modelToIgnore = new HashSet<>(); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java index 51d5f672899..ef851128824 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java @@ -37,6 +37,8 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.openapitools.codegen.utils.StringUtils.underscore; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(ElixirClientCodegen.class); @@ -276,7 +278,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig StringBuffer buffer = new StringBuffer(); while (matcher.find()) { String pathTemplateName = matcher.group(1); - matcher.appendReplacement(buffer, "#{" + org.openapitools.codegen.utils.StringUtils.underscore(pathTemplateName) + "}" + "$2"); + matcher.appendReplacement(buffer, "#{" + underscore(pathTemplateName) + "}" + "$2"); pathTemplateNames.add(pathTemplateName); } ExtendedCodegenOperation eco = new ExtendedCodegenOperation(o); @@ -324,7 +326,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig String underscored(String words) { ArrayList underscoredWords = new ArrayList(); for (String word : words.split(" ")) { - underscoredWords.add(org.openapitools.codegen.utils.StringUtils.underscore(word)); + underscoredWords.add(underscore(word)); } return join("_", underscoredWords); } @@ -332,7 +334,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig String modulized(String words) { ArrayList modulizedWords = new ArrayList(); for (String word : words.split(" ")) { - modulizedWords.add(org.openapitools.codegen.utils.StringUtils.camelize(word)); + modulizedWords.add(camelize(word)); } return join("", modulizedWords); } @@ -351,7 +353,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig private String sourceFolder() { ArrayList underscoredWords = new ArrayList(); for (String word : moduleName.split("\\.")) { - underscoredWords.add(org.openapitools.codegen.utils.StringUtils.underscore(word)); + underscoredWords.add(underscore(word)); } return ("lib/" + join("/", underscoredWords)).replace('/', File.separatorChar); } @@ -378,7 +380,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig if (name.length() == 0) { return "Default"; } - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override @@ -387,14 +389,14 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig name = name.replaceAll("-", "_"); // e.g. PetApi.go => pet_api.go - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); } @Override public String toModelName(String name) { // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(toModelFilename(name)); + return camelize(toModelFilename(name)); } @Override @@ -421,7 +423,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig name = "model_" + name; // e.g. 200Response => Model200Response (after camelize) } - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); } @Override @@ -433,17 +435,17 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId))); - return org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId)); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId))); + return underscore(sanitizeName("call_" + operationId)); } // operationId starts with a number if (operationId.matches("^\\d.*")) { - LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId))); + LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId))); operationId = "call_" + operationId; } - return org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName(operationId)); + return underscore(sanitizeName(operationId)); } /** @@ -596,7 +598,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig public String typespec() { StringBuilder sb = new StringBuilder("@spec "); - sb.append(org.openapitools.codegen.utils.StringUtils.underscore(operationId)); + sb.append(underscore(operationId)); sb.append("(Tesla.Env.client, "); for (CodegenParameter param : allParams) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java index 21a4589c3d2..68743d091ed 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java @@ -19,7 +19,6 @@ package org.openapitools.codegen.languages; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.media.ArraySchema; -import io.swagger.v3.oas.models.media.NumberSchema; import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.responses.ApiResponse; import org.openapitools.codegen.CliOption; @@ -55,6 +54,8 @@ import java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; +import static org.openapitools.codegen.utils.StringUtils.camelize; + public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(ElmClientCodegen.class); private Set customPrimitives = new HashSet(); @@ -252,7 +253,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String toModelName(String name) { - final String modelName = org.openapitools.codegen.utils.StringUtils.camelize(name); + final String modelName = camelize(name); return defaultIncludes.contains(modelName) ? modelName + "_" : modelName; } @@ -268,13 +269,13 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String toVarName(String name) { - final String varName = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + final String varName = camelize(name, true); return isReservedWord(varName) ? escapeReservedWord(name) : varName; } @Override public String toEnumVarName(String value, String datatype) { - String camelized = org.openapitools.codegen.utils.StringUtils.camelize(value.replace(" ", "_").replace("(", "_").replace(")", "")); // TODO FIXME escape properly + String camelized = camelize(value.replace(" ", "_").replace("(", "_").replace(")", "")); // TODO FIXME escape properly if (camelized.length() == 0) { LOGGER.error("Unable to determine enum variable name (name: {}, datatype: {}) from empty string. Default to UnknownEnumVariableName", value, datatype); @@ -584,7 +585,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { if (mapFn == null) { throw new RuntimeException("Parameter '" + param.paramName + "' cannot be converted to a string. Please report the issue."); } - + if (param.isListContainer) { if (!param.required) { mapFn = "(" + mapFn + ")"; diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangClientCodegen.java index d202e755268..9787862a7a6 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangClientCodegen.java @@ -33,7 +33,8 @@ import java.util.regex.Pattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(ErlangClientCodegen.class); @@ -204,7 +205,7 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig if (this.reservedWordsMappings().containsKey(name)) { return this.reservedWordsMappings().get(name); } - return org.openapitools.codegen.utils.StringUtils.camelize(name) + '_'; + return camelize(name) + '_'; } @Override @@ -230,7 +231,7 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig @Override public String toParamName(String name) { - return org.openapitools.codegen.utils.StringUtils.camelize(toVarName(name)); + return camelize(toVarName(name)); } @Override @@ -249,17 +250,17 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig @Override public String toModelName(String name) { - return this.packageName + "_" + org.openapitools.codegen.utils.StringUtils.underscore(name.replaceAll("-", "_").replaceAll("\\.", "_")); + return this.packageName + "_" + underscore(name.replaceAll("-", "_").replaceAll("\\.", "_")); } @Override public String toApiName(String name) { - return this.packageName + "_" + org.openapitools.codegen.utils.StringUtils.underscore(name.replaceAll("-", "_").replaceAll("\\.", "_")); + return this.packageName + "_" + underscore(name.replaceAll("-", "_").replaceAll("\\.", "_")); } @Override public String toModelFilename(String name) { - return this.packageName + "_" + org.openapitools.codegen.utils.StringUtils.underscore(name.replaceAll("\\.", "_")); + return this.packageName + "_" + underscore(name.replaceAll("\\.", "_")); } @Override @@ -269,18 +270,18 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig name = name.replaceAll("-", "_").replaceAll("\\.", "_"); // e.g. PetApi.erl => pet_api.erl - return this.packageName + "_" + org.openapitools.codegen.utils.StringUtils.underscore(name) + "_api"; + return this.packageName + "_" + underscore(name) + "_api"; } @Override public String toOperationId(String operationId) { // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId)).replaceAll("\\.", "_")); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)).replaceAll("\\.", "_")); operationId = "call_" + operationId; } - return org.openapitools.codegen.utils.StringUtils.underscore(operationId.replaceAll("\\.", "_")); + return underscore(operationId.replaceAll("\\.", "_")); } @Override @@ -302,7 +303,7 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig StringBuffer buffer = new StringBuffer(); while (matcher.find()) { String pathTemplateName = matcher.group(1); - matcher.appendReplacement(buffer, "\", " + org.openapitools.codegen.utils.StringUtils.camelize(pathTemplateName) + ", \""); + matcher.appendReplacement(buffer, "\", " + camelize(pathTemplateName) + ", \""); pathTemplateNames.add(pathTemplateName); } matcher.appendTail(buffer); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangProperCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangProperCodegen.java index f580ea60952..66975476ee9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangProperCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangProperCodegen.java @@ -33,6 +33,9 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; + public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(ErlangProperCodegen.class); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangServerCodegen.java index 1fc21142708..69c6b08b8ac 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangServerCodegen.java @@ -32,6 +32,8 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig { @@ -200,7 +202,7 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig if (name.length() == 0) { return this.packageName + "_default_handler"; } - return this.packageName + "_" + org.openapitools.codegen.utils.StringUtils.underscore(name) + "_handler"; + return this.packageName + "_" + underscore(name) + "_handler"; } /** @@ -228,18 +230,18 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig @Override public String toModelName(String name) { - return org.openapitools.codegen.utils.StringUtils.camelize(toModelFilename(name)); + return camelize(toModelFilename(name)); } @Override public String toOperationId(String operationId) { // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId))); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId))); operationId = "call_" + operationId; } - return org.openapitools.codegen.utils.StringUtils.camelize(operationId); + return camelize(operationId); } @Override @@ -278,7 +280,7 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig } protected String toModuleName(String name) { - return this.packageName + "_" + org.openapitools.codegen.utils.StringUtils.underscore(name.replaceAll("-", "_")); + return this.packageName + "_" + underscore(name.replaceAll("-", "_")); } protected String toSourceFilePath(String name, String extension) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/FlashClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/FlashClientCodegen.java index 2925a1f893f..a91571f77cf 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/FlashClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/FlashClientCodegen.java @@ -29,6 +29,8 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Locale; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(FlashClientCodegen.class); @@ -265,7 +267,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig // underscore the variable name // petId => pet_id - name = org.openapitools.codegen.utils.StringUtils.camelize(dropDots(name), true); + name = camelize(dropDots(name), true); // for reserved word or word starting with number, append _ if (isReservedWord(name) || name.matches("^\\d.*")) { @@ -295,13 +297,13 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. return => ModelReturn (after camelize) } // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override @@ -316,7 +318,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. // e.g. PhoneNumberApi.rb => phone_number_api.rb - return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Api"; + return camelize(name) + "Api"; } @Override @@ -325,7 +327,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig return "DefaultApi"; } // e.g. phone_number_api => PhoneNumberApi - return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Api"; + return camelize(name) + "Api"; } @Override @@ -333,7 +335,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig if (name.length() == 0) { return "DefaultApi"; } - return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Api"; + return camelize(name) + "Api"; } @Override @@ -345,11 +347,11 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId))); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId))); operationId = "call_" + operationId; } - return org.openapitools.codegen.utils.StringUtils.underscore(operationId); + return underscore(operationId); } public void setPackageName(String packageName) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GroovyClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GroovyClientCodegen.java index 94c89e0843f..6818ae26682 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GroovyClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GroovyClientCodegen.java @@ -20,6 +20,7 @@ package org.openapitools.codegen.languages; import org.openapitools.codegen.*; import java.io.File; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class GroovyClientCodegen extends AbstractJavaCodegen { @@ -99,7 +100,7 @@ public class GroovyClientCodegen extends AbstractJavaCodegen { return "DefaultApi"; } name = sanitizeName(name); - return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Api"; + return camelize(name) + "Api"; } public void setConfigPackage(String configPackage) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellHttpClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellHttpClientCodegen.java index ed410e8ddf5..89dd7bf7cab 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellHttpClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellHttpClientCodegen.java @@ -36,6 +36,8 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(HaskellHttpClientCodegen.class); @@ -622,8 +624,8 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC } op.operationId = uniqueName; op.operationIdLowerCase = uniqueName.toLowerCase(Locale.ROOT); - op.operationIdCamelCase = org.openapitools.codegen.utils.StringUtils.camelize(uniqueName); - op.operationIdSnakeCase = org.openapitools.codegen.utils.StringUtils.underscore(uniqueName); + op.operationIdCamelCase = camelize(uniqueName); + op.operationIdSnakeCase = underscore(uniqueName); opList.add(op); op.baseName = tag; @@ -1083,8 +1085,8 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC public String toVarName(String prefix, String name) { Boolean hasPrefix = !StringUtils.isBlank(prefix); - name = org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName(name.replaceAll("-", "_"))); - name = org.openapitools.codegen.utils.StringUtils.camelize(name, !hasPrefix); + name = underscore(sanitizeName(name.replaceAll("-", "_"))); + name = camelize(name, !hasPrefix); if (hasPrefix) { return prefix + name; } else { @@ -1129,7 +1131,7 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC } public String toTypeName(String prefix, String name) { - name = escapeIdentifier(prefix, org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(name))); + name = escapeIdentifier(prefix, camelize(sanitizeName(name))); return name; } @@ -1138,7 +1140,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", org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true)); + operationId = escapeIdentifier("op", camelize(sanitizeName(operationId), true)); return operationId; } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellServantCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellServantCodegen.java index 44bbe3aebdc..7d1a2b89c72 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellServantCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/HaskellServantCodegen.java @@ -47,6 +47,7 @@ import java.util.Locale; import java.util.Map; import java.util.regex.Pattern; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class HaskellServantCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(HaskellServantCodegen.class); @@ -502,7 +503,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf } } else if (op.getHasFormParams()) { // Use the FormX data type, where X is the conglomerate of all things being passed - String formName = "Form" + org.openapitools.codegen.utils.StringUtils.camelize(op.operationId); + String formName = "Form" + camelize(op.operationId); bodyType = formName; path.add("ReqBody '[FormUrlEncoded] " + formName); } @@ -527,7 +528,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf // store form parameter name in the vendor extensions for (CodegenParameter param : op.formParams) { - param.vendorExtensions.put("x-formParamName", org.openapitools.codegen.utils.StringUtils.camelize(param.baseName)); + param.vendorExtensions.put("x-formParamName", camelize(param.baseName)); } // Add the HTTP method and return type @@ -543,9 +544,9 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf op.vendorExtensions.put("x-routeType", joinStrings(" :> ", path)); op.vendorExtensions.put("x-clientType", joinStrings(" -> ", type)); - op.vendorExtensions.put("x-formName", "Form" + org.openapitools.codegen.utils.StringUtils.camelize(op.operationId)); + op.vendorExtensions.put("x-formName", "Form" + camelize(op.operationId)); for (CodegenParameter param : op.formParams) { - param.vendorExtensions.put("x-formPrefix", org.openapitools.codegen.utils.StringUtils.camelize(op.operationId, true)); + param.vendorExtensions.put("x-formPrefix", camelize(op.operationId, true)); } return op; } @@ -610,9 +611,9 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf } // From the model name, compute the prefix for the fields. - String prefix = org.openapitools.codegen.utils.StringUtils.camelize(model.classname, true); + String prefix = camelize(model.classname, true); for (CodegenProperty prop : model.vars) { - prop.name = toVarName(prefix + org.openapitools.codegen.utils.StringUtils.camelize(fixOperatorChars(prop.name))); + prop.name = toVarName(prefix + camelize(fixOperatorChars(prop.name))); } // Create newtypes for things with non-object types diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index 39969fdfbfb..842e0d4514b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -46,6 +46,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.StringUtils.camelize; public class JavaClientCodegen extends AbstractJavaCodegen implements BeanValidationFeatures, PerformBeanValidationFeatures, @@ -466,7 +467,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] = "{" + org.openapitools.codegen.utils.StringUtils.camelize(items[i].substring(1, items[i].length() - 1), true) + "}"; + items[i] = "{" + camelize(items[i].substring(1, items[i].length() - 1), true) + "}"; } } op.path = StringUtils.join(items, "/"); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaInflectorServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaInflectorServerCodegen.java index 30b04743158..c4a29af8a8b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaInflectorServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaInflectorServerCodegen.java @@ -33,6 +33,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class JavaInflectorServerCodegen extends AbstractJavaCodegen { @@ -227,6 +228,6 @@ public class JavaInflectorServerCodegen extends AbstractJavaCodegen { return "DefaultController"; } name = name.replaceAll("[^a-zA-Z0-9]+", "_"); - return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Controller"; + return camelize(name) + "Controller"; } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java index e3459031019..ac13ef54b3a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java @@ -33,6 +33,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen { @@ -222,6 +223,6 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen { return primaryResourceName + "Api"; } computed = sanitizeName(computed); - return org.openapitools.codegen.utils.StringUtils.camelize(computed) + "Api"; + return camelize(computed) + "Api"; } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaPKMSTServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaPKMSTServerCodegen.java index aa638d5d25e..a4cd75c0d44 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaPKMSTServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaPKMSTServerCodegen.java @@ -41,6 +41,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import static org.openapitools.codegen.utils.StringUtils.camelize; /** * Created by prokarma on 04/09/17. @@ -546,7 +547,7 @@ public class JavaPKMSTServerCodegen extends AbstractJavaCodegen { title = title.substring(0, title.length() - 3); } - this.title = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(title), true); + this.title = camelize(sanitizeName(title), true); } additionalProperties.put(TITLE, this.title); } @@ -595,7 +596,7 @@ public class JavaPKMSTServerCodegen extends AbstractJavaCodegen { return "DefaultApi"; } name = sanitizeName(name); - return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Api"; + return camelize(name) + "Api"; } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaPlayFrameworkCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaPlayFrameworkCodegen.java index 4fb3905280c..4b087bb794d 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaPlayFrameworkCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaPlayFrameworkCodegen.java @@ -35,6 +35,7 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements BeanValidationFeatures { @@ -302,7 +303,7 @@ public class JavaPlayFrameworkCodegen extends AbstractJavaCodegen implements Bea Matcher match = pathVariableMatcher.matcher(operation.path); while (match.find()) { String completeMatch = match.group(); - String replacement = ":" + org.openapitools.codegen.utils.StringUtils.camelize(match.group(1), true); + String replacement = ":" + camelize(match.group(1), true); operation.path = operation.path.replace(completeMatch, replacement); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaUndertowServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaUndertowServerCodegen.java index 5c602bf2ca2..cc5f019d70f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaUndertowServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaUndertowServerCodegen.java @@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class JavaUndertowServerCodegen extends AbstractJavaCodegen { @@ -202,6 +203,6 @@ public class JavaUndertowServerCodegen extends AbstractJavaCodegen { return "DefaultHandler"; } name = name.replaceAll("[^a-zA-Z0-9]+", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. - return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Handler"; + return camelize(name) + "Handler"; } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClientCodegen.java index e83f651ac03..c8151053f6a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClientCodegen.java @@ -48,6 +48,10 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.dashize; +import static org.openapitools.codegen.utils.StringUtils.underscore; + public class JavascriptClientCodegen extends DefaultCodegen implements CodegenConfig { @SuppressWarnings("hiding") private static final Logger LOGGER = LoggerFactory.getLogger(JavascriptClientCodegen.class); @@ -289,7 +293,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo Info info = openAPI.getInfo(); if (StringUtils.isBlank(projectName) && info.getTitle() != null) { // when projectName is not specified, generate it from info.title - projectName = sanitizeName(org.openapitools.codegen.utils.StringUtils.dashize(info.getTitle())); + projectName = sanitizeName(dashize(info.getTitle())); } if (StringUtils.isBlank(projectVersion)) { // when projectVersion is not specified, use info.version @@ -316,7 +320,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo projectName = "openapi-js-client"; } if (StringUtils.isBlank(moduleName)) { - moduleName = org.openapitools.codegen.utils.StringUtils.camelize(org.openapitools.codegen.utils.StringUtils.underscore(projectName)); + moduleName = camelize(underscore(projectName)); } if (StringUtils.isBlank(projectVersion)) { projectVersion = "1.0.0"; @@ -513,11 +517,11 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo case original: return name; case camelCase: - return org.openapitools.codegen.utils.StringUtils.camelize(name, true); + return camelize(name, true); case PascalCase: - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); case snake_case: - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); default: throw new IllegalArgumentException("Invalid model property naming '" + name + "'. Must be 'original', 'camelCase', " + @@ -571,7 +575,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo // camelize the model name // phone_number => PhoneNumber - name = org.openapitools.codegen.utils.StringUtils.camelize(name); + name = camelize(name); // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { @@ -840,18 +844,18 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo throw new RuntimeException("Empty method/operation name (operationId) not allowed"); } - operationId = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true); + operationId = camelize(sanitizeName(operationId), true); // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - String newOperationId = org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId, true); + String newOperationId = camelize("call_" + operationId, true); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId); return newOperationId; } // operationId starts with a number if (operationId.matches("^\\d.*")) { - String newOperationId = org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId, true); + String newOperationId = camelize("call_" + operationId, true); LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + newOperationId); return newOperationId; } @@ -1133,7 +1137,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo @Override public String toEnumName(CodegenProperty property) { - return sanitizeName(org.openapitools.codegen.utils.StringUtils.camelize(property.name)) + "Enum"; + return sanitizeName(camelize(property.name)) + "Enum"; } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClosureAngularClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClosureAngularClientCodegen.java index 6e8182c5077..250e2ed344f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClosureAngularClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClosureAngularClientCodegen.java @@ -41,7 +41,7 @@ import java.util.*; import java.io.File; import org.apache.commons.lang3.StringUtils; - +import static org.openapitools.codegen.utils.StringUtils.camelize; public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(JavascriptClosureAngularClientCodegen.class); @@ -188,7 +188,7 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem // camelize the variable name // pet_id => PetId - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); // for reserved word or word starting with number, append _ if (isReservedWord(name) || name.matches("^\\d.*")) @@ -215,13 +215,13 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. return => ModelReturn (after camelize) } // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override @@ -305,11 +305,11 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem throw new RuntimeException("Empty method/operation name (operationId) not allowed"); } - operationId = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true); + operationId = camelize(sanitizeName(operationId), true); // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - String newOperationId = org.openapitools.codegen.utils.StringUtils.camelize("call_" + operationId, true); + String newOperationId = camelize("call_" + operationId, true); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId); return newOperationId; } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptFlowtypedClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptFlowtypedClientCodegen.java index 003b2f305ca..4e00068accc 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptFlowtypedClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptFlowtypedClientCodegen.java @@ -29,6 +29,7 @@ import org.openapitools.codegen.utils.ModelUtils; import java.text.SimpleDateFormat; import java.util.*; +import static org.openapitools.codegen.utils.StringUtils.dashize; public class JavascriptFlowtypedClientCodegen extends AbstractTypeScriptClientCodegen { private static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm", Locale.ROOT); @@ -186,7 +187,7 @@ public class JavascriptFlowtypedClientCodegen extends AbstractTypeScriptClientCo Info info = openAPI.getInfo(); if (StringUtils.isBlank(npmName) && info.getTitle() != null) { // when projectName is not specified, generate it from info.title - npmName = sanitizeName(org.openapitools.codegen.utils.StringUtils.dashize(info.getTitle())); + npmName = sanitizeName(dashize(info.getTitle())); } if (StringUtils.isBlank(npmVersion)) { // when projectVersion is not specified, use info.version diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java index fb79272c9f5..fa146f08670 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java @@ -35,6 +35,7 @@ import java.util.*; import java.util.regex.Matcher; import java.util.stream.Collectors; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class KotlinSpringServerCodegen extends AbstractKotlinCodegen implements BeanValidationFeatures { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/LuaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/LuaClientCodegen.java index de11614209f..a80f308998b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/LuaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/LuaClientCodegen.java @@ -43,6 +43,8 @@ import java.util.ListIterator; import java.util.Locale; import java.util.Map; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(LuaClientCodegen.class); @@ -203,7 +205,7 @@ public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig { if (this.reservedWordsMappings().containsKey(name)) { return this.reservedWordsMappings().get(name); } - return org.openapitools.codegen.utils.StringUtils.camelize(name) + '_'; + return camelize(name) + '_'; } @Override @@ -226,7 +228,7 @@ public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig { // convert variable name to snake case // PetId => pet_id - name = org.openapitools.codegen.utils.StringUtils.underscore(name); + name = underscore(name); // for reserved word or word starting with number, append _ if (isReservedWord(name)) @@ -273,7 +275,7 @@ public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig { name = "model_" + name; // e.g. 200Response => Model200Response (after camelize) } - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); } @Override @@ -282,7 +284,7 @@ public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig { name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. // e.g. PetApi.lua => pet_api.lua - return org.openapitools.codegen.utils.StringUtils.underscore(name) + "_api"; + return underscore(name) + "_api"; } @Override @@ -339,7 +341,7 @@ public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String toApiName(String name) { - return org.openapitools.codegen.utils.StringUtils.underscore(super.toApiName(name)); + return underscore(super.toApiName(name)); } @Override @@ -391,11 +393,11 @@ public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig { // method name cannot use reserved keyword, e.g. return if (isReservedWord(sanitizedOperationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore("call_" + operationId)); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore("call_" + operationId)); sanitizedOperationId = "call_" + sanitizedOperationId; } - return org.openapitools.codegen.utils.StringUtils.underscore(sanitizedOperationId); + return underscore(sanitizedOperationId); } @Override @@ -530,7 +532,7 @@ public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig { } // string - String enumName = sanitizeName(org.openapitools.codegen.utils.StringUtils.underscore(name).toUpperCase(Locale.ROOT)); + String enumName = sanitizeName(underscore(name).toUpperCase(Locale.ROOT)); enumName = enumName.replaceFirst("^_", ""); enumName = enumName.replaceFirst("_$", ""); @@ -543,7 +545,7 @@ public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String toEnumName(CodegenProperty property) { - String enumName = org.openapitools.codegen.utils.StringUtils.underscore(toModelName(property.name)).toUpperCase(Locale.ROOT); + String enumName = underscore(toModelName(property.name)).toUpperCase(Locale.ROOT); // remove [] for array or map of enum enumName = enumName.replace("[]", ""); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ObjcClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ObjcClientCodegen.java index 4662fd132cc..42db45986d2 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ObjcClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ObjcClientCodegen.java @@ -44,7 +44,7 @@ import java.util.Map; import java.util.Set; import org.apache.commons.lang3.StringUtils; - +import static org.openapitools.codegen.utils.StringUtils.camelize; public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(ObjcClientCodegen.class); @@ -432,7 +432,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { // model name starts with number /* no need for the fix below as objc model starts with prefix (e.g. SWG) if (type.matches("^\\d.*")) { - LOGGER.warn(type + " (model name starts with number) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + type)); + LOGGER.warn(type + " (model name starts with number) cannot be used as model name. Renamed to " + camelize("model_" + type)); type = "model_" + type; // e.g. 200Response => Model200Response (after camelize) } */ @@ -456,7 +456,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { importMapping.values().contains(type) || defaultIncludes.contains(type) || languageSpecificPrimitives.contains(type)) { - return org.openapitools.codegen.utils.StringUtils.camelize(type); + return camelize(type); } // custom classes else { @@ -468,7 +468,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { type = modelNamePrefix + "_" + type; } - return classPrefix + org.openapitools.codegen.utils.StringUtils.camelize(type); // add class prefix + return classPrefix + camelize(type); // add class prefix } } @@ -529,12 +529,12 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String toApiName(String name) { - return classPrefix + org.openapitools.codegen.utils.StringUtils.camelize(name) + "Api"; + return classPrefix + camelize(name) + "Api"; } @Override public String toApiFilename(String name) { - return classPrefix + org.openapitools.codegen.utils.StringUtils.camelize(name) + "Api"; + return classPrefix + camelize(name) + "Api"; } @Override @@ -559,7 +559,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { // camelize (lower first character) the variable name // e.g. `pet_id` to `petId` - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); // for reserved word or word starting with number, prepend `_` if (isReservedWord(name) || name.matches("^\\d.*")) { @@ -604,11 +604,11 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId), true)); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true)); operationId = "call_" + operationId; } - return org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true); + return camelize(sanitizeName(operationId), true); } public void setClassPrefix(String classPrefix) { @@ -647,7 +647,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { for (CodegenOperation operation : ops) { if (!operation.allParams.isEmpty()) { String firstParamName = operation.allParams.get(0).paramName; - operation.vendorExtensions.put("firstParamAltName", org.openapitools.codegen.utils.StringUtils.camelize(firstParamName)); + operation.vendorExtensions.put("firstParamAltName", camelize(firstParamName)); } } } @@ -657,7 +657,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public void postProcessModelProperty(CodegenModel model, CodegenProperty schema) { super.postProcessModelProperty(model, schema); - schema.vendorExtensions.put("x-uppercaseName", org.openapitools.codegen.utils.StringUtils.camelize(schema.name)); + schema.vendorExtensions.put("x-uppercaseName", camelize(schema.name)); } /** diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PerlClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PerlClientCodegen.java index 60e52c4e7fd..6743d7bf3eb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PerlClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PerlClientCodegen.java @@ -34,6 +34,9 @@ import java.util.regex.Matcher; import org.apache.commons.lang3.StringUtils; import org.apache.commons.io.FilenameUtils; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; + public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(PerlClientCodegen.class); @@ -282,7 +285,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { public String toVarName(String name) { // return the name in underscore style // PhoneNumber => phone_number - name = org.openapitools.codegen.utils.StringUtils.underscore(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. + name = underscore(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. // parameter name starting with number won't compile // need to escape it by appending _ at the beginning @@ -304,13 +307,13 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { // model name cannot use reserved keyword if (isReservedWord(name)) { - LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; } // model name starts with number if (name.matches("^\\d.*")) { - LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. 200Response => Model200Response (after camelize) } @@ -325,7 +328,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override @@ -360,7 +363,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. // e.g. phone_number_api.rb => PhoneNumberApi.rb - return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Api"; + return camelize(name) + "Api"; } @Override @@ -369,32 +372,32 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig { return "DefaultApi"; } // e.g. phone_number_api => PhoneNumberApi - return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Api"; + return camelize(name) + "Api"; } @Override public String toOperationId(String operationId) { //rename to empty_function_name_1 (e.g.) if method name is empty if (StringUtils.isEmpty(operationId)) { - operationId = org.openapitools.codegen.utils.StringUtils.underscore("empty_function_name_" + emptyFunctionNameCounter++); + operationId = underscore("empty_function_name_" + emptyFunctionNameCounter++); LOGGER.warn("Empty method name (operationId) found. Renamed to " + operationId); return operationId; } // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId))); - return org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId)); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId))); + return underscore(sanitizeName("call_" + operationId)); } // operationId starts with a number if (operationId.matches("^\\d.*")) { - LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId))); + LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId))); operationId = "call_" + operationId; } - //return org.openapitools.codegen.utils.StringUtils.underscore(operationId).replaceAll("[^A-Za-z0-9_]", ""); - return org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName(operationId)); + //return underscore(operationId).replaceAll("[^A-Za-z0-9_]", ""); + return underscore(sanitizeName(operationId)); } public void setModuleName(String moduleName) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpLaravelServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpLaravelServerCodegen.java index 5c67685d979..e6cbfc36af4 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpLaravelServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpLaravelServerCodegen.java @@ -22,6 +22,7 @@ import org.openapitools.codegen.*; import java.io.File; import java.util.*; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class PhpLaravelServerCodegen extends AbstractPhpCodegen { protected String apiVersion = "1.0.0"; @@ -241,7 +242,7 @@ public class PhpLaravelServerCodegen extends AbstractPhpCodegen { return "DefaultController"; } - return org.openapitools.codegen.utils.StringUtils.camelize(name, false) + "Controller"; + return camelize(name, false) + "Controller"; } protected String controllerFileFolder() { @@ -263,6 +264,6 @@ public class PhpLaravelServerCodegen extends AbstractPhpCodegen { return "DefaultController"; } - return org.openapitools.codegen.utils.StringUtils.camelize(name, false) + "Controller"; + return camelize(name, false) + "Controller"; } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSilexServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSilexServerCodegen.java index e8866e05808..3d697a135e7 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSilexServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSilexServerCodegen.java @@ -36,6 +36,8 @@ import java.util.Map; import org.apache.commons.lang3.StringUtils; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class PhpSilexServerCodegen extends DefaultCodegen implements CodegenConfig { protected String invokerPackage; @@ -46,7 +48,7 @@ public class PhpSilexServerCodegen extends DefaultCodegen implements CodegenConf public PhpSilexServerCodegen() { super(); - invokerPackage = org.openapitools.codegen.utils.StringUtils.camelize("OpenAPIServer"); + invokerPackage = camelize("OpenAPIServer"); String packageName = "OpenAPIServer"; modelPackage = "lib" + File.separator + "models"; apiPackage = "lib"; @@ -200,7 +202,7 @@ public class PhpSilexServerCodegen extends DefaultCodegen implements CodegenConf public String toVarName(String name) { // return the name in underscore style // PhoneNumber => phone_number - name = org.openapitools.codegen.utils.StringUtils.underscore(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. + name = underscore(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. // parameter name starting with number won't compile // need to escape it by appending _ at the beginning @@ -226,7 +228,7 @@ public class PhpSilexServerCodegen extends DefaultCodegen implements CodegenConf // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override @@ -259,7 +261,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] = "{" + org.openapitools.codegen.utils.StringUtils.camelize(items[i].substring(1, items[i].length() - 1), true) + "}"; + items[i] = "{" + camelize(items[i].substring(1, items[i].length() - 1), true) + "}"; } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java index 95fcba39688..1e17640e066 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSymfonyServerCodegen.java @@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.util.*; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements CodegenConfig { @SuppressWarnings("hiding") @@ -568,14 +569,14 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg if (name.isEmpty()) { return "DefaultApiInterface"; } - return org.openapitools.codegen.utils.StringUtils.camelize(name, false) + "ApiInterface"; + return camelize(name, false) + "ApiInterface"; } protected String toControllerName(String name) { if (name.isEmpty()) { return "DefaultController"; } - return org.openapitools.codegen.utils.StringUtils.camelize(name, false) + "Controller"; + return camelize(name, false) + "Controller"; } protected String toSymfonyService(String name) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java index 86536a3c15a..7c7ba4ba73f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java @@ -41,6 +41,7 @@ import java.util.Locale; import java.util.Map; import static java.util.UUID.randomUUID; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class PowerShellClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(PowerShellClientCodegen.class); @@ -329,19 +330,19 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. return => ModelReturn (after camelize) } // model name starts with number if (name.matches("^\\d.*")) { - LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. 200Response => Model200Response (after camelize) } // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override @@ -406,11 +407,11 @@ public class PowerShellClientCodegen extends DefaultCodegen implements CodegenCo // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId))); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId))); operationId = "call_" + operationId; } - return org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId)); + return camelize(sanitizeName(operationId)); } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java index 3bc13a1083c..aa51915b842 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java @@ -43,6 +43,8 @@ import java.util.Locale; import java.util.Map; import java.util.regex.Pattern; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(PythonClientCodegen.class); @@ -444,7 +446,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig // underscore the variable name // petId => pet_id - name = org.openapitools.codegen.utils.StringUtils.underscore(name); + name = underscore(name); // remove leading underscore name = name.replaceAll("^_*", ""); @@ -476,13 +478,13 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. return => ModelReturn (after camelize) } // model name starts with number if (name.matches("^\\d.*")) { - LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. 200Response => Model200Response (after camelize) } @@ -496,14 +498,14 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override public String toModelFilename(String name) { // underscore the model file name // PhoneNumber => phone_number - return org.openapitools.codegen.utils.StringUtils.underscore(dropDots(toModelName(name))); + return underscore(dropDots(toModelName(name))); } @Override @@ -517,7 +519,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig name = name.replaceAll("-", "_"); // e.g. PhoneNumberApi.py => phone_number_api.py - return org.openapitools.codegen.utils.StringUtils.underscore(name) + "_api"; + return underscore(name) + "_api"; } @Override @@ -531,7 +533,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig return "DefaultApi"; } // e.g. phone_number_api => PhoneNumberApi - return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Api"; + return camelize(name) + "Api"; } @Override @@ -539,7 +541,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig if (name.length() == 0) { return "default_api"; } - return org.openapitools.codegen.utils.StringUtils.underscore(name) + "_api"; + return underscore(name) + "_api"; } @Override @@ -551,17 +553,17 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId))); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId))); operationId = "call_" + operationId; } // operationId starts with a number if (operationId.matches("^\\d.*")) { - LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId))); + LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId))); operationId = "call_" + operationId; } - return org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName(operationId)); + return underscore(sanitizeName(operationId)); } public void setPackageName(String packageName) { @@ -591,7 +593,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig */ @SuppressWarnings("static-method") public String generatePackageName(String packageName) { - return org.openapitools.codegen.utils.StringUtils.underscore(packageName.replaceAll("[^\\w]+", "")); + return underscore(packageName.replaceAll("[^\\w]+", "")); } /** diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFlaskConnexionServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFlaskConnexionServerCodegen.java index 9a2a92aa080..498f8abe955 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFlaskConnexionServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFlaskConnexionServerCodegen.java @@ -35,6 +35,8 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.util.*; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class PythonFlaskConnexionServerCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(PythonFlaskConnexionServerCodegen.class); @@ -253,12 +255,12 @@ public class PythonFlaskConnexionServerCodegen extends DefaultCodegen implements if (name == null || name.length() == 0) { return "DefaultController"; } - return org.openapitools.codegen.utils.StringUtils.camelize(name, false) + "Controller"; + return camelize(name, false) + "Controller"; } @Override public String toApiFilename(String name) { - return org.openapitools.codegen.utils.StringUtils.underscore(toApiName(name)); + return underscore(toApiName(name)); } @Override @@ -412,7 +414,7 @@ public class PythonFlaskConnexionServerCodegen extends DefaultCodegen implements // underscore the variable name // petId => pet_id - name = org.openapitools.codegen.utils.StringUtils.underscore(name); + name = underscore(name); // remove leading underscore name = name.replaceAll("^_*", ""); @@ -440,7 +442,7 @@ public class PythonFlaskConnexionServerCodegen extends DefaultCodegen implements public String toModelFilename(String name) { // underscore the model file name // PhoneNumber => phone_number - return org.openapitools.codegen.utils.StringUtils.underscore(dropDots(toModelName(name))); + return underscore(dropDots(toModelName(name))); } @Override @@ -451,13 +453,13 @@ public class PythonFlaskConnexionServerCodegen extends DefaultCodegen implements // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. return => ModelReturn (after camelize) } // model name starts with number if (name.matches("^\\d.*")) { - LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. 200Response => Model200Response (after camelize) } @@ -471,7 +473,7 @@ public class PythonFlaskConnexionServerCodegen extends DefaultCodegen implements // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override @@ -483,11 +485,11 @@ public class PythonFlaskConnexionServerCodegen extends DefaultCodegen implements // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId))); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId))); operationId = "call_" + operationId; } - return org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName(operationId)); + return underscore(sanitizeName(operationId)); } /** diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java index 49db39f4874..4c4dd0ae78b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RClientCodegen.java @@ -28,6 +28,8 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.util.*; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class RClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(RClientCodegen.class); @@ -173,7 +175,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { if (this.reservedWordsMappings().containsKey(name)) { return this.reservedWordsMappings().get(name); } - return org.openapitools.codegen.utils.StringUtils.camelize(name) + '_'; + return camelize(name) + '_'; } @Override @@ -196,7 +198,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { // convert variable name to snake case // PetId => pet_id - name = org.openapitools.codegen.utils.StringUtils.underscore(name); + name = underscore(name); // for reserved word or word starting with number, append _ if (isReservedWord(name)) @@ -233,17 +235,17 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. return => ModelReturn (after camelize) } // model name starts with number if (name.matches("^\\d.*")) { - LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. 200Response => Model200Response (after camelize) } - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override @@ -252,7 +254,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. // e.g. PetApi.r => pet_api.r - return org.openapitools.codegen.utils.StringUtils.camelize(name + "_api"); + return camelize(name + "_api"); } @Override @@ -277,7 +279,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String toApiName(String name) { - return org.openapitools.codegen.utils.StringUtils.camelize(super.toApiName(name)); + return camelize(super.toApiName(name)); } @Override @@ -329,11 +331,11 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { // method name cannot use reserved keyword, e.g. return if (isReservedWord(sanitizedOperationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore("call_" + operationId)); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore("call_" + operationId)); sanitizedOperationId = "call_" + sanitizedOperationId; } - return org.openapitools.codegen.utils.StringUtils.underscore(sanitizedOperationId); + return underscore(sanitizedOperationId); } @Override @@ -433,7 +435,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { } // string - String enumName = sanitizeName(org.openapitools.codegen.utils.StringUtils.underscore(name).toUpperCase(Locale.ROOT)); + String enumName = sanitizeName(underscore(name).toUpperCase(Locale.ROOT)); enumName = enumName.replaceFirst("^_", ""); enumName = enumName.replaceFirst("_$", ""); @@ -446,7 +448,7 @@ public class RClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String toEnumName(CodegenProperty property) { - String enumName = org.openapitools.codegen.utils.StringUtils.underscore(toModelName(property.name)).toUpperCase(Locale.ROOT); + String enumName = underscore(toModelName(property.name)).toUpperCase(Locale.ROOT); // remove [] for array or map of enum enumName = enumName.replace("[]", ""); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java index 575c983cbad..4c0ab9c54a8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java @@ -31,6 +31,9 @@ import java.util.Iterator; import java.util.Locale; import java.util.Map; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; + public class RubyClientCodegen extends AbstractRubyCodegen { private static final Logger LOGGER = LoggerFactory.getLogger(RubyClientCodegen.class); public static final String GEM_NAME = "gemName"; @@ -252,7 +255,7 @@ public class RubyClientCodegen extends AbstractRubyCodegen { */ @SuppressWarnings("static-method") public String generateModuleName(String gemName) { - return org.openapitools.codegen.utils.StringUtils.camelize(gemName.replaceAll("[^\\w]+", "_")); + return camelize(gemName.replaceAll("[^\\w]+", "_")); } /** @@ -263,7 +266,7 @@ public class RubyClientCodegen extends AbstractRubyCodegen { */ @SuppressWarnings("static-method") public String generateGemName(String moduleName) { - return org.openapitools.codegen.utils.StringUtils.underscore(moduleName.replaceAll("[^\\w]+", "")); + return underscore(moduleName.replaceAll("[^\\w]+", "")); } @Override @@ -330,25 +333,25 @@ public class RubyClientCodegen extends AbstractRubyCodegen { // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - String modelName = org.openapitools.codegen.utils.StringUtils.camelize("Model" + name); + String modelName = camelize("Model" + name); LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName); return modelName; } // model name starts with number if (name.matches("^\\d.*")) { - LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. 200Response => Model200Response (after camelize) } // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override public String toModelFilename(String name) { - return org.openapitools.codegen.utils.StringUtils.underscore(toModelName(name)); + return underscore(toModelName(name)); } @Override @@ -362,7 +365,7 @@ public class RubyClientCodegen extends AbstractRubyCodegen { name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. // e.g. PhoneNumberApi.rb => phone_number_api.rb - return org.openapitools.codegen.utils.StringUtils.underscore(name) + "_api"; + return underscore(name) + "_api"; } @Override @@ -386,7 +389,7 @@ public class RubyClientCodegen extends AbstractRubyCodegen { return "DefaultApi"; } // e.g. phone_number_api => PhoneNumberApi - return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Api"; + return camelize(name) + "Api"; } @Override @@ -414,7 +417,7 @@ public class RubyClientCodegen extends AbstractRubyCodegen { } // string - String enumName = sanitizeName(org.openapitools.codegen.utils.StringUtils.underscore(name).toUpperCase(Locale.ROOT)); + String enumName = sanitizeName(underscore(name).toUpperCase(Locale.ROOT)); enumName = enumName.replaceFirst("^_", ""); enumName = enumName.replaceFirst("_$", ""); @@ -427,7 +430,7 @@ public class RubyClientCodegen extends AbstractRubyCodegen { @Override public String toEnumName(CodegenProperty property) { - String enumName = org.openapitools.codegen.utils.StringUtils.underscore(toModelName(property.name)).toUpperCase(Locale.ROOT); + String enumName = underscore(toModelName(property.name)).toUpperCase(Locale.ROOT); enumName = enumName.replaceFirst("^_", ""); enumName = enumName.replaceFirst("_$", ""); @@ -448,25 +451,25 @@ public class RubyClientCodegen extends AbstractRubyCodegen { public String toOperationId(String operationId) { // rename to empty_method_name_1 (e.g.) if method name is empty if (StringUtils.isEmpty(operationId)) { - operationId = org.openapitools.codegen.utils.StringUtils.underscore("empty_method_name_" + emptyMethodNameCounter++); + operationId = underscore("empty_method_name_" + emptyMethodNameCounter++); LOGGER.warn("Empty method name (operationId) found. Renamed to " + operationId); return operationId; } // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - String newOperationId = org.openapitools.codegen.utils.StringUtils.underscore("call_" + operationId); + String newOperationId = underscore("call_" + operationId); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId); return newOperationId; } // operationId starts with a number if (operationId.matches("^\\d.*")) { - LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId))); + LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId))); operationId = "call_" + operationId; } - return org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName(operationId)); + return underscore(sanitizeName(operationId)); } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyOnRailsServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyOnRailsServerCodegen.java index d67b1ad5ce7..1de90332b08 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyOnRailsServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyOnRailsServerCodegen.java @@ -19,7 +19,6 @@ package org.openapitools.codegen.languages; import java.text.SimpleDateFormat; - import org.openapitools.codegen.CliOption; import org.openapitools.codegen.CodegenType; import org.openapitools.codegen.CodegenConstants; @@ -34,6 +33,8 @@ import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class RubyOnRailsServerCodegen extends AbstractRubyCodegen { @@ -221,28 +222,28 @@ public class RubyOnRailsServerCodegen extends AbstractRubyCodegen { public String toModelName(String name) { // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - String modelName = org.openapitools.codegen.utils.StringUtils.camelize("Model" + name); + String modelName = camelize("Model" + name); LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName); return modelName; } // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override public String toModelFilename(String name) { // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - String filename = org.openapitools.codegen.utils.StringUtils.underscore("model_" + name); + String filename = underscore("model_" + name); LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + filename); return filename; } // underscore the model file name // PhoneNumber.rb => phone_number.rb - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); } @Override @@ -251,7 +252,7 @@ public class RubyOnRailsServerCodegen extends AbstractRubyCodegen { name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. // e.g. DefaultController => defaults_controller.rb - return org.openapitools.codegen.utils.StringUtils.underscore(name) + "_controller"; + return underscore(name) + "_controller"; } @Override @@ -261,7 +262,7 @@ public class RubyOnRailsServerCodegen extends AbstractRubyCodegen { } // e.g. PhoneNumber => phone_number - return org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName(name)); + return underscore(sanitizeName(name)); } @Override @@ -270,7 +271,7 @@ public class RubyOnRailsServerCodegen extends AbstractRubyCodegen { return "ApiController"; } // e.g. phone_number_controller => PhoneNumberController - return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Controller"; + return camelize(name) + "Controller"; } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubySinatraServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubySinatraServerCodegen.java index 05ecc9fa4e8..d0f71a2c134 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubySinatraServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubySinatraServerCodegen.java @@ -28,6 +28,8 @@ import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class RubySinatraServerCodegen extends AbstractRubyCodegen { @@ -110,26 +112,26 @@ public class RubySinatraServerCodegen extends AbstractRubyCodegen { public String toModelName(String name) { // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. return => ModelReturn (after camelize) } // camelize the model name // phone_number => PhoneNumber - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } @Override public String toModelFilename(String name) { // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore("model_" + name)); + LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + underscore("model_" + name)); name = "model_" + name; // e.g. return => ModelReturn (after camelize) } // underscore the model file name // PhoneNumber.rb => phone_number.rb - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); } @Override @@ -138,7 +140,7 @@ public class RubySinatraServerCodegen extends AbstractRubyCodegen { name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. // e.g. PhoneNumberApi.rb => phone_number_api.rb - return org.openapitools.codegen.utils.StringUtils.underscore(name) + "_api"; + return underscore(name) + "_api"; } @Override @@ -147,7 +149,7 @@ public class RubySinatraServerCodegen extends AbstractRubyCodegen { return "DefaultApi"; } // e.g. phone_number_api => PhoneNumberApi - return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Api"; + return camelize(name) + "Api"; } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java index 1fcc570dd60..c6f9da87a6c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java @@ -30,6 +30,8 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.util.*; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class RustClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(RustClientCodegen.class); @@ -224,7 +226,7 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig { return name; // snake_case, e.g. PetId => pet_id - name = StringUtils.underscore(name); + name = underscore(name); // for reserved word or word starting with number, append _ if (isReservedWord(name)) @@ -246,7 +248,7 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig { public String toModelName(String name) { // camelize the model name // phone_number => PhoneNumber - return StringUtils.camelize(toModelFilename(name)); + return camelize(toModelFilename(name)); } @Override @@ -274,7 +276,7 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig { name = "model_" + name; // e.g. 200Response => Model200Response (after camelize) } - return StringUtils.underscore(name); + return underscore(name); } @Override @@ -283,7 +285,7 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig { name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. // e.g. PetApi.rs => pet_api.rs - return StringUtils.underscore(name) + "_api"; + return underscore(name) + "_api"; } @Override @@ -504,7 +506,7 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig { } // string - String enumName = sanitizeName(org.openapitools.codegen.utils.StringUtils.underscore(name).toUpperCase(Locale.ROOT)); + String enumName = sanitizeName(underscore(name).toUpperCase(Locale.ROOT)); enumName = enumName.replaceFirst("^_", ""); enumName = enumName.replaceFirst("_$", ""); @@ -517,7 +519,7 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String toEnumName(CodegenProperty property) { - String enumName = org.openapitools.codegen.utils.StringUtils.underscore(toModelName(property.name)).toUpperCase(Locale.ROOT); + String enumName = underscore(toModelName(property.name)).toUpperCase(Locale.ROOT); // remove [] for array or map of enum enumName = enumName.replace("[]", ""); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java index 445850a01dd..b86dd81324e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java @@ -55,7 +55,8 @@ import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Set; - +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { @@ -301,7 +302,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { if (name.length() == 0) { return "default"; } - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); } /** @@ -331,7 +332,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { public String toModelName(String name) { // camelize the model name // phone_number => PhoneNumber - String camelizedName = org.openapitools.codegen.utils.StringUtils.camelize(toModelFilename(name)); + String camelizedName = camelize(toModelFilename(name)); // model name cannot use reserved keyword, e.g. return if (isReservedWord(camelizedName)) { @@ -364,18 +365,18 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { sanitizedName = escapeReservedWord(sanitizedName); } - return org.openapitools.codegen.utils.StringUtils.underscore(sanitizedName); + return underscore(sanitizedName); } @Override public String toOperationId(String operationId) { // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId))); + LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId))); operationId = "call_" + operationId; } - return org.openapitools.codegen.utils.StringUtils.camelize(operationId); + return camelize(operationId); } @Override @@ -392,16 +393,16 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { - LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize("model_" + name)); + LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name)); name = "model_" + name; // e.g. return => ModelReturn (after camelize) } - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); } @Override public String toEnumName(CodegenProperty property) { - return sanitizeName(org.openapitools.codegen.utils.StringUtils.camelize(property.name)) + "Enum"; + return sanitizeName(camelize(property.name)) + "Enum"; } @Override @@ -452,7 +453,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. // e.g. PetApi.go => pet_api.go - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); } @Override @@ -522,8 +523,8 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { pathSetMap.put(pathId, pathSetEntry); } - op.vendorExtensions.put("operation_id", org.openapitools.codegen.utils.StringUtils.underscore(op.operationId)); - op.vendorExtensions.put("uppercase_operation_id", org.openapitools.codegen.utils.StringUtils.underscore(op.operationId).toUpperCase(Locale.ROOT)); + op.vendorExtensions.put("operation_id", underscore(op.operationId)); + op.vendorExtensions.put("uppercase_operation_id", underscore(op.operationId).toUpperCase(Locale.ROOT)); op.vendorExtensions.put("path", op.path.replace("{", ":").replace("}", "")); op.vendorExtensions.put("PATH_ID", pathId); op.vendorExtensions.put("hasPathParams", !op.pathParams.isEmpty()); @@ -604,13 +605,13 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { if (rsp.vendorExtensions.containsKey("x-responseId")) { responseId = (String) rsp.vendorExtensions.get("x-responseId"); } else if (words.length != 0) { - responseId = org.openapitools.codegen.utils.StringUtils.camelize(words[0].replace(" ", "_")); + responseId = camelize(words[0].replace(" ", "_")); } else { responseId = "Status" + rsp.code; } rsp.vendorExtensions.put("x-responseId", responseId); - rsp.vendorExtensions.put("x-uppercaseResponseId", org.openapitools.codegen.utils.StringUtils.underscore(responseId).toUpperCase(Locale.ROOT)); - rsp.vendorExtensions.put("uppercase_operation_id", org.openapitools.codegen.utils.StringUtils.underscore(op.operationId).toUpperCase(Locale.ROOT)); + rsp.vendorExtensions.put("x-uppercaseResponseId", underscore(responseId).toUpperCase(Locale.ROOT)); + rsp.vendorExtensions.put("uppercase_operation_id", underscore(op.operationId).toUpperCase(Locale.ROOT)); if (rsp.dataType != null) { rsp.vendorExtensions.put("uppercase_data_type", (rsp.dataType.replace("models::", "")).toUpperCase(Locale.ROOT)); @@ -687,7 +688,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { if (op.bodyParam != null) { // Default to consuming json - op.bodyParam.vendorExtensions.put("uppercase_operation_id", org.openapitools.codegen.utils.StringUtils.underscore(op.operationId).toUpperCase(Locale.ROOT)); + op.bodyParam.vendorExtensions.put("uppercase_operation_id", underscore(op.operationId).toUpperCase(Locale.ROOT)); if (consumesXml) { op.bodyParam.vendorExtensions.put("consumesXml", true); } else if (consumesPlainText) { @@ -700,7 +701,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { for (CodegenParameter param : op.bodyParams) { processParam(param, op); - param.vendorExtensions.put("uppercase_operation_id", org.openapitools.codegen.utils.StringUtils.underscore(op.operationId).toUpperCase(Locale.ROOT)); + param.vendorExtensions.put("uppercase_operation_id", underscore(op.operationId).toUpperCase(Locale.ROOT)); // Default to producing json if nothing else is specified if (consumesXml) { @@ -938,9 +939,9 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { // If we use a more qualified model name, then only camelize the actual type, not the qualifier. if (property.dataType.contains(":")) { int position = property.dataType.lastIndexOf(":"); - property.dataType = property.dataType.substring(0, position) + org.openapitools.codegen.utils.StringUtils.camelize(property.dataType.substring(position)); + property.dataType = property.dataType.substring(0, position) + camelize(property.dataType.substring(position)); } else { - property.dataType = org.openapitools.codegen.utils.StringUtils.camelize(property.dataType, false); + property.dataType = camelize(property.dataType, false); } } @@ -988,7 +989,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { } } - property.name = org.openapitools.codegen.utils.StringUtils.underscore(property.name); + property.name = underscore(property.name); if (!property.required) { property.defaultValue = (property.defaultValue != null) ? "Some(" + property.defaultValue + ")" : "None"; diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java index ba8ea0062dd..7bffd96158c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java @@ -35,6 +35,7 @@ import java.io.StringWriter; import java.io.Writer; import java.util.*; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements CodegenConfig { protected String mainPackage = "org.openapitools.client"; @@ -336,7 +337,7 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code @Override public String formatFragment(String fragment) { - return org.openapitools.codegen.utils.StringUtils.camelize(fragment, !capitalizeFirst); + return camelize(fragment, !capitalizeFirst); } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaHttpClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaHttpClientCodegen.java index f02d21d289f..ad236633f4b 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaHttpClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaHttpClientCodegen.java @@ -26,6 +26,8 @@ import java.io.File; import java.util.Arrays; import java.util.HashMap; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class ScalaHttpClientCodegen extends AbstractScalaCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(ScalaHttpClientCodegen.class); @@ -185,11 +187,11 @@ public class ScalaHttpClientCodegen extends AbstractScalaCodegen implements Code case original: return name; case camelCase: - return org.openapitools.codegen.utils.StringUtils.camelize(name, true); + return camelize(name, true); case PascalCase: - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); case snake_case: - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); default: throw new IllegalArgumentException("Invalid model property naming '" + name + "'. Must be 'original', 'camelCase', " + @@ -227,7 +229,7 @@ public class ScalaHttpClientCodegen extends AbstractScalaCodegen implements Code throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); } - return org.openapitools.codegen.utils.StringUtils.camelize(operationId, true); + return camelize(operationId, true); } @Override @@ -236,7 +238,7 @@ public class ScalaHttpClientCodegen extends AbstractScalaCodegen implements Code // camelize the model name // phone_number => PhoneNumber - final String camelizedName = org.openapitools.codegen.utils.StringUtils.camelize(sanitizedName); + final String camelizedName = camelize(sanitizedName); // model name cannot use reserved keyword, e.g. return if (isReservedWord(camelizedName)) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaLagomServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaLagomServerCodegen.java index 1b8272a262e..adf429c65cd 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaLagomServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaLagomServerCodegen.java @@ -23,7 +23,8 @@ import org.apache.commons.lang3.StringUtils; import java.util.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class ScalaLagomServerCodegen extends AbstractScalaCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(ScalaLagomServerCodegen.class); @@ -167,11 +168,11 @@ public class ScalaLagomServerCodegen extends AbstractScalaCodegen implements Cod case original: return name; case camelCase: - return org.openapitools.codegen.utils.StringUtils.camelize(name, true); + return camelize(name, true); case PascalCase: - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); case snake_case: - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); default: throw new IllegalArgumentException("Invalid model property naming '" + name + "'. Must be 'original', 'camelCase', " + @@ -207,7 +208,7 @@ public class ScalaLagomServerCodegen extends AbstractScalaCodegen implements Cod throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); } - return org.openapitools.codegen.utils.StringUtils.camelize(operationId, true); + return camelize(operationId, true); } @Override @@ -216,7 +217,7 @@ public class ScalaLagomServerCodegen extends AbstractScalaCodegen implements Cod // camelize the model name // phone_number => PhoneNumber - final String camelizedName = org.openapitools.codegen.utils.StringUtils.camelize(sanitizedName); + final String camelizedName = camelize(sanitizedName); // model name cannot use reserved keyword, e.g. return if (isReservedWord(camelizedName)) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalazClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalazClientCodegen.java index 6936e6df867..81d413b2169 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalazClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalazClientCodegen.java @@ -31,6 +31,8 @@ import java.io.Writer; import java.util.Arrays; import java.util.HashMap; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class ScalazClientCodegen extends AbstractScalaCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(ScalazClientCodegen.class); @@ -164,11 +166,11 @@ public class ScalazClientCodegen extends AbstractScalaCodegen implements Codegen case original: return name; case camelCase: - return org.openapitools.codegen.utils.StringUtils.camelize(name, true); + return camelize(name, true); case PascalCase: - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); case snake_case: - return org.openapitools.codegen.utils.StringUtils.underscore(name); + return underscore(name); default: throw new IllegalArgumentException("Invalid model property naming '" + name + "'. Must be 'original', 'camelCase', " + @@ -204,7 +206,7 @@ public class ScalazClientCodegen extends AbstractScalaCodegen implements Codegen throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); } - return org.openapitools.codegen.utils.StringUtils.camelize(operationId, true); + return camelize(operationId, true); } @Override @@ -213,7 +215,7 @@ public class ScalazClientCodegen extends AbstractScalaCodegen implements Codegen // camelize the model name // phone_number => PhoneNumber - final String camelizedName = org.openapitools.codegen.utils.StringUtils.camelize(sanitizedName); + final String camelizedName = camelize(sanitizedName); // model name cannot use reserved keyword, e.g. return if (isReservedWord(camelizedName)) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java index 9865d665c2d..667133e0eff 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java @@ -50,6 +50,7 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.stream.Collectors; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class SpringCodegen extends AbstractJavaCodegen implements BeanValidationFeatures, PerformBeanValidationFeatures, @@ -478,7 +479,7 @@ public class SpringCodegen extends AbstractJavaCodegen title = title.substring(0, title.length() - 3); } - this.title = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(title), true); + this.title = camelize(sanitizeName(title), true); } additionalProperties.put(TITLE, this.title); } @@ -628,7 +629,7 @@ public class SpringCodegen extends AbstractJavaCodegen List authMethods = (List) objs.get("authMethods"); if (authMethods != null) { for (CodegenSecurity authMethod : authMethods) { - authMethod.name = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(authMethod.name), true); + authMethod.name = camelize(sanitizeName(authMethod.name), true); } } } @@ -641,7 +642,7 @@ public class SpringCodegen extends AbstractJavaCodegen return "DefaultApi"; } name = sanitizeName(name); - return org.openapitools.codegen.utils.StringUtils.camelize(name) + "Api"; + return camelize(name) + "Api"; } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/StaticHtml2Generator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/StaticHtml2Generator.java index e220f906343..472dc81924e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/StaticHtml2Generator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/StaticHtml2Generator.java @@ -45,6 +45,9 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import static org.openapitools.codegen.utils.StringUtils.dashize; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(StaticHtml2Generator.class); @@ -162,7 +165,7 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi Info info = openAPI.getInfo(); if (StringUtils.isBlank(jsProjectName) && info.getTitle() != null) { // when jsProjectName is not specified, generate it from info.title - jsProjectName = sanitizeName(org.openapitools.codegen.utils.StringUtils.dashize(info.getTitle())); + jsProjectName = sanitizeName(dashize(info.getTitle())); } } @@ -171,7 +174,7 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi jsProjectName = "openapi-js-client"; } if (StringUtils.isBlank(jsModuleName)) { - jsModuleName = org.openapitools.codegen.utils.StringUtils.camelize(org.openapitools.codegen.utils.StringUtils.underscore(jsProjectName)); + jsModuleName = camelize(underscore(jsProjectName)); } additionalProperties.put("jsProjectName", jsProjectName); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift3Codegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift3Codegen.java index e4a90d91ae8..124598d37ee 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift3Codegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift3Codegen.java @@ -33,6 +33,7 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class Swift3Codegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(Swift3Codegen.class); @@ -389,7 +390,7 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig { // camelize the model name // phone_number => PhoneNumber - name = org.openapitools.codegen.utils.StringUtils.camelize(name); + name = camelize(name); // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { @@ -447,7 +448,7 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig { @Override public String toOperationId(String operationId) { - operationId = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true); + operationId = camelize(sanitizeName(operationId), true); // throw exception if method name is empty. This should not happen but keep the check just in case if (StringUtils.isEmpty(operationId)) { @@ -456,15 +457,15 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig { // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - String newOperationId = org.openapitools.codegen.utils.StringUtils.camelize(("call_" + operationId), true); + String newOperationId = camelize(("call_" + operationId), true); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId); return newOperationId; } // operationId starts with a number if (operationId.matches("^\\d.*")) { - LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId), true)); - operationId = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId), true); + LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true)); + operationId = camelize(sanitizeName("call_" + operationId), true); } return operationId; @@ -482,7 +483,7 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig { // camelize the variable name // pet_id => petId - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); // for reserved word or word starting with number, append _ if (isReservedWord(name) || name.matches("^\\d.*")) { @@ -505,9 +506,9 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig { return name; } - // org.openapitools.codegen.utils.StringUtils.camelize(lower) the variable name + // camelize(lower) the variable name // pet_id => petId - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); // for reserved word or word starting with number, append _ if (isReservedWord(name) || name.matches("^\\d.*")) { @@ -586,18 +587,18 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig { String startingNumbers = startWithNumberMatcher.group(0); String nameWithoutStartingNumbers = name.substring(startingNumbers.length()); - return "_" + startingNumbers + org.openapitools.codegen.utils.StringUtils.camelize(nameWithoutStartingNumbers, true); + return "_" + startingNumbers + camelize(nameWithoutStartingNumbers, true); } // for symbol, e.g. $, # if (getSymbolName(name) != null) { - return org.openapitools.codegen.utils.StringUtils.camelize(WordUtils.capitalizeFully(getSymbolName(name).toUpperCase(Locale.ROOT)), true); + return camelize(WordUtils.capitalizeFully(getSymbolName(name).toUpperCase(Locale.ROOT)), true); } // Camelize only when we have a structure defined below Boolean camelized = false; if (name.matches("[A-Z][a-z0-9]+[a-zA-Z0-9]*")) { - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); camelized = true; } @@ -610,7 +611,7 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig { // Check for numerical conversions if ("Int".equals(datatype) || "Int32".equals(datatype) || "Int64".equals(datatype) || "Float".equals(datatype) || "Double".equals(datatype)) { - String varName = "number" + org.openapitools.codegen.utils.StringUtils.camelize(name); + String varName = "number" + camelize(name); varName = varName.replaceAll("-", "minus"); varName = varName.replaceAll("\\+", "plus"); varName = varName.replaceAll("\\.", "dot"); @@ -624,7 +625,7 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig { } char[] separators = {'-', '_', ' ', ':', '(', ')'}; - return org.openapitools.codegen.utils.StringUtils.camelize(WordUtils.capitalizeFully(StringUtils.lowerCase(name), separators).replaceAll("[-_ :\\(\\)]", ""), true); + return camelize(WordUtils.capitalizeFully(StringUtils.lowerCase(name), separators).replaceAll("[-_ :\\(\\)]", ""), true); } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift4Codegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift4Codegen.java index ff69058cc95..b767a3ddbdb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift4Codegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift4Codegen.java @@ -33,6 +33,7 @@ import java.io.File; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class Swift4Codegen extends DefaultCodegen implements CodegenConfig { @@ -480,7 +481,7 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig { // camelize the model name // phone_number => PhoneNumber - name = org.openapitools.codegen.utils.StringUtils.camelize(name); + name = camelize(name); // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { @@ -556,7 +557,7 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig { @Override public String toOperationId(String operationId) { - operationId = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true); + operationId = camelize(sanitizeName(operationId), true); // Throw exception if method name is empty. // This should not happen but keep the check just in case @@ -566,7 +567,7 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig { // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - String newOperationId = org.openapitools.codegen.utils.StringUtils.camelize(("call_" + operationId), true); + String newOperationId = camelize(("call_" + operationId), true); LOGGER.warn(operationId + " (reserved word) cannot be used as method name." + " Renamed to " + newOperationId); return newOperationId; @@ -574,8 +575,8 @@ public class Swift4Codegen 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 name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId), true)); - operationId = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId), true); + LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true)); + operationId = camelize(sanitizeName("call_" + operationId), true); } @@ -594,7 +595,7 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig { // camelize the variable name // pet_id => petId - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); // for reserved word or word starting with number, append _ if (isReservedWord(name) || name.matches("^\\d.*")) { @@ -617,9 +618,9 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig { return name; } - // org.openapitools.codegen.utils.StringUtils.camelize(lower) the variable name + // camelize(lower) the variable name // pet_id => petId - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); // for reserved word or word starting with number, append _ if (isReservedWord(name) || name.matches("^\\d.*")) { @@ -705,18 +706,18 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig { String startingNumbers = startWithNumberMatcher.group(0); String nameWithoutStartingNumbers = name.substring(startingNumbers.length()); - return "_" + startingNumbers + org.openapitools.codegen.utils.StringUtils.camelize(nameWithoutStartingNumbers, true); + return "_" + startingNumbers + camelize(nameWithoutStartingNumbers, true); } // for symbol, e.g. $, # if (getSymbolName(name) != null) { - return org.openapitools.codegen.utils.StringUtils.camelize(WordUtils.capitalizeFully(getSymbolName(name).toUpperCase(Locale.ROOT)), true); + return camelize(WordUtils.capitalizeFully(getSymbolName(name).toUpperCase(Locale.ROOT)), true); } // Camelize only when we have a structure defined below Boolean camelized = false; if (name.matches("[A-Z][a-z0-9]+[a-zA-Z0-9]*")) { - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); camelized = true; } @@ -729,7 +730,7 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig { // Check for numerical conversions if ("Int".equals(datatype) || "Int32".equals(datatype) || "Int64".equals(datatype) || "Float".equals(datatype) || "Double".equals(datatype)) { - String varName = "number" + org.openapitools.codegen.utils.StringUtils.camelize(name); + String varName = "number" + camelize(name); varName = varName.replaceAll("-", "minus"); varName = varName.replaceAll("\\+", "plus"); varName = varName.replaceAll("\\.", "dot"); @@ -743,7 +744,7 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig { } char[] separators = {'-', '_', ' ', ':', '(', ')'}; - return org.openapitools.codegen.utils.StringUtils.camelize(WordUtils.capitalizeFully(StringUtils.lowerCase(name), separators) + return camelize(WordUtils.capitalizeFully(StringUtils.lowerCase(name), separators) .replaceAll("[-_ :\\(\\)]", ""), true); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SwiftClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SwiftClientCodegen.java index 775694c5e09..841214e2291 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SwiftClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SwiftClientCodegen.java @@ -34,6 +34,8 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; /** * Swift (2.x) generator is no longer actively maintained. Please use @@ -320,7 +322,7 @@ public class SwiftClientCodegen extends DefaultCodegen implements CodegenConfig // camelize the model name // phone_number => PhoneNumber - name = org.openapitools.codegen.utils.StringUtils.camelize(name); + name = camelize(name); // model name cannot use reserved keyword, e.g. return if (isReservedWord(name)) { @@ -437,7 +439,7 @@ public class SwiftClientCodegen extends DefaultCodegen implements CodegenConfig @Override public String toOperationId(String operationId) { - operationId = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId), true); + operationId = camelize(sanitizeName(operationId), true); // throw exception if method name is empty. This should not happen but keep the check just in case if (StringUtils.isEmpty(operationId)) { @@ -446,15 +448,15 @@ public class SwiftClientCodegen extends DefaultCodegen implements CodegenConfig // method name cannot use reserved keyword, e.g. return if (isReservedWord(operationId)) { - String newOperationId = org.openapitools.codegen.utils.StringUtils.camelize(("call_" + operationId), true); + String newOperationId = camelize(("call_" + operationId), true); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId); return newOperationId; } // operationId starts with a number if (operationId.matches("^\\d.*")) { - LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId), true)); - operationId = org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName("call_" + operationId), true); + LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true)); + operationId = camelize(sanitizeName("call_" + operationId), true); } return operationId; @@ -472,7 +474,7 @@ public class SwiftClientCodegen extends DefaultCodegen implements CodegenConfig // camelize the variable name // pet_id => petId - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); // for reserved word or word starting with number, append _ if (isReservedWord(name) || name.matches("^\\d.*")) { @@ -495,9 +497,9 @@ public class SwiftClientCodegen extends DefaultCodegen implements CodegenConfig return name; } - // org.openapitools.codegen.utils.StringUtils.camelize(lower) the variable name + // camelize(lower) the variable name // pet_id => petId - name = org.openapitools.codegen.utils.StringUtils.camelize(name, true); + name = camelize(name, true); // for reserved word or word starting with number, append _ if (isReservedWord(name) || name.matches("^\\d.*")) { @@ -525,7 +527,7 @@ public class SwiftClientCodegen extends DefaultCodegen implements CodegenConfig builder.append(stringBeforeMatch); String group = matcher.group().substring(1, matcher.group().length() - 1); - group = org.openapitools.codegen.utils.StringUtils.camelize(group, true); + group = camelize(group, true); builder .append("{") .append(group) @@ -584,7 +586,7 @@ public class SwiftClientCodegen extends DefaultCodegen implements CodegenConfig } // string - String enumName = sanitizeName(org.openapitools.codegen.utils.StringUtils.underscore(name).toUpperCase(Locale.ROOT)); + String enumName = sanitizeName(underscore(name).toUpperCase(Locale.ROOT)); enumName = enumName.replaceFirst("^_", ""); enumName = enumName.replaceFirst("_$", ""); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java index 623f5ab340f..c91f93e5ef9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java @@ -29,6 +29,9 @@ import java.io.File; import java.text.SimpleDateFormat; import java.util.*; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; +import static org.openapitools.codegen.utils.StringUtils.dashize; public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCodegen { private static final Logger LOGGER = LoggerFactory.getLogger(TypeScriptAngularClientCodegen.class); @@ -571,7 +574,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode if (modelFileSuffix.length() > 0) { name = name.substring(0, name.length() - modelFileSuffix.length()); } - return org.openapitools.codegen.utils.StringUtils.camelize(name) + modelSuffix; + return camelize(name) + modelSuffix; } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java index 9ca446c5a80..c078a29382f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java @@ -28,7 +28,7 @@ import java.io.File; import java.text.SimpleDateFormat; import java.util.*; - +import static org.openapitools.codegen.utils.StringUtils.camelize; public class TypeScriptInversifyClientCodegen extends AbstractTypeScriptClientCodegen { private static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm", Locale.ROOT); @@ -327,7 +327,7 @@ public class TypeScriptInversifyClientCodegen extends AbstractTypeScriptClientCo if (name.length() == 0) { return "default.service"; } - return org.openapitools.codegen.utils.StringUtils.camelize(name, true) + ".service"; + return camelize(name, true) + ".service"; } @Override @@ -337,7 +337,7 @@ public class TypeScriptInversifyClientCodegen extends AbstractTypeScriptClientCo @Override public String toModelFilename(String name) { - return org.openapitools.codegen.utils.StringUtils.camelize(toModelName(name), true); + return camelize(toModelName(name), true); } @Override @@ -376,7 +376,7 @@ public class TypeScriptInversifyClientCodegen extends AbstractTypeScriptClientCo private String getModelnameFromModelFilename(String filename) { String name = filename.substring((modelPackage() + "/").length()); - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java index 6021187cd04..f613fb495bb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java @@ -29,6 +29,7 @@ import java.io.File; import java.text.SimpleDateFormat; import java.util.*; +import static org.openapitools.codegen.utils.StringUtils.camelize; public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen { private static final Logger LOGGER = LoggerFactory.getLogger(TypeScriptNodeClientCodegen.class); @@ -107,7 +108,7 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen if (name.length() == 0) { return "default" + apiSuffix; } - return org.openapitools.codegen.utils.StringUtils.camelize(name, true) + apiSuffix; + return camelize(name, true) + apiSuffix; } @Override @@ -117,7 +118,7 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen @Override public String toModelFilename(String name) { - return org.openapitools.codegen.utils.StringUtils.camelize(toModelName(name), true); + return camelize(toModelName(name), true); } @Override @@ -296,6 +297,6 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen private String getModelnameFromModelFilename(String filename) { String name = filename.substring((modelPackage() + File.separator).length()); - return org.openapitools.codegen.utils.StringUtils.camelize(name); + return camelize(name); } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/mustache/CamelCaseLambda.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/mustache/CamelCaseLambda.java index f67b0e848a2..110302b1bb8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/mustache/CamelCaseLambda.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/mustache/CamelCaseLambda.java @@ -26,7 +26,6 @@ import java.io.Writer; import static org.openapitools.codegen.utils.StringUtils.camelize; - /** * Converts text in a fragment to camelCase. * From ced6e0502ec53031efa0a043924f7fe7e4b2691e Mon Sep 17 00:00:00 2001 From: Atsushi Hanaoka Date: Thu, 6 Dec 2018 18:10:45 +0900 Subject: [PATCH 2/2] [typescript] Avoid strictNullChecks errors for apiKeys (#1611) * [typescript] Avoid strictNullChecks errors for apiKeys fix #1607 * Run ./bin/{LANG}-petstore.sh - ./bin/typescript-angular-petstore-all.sh - ./bin/typescript-inversify-petstore.sh * Run ./bin/security/{LANG}-petstore.sh - ./bin/security/typescript-angular.sh - ./bin/security/typescript-angular2.sh - ./bin/security/typescript-inversify.sh * [typescript] Fix parameter name sanitization * Fix invalid consumes of petstore-security-test.yaml * Run ./bin/security/typescript-*.sh --- .../AbstractTypeScriptClientCodegen.java | 2 +- .../typescript-angular/api.service.mustache | 4 +- .../typescript-inversify/api.service.mustache | 4 +- .../TypeScriptNodeClientCodegenTest.java | 1 + .../resources/2_0/petstore-security-test.yaml | 3 +- .../.openapi-generator/VERSION | 2 +- .../typescript-angular/README.md | 23 +- .../typescript-angular/api.module.ts | 2 +- .../typescript-angular/api/fake.service.ts | 42 ++- .../typescript-angular/configuration.ts | 18 +- .../typescript-angular/git_push.sh | 2 +- .../typescript-angular/model/models.ts | 2 +- .../typescript-angular/model/return.ts | 22 ++ .../.openapi-generator/VERSION | 2 +- .../typescript-angular2/README.md | 23 +- .../typescript-angular2/api.module.ts | 2 +- .../typescript-angular2/api/fake.service.ts | 42 ++- .../typescript-angular2/configuration.ts | 18 +- .../typescript-angular2/git_push.sh | 2 +- .../typescript-angular2/model/models.ts | 2 +- .../typescript-angular2/model/return.ts | 22 ++ .../.openapi-generator/VERSION | 2 +- .../typescript-fetch/apis/FakeApi.ts | 56 ++++ .../typescript-fetch/apis/index.ts | 1 + .../typescript-fetch/index.ts | 19 +- .../typescript-fetch/models/Return.ts | 44 +++ .../typescript-fetch/models/index.ts | 1 + .../typescript-fetch/runtime.ts | 267 ++++++++++++++++++ .../typescript-fetch/tsconfig.json | 17 ++ .../.openapi-generator/VERSION | 2 +- .../typescript-inversify/api/fake.service.ts | 14 +- .../typescript-inversify/model/return.ts | 22 ++ .../.openapi-generator/VERSION | 2 +- .../typescript-node/api/fakeApi.ts | 13 +- .../typescript-node/model/models.ts | 8 +- .../typescript-node/model/return.ts | 36 +++ .../default/api/pet.service.ts | 2 +- .../default/api/store.service.ts | 2 +- .../npm/api/pet.service.ts | 2 +- .../npm/api/store.service.ts | 2 +- .../with-interfaces/api/pet.service.ts | 2 +- .../with-interfaces/api/store.service.ts | 2 +- .../npm/api/pet.service.ts | 2 +- .../npm/api/store.service.ts | 2 +- .../npm/api/pet.service.ts | 2 +- .../npm/api/store.service.ts | 2 +- .../builds/default/api/pet.service.ts | 2 +- .../builds/default/api/store.service.ts | 2 +- .../builds/with-npm/api/pet.service.ts | 2 +- .../builds/with-npm/api/store.service.ts | 2 +- .../builds/default/api/pet.service.ts | 2 +- .../builds/default/api/store.service.ts | 2 +- .../builds/with-npm/api/pet.service.ts | 2 +- .../builds/with-npm/api/store.service.ts | 2 +- .../typescript-inversify/api/pet.service.ts | 2 +- .../typescript-inversify/api/store.service.ts | 2 +- 56 files changed, 636 insertions(+), 148 deletions(-) create mode 100644 samples/client/petstore-security-test/typescript-angular/model/return.ts create mode 100644 samples/client/petstore-security-test/typescript-angular2/model/return.ts create mode 100644 samples/client/petstore-security-test/typescript-fetch/apis/FakeApi.ts create mode 100644 samples/client/petstore-security-test/typescript-fetch/apis/index.ts create mode 100644 samples/client/petstore-security-test/typescript-fetch/models/Return.ts create mode 100644 samples/client/petstore-security-test/typescript-fetch/models/index.ts create mode 100644 samples/client/petstore-security-test/typescript-fetch/runtime.ts create mode 100644 samples/client/petstore-security-test/typescript-fetch/tsconfig.json create mode 100644 samples/client/petstore-security-test/typescript-inversify/model/return.ts create mode 100644 samples/client/petstore-security-test/typescript-node/model/return.ts diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java index 6e178de0cc9..c6a81150c02 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java @@ -161,7 +161,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp @Override public String toParamName(String name) { // sanitize name - name = sanitizeName(name, "\\W-[\\$]"); + name = sanitizeName(name, "[^\\w$]"); if ("_".equals(name)) { name = "_u"; diff --git a/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache b/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache index 55a115fff30..aa403a86ecc 100644 --- a/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache @@ -192,13 +192,13 @@ export class {{classname}} { // authentication ({{name}}) required {{#isApiKey}} {{#isKeyInHeader}} - if (this.configuration.apiKeys["{{keyParamName}}"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["{{keyParamName}}"]) { {{#useHttpClient}}headers = {{/useHttpClient}}headers.set('{{keyParamName}}', this.configuration.apiKeys["{{keyParamName}}"]); } {{/isKeyInHeader}} {{#isKeyInQuery}} - if (this.configuration.apiKeys["{{keyParamName}}"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["{{keyParamName}}"]) { {{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.set('{{keyParamName}}', this.configuration.apiKeys["{{keyParamName}}"]); } diff --git a/modules/openapi-generator/src/main/resources/typescript-inversify/api.service.mustache b/modules/openapi-generator/src/main/resources/typescript-inversify/api.service.mustache index 25958375576..703a3d0573a 100644 --- a/modules/openapi-generator/src/main/resources/typescript-inversify/api.service.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-inversify/api.service.mustache @@ -106,12 +106,12 @@ export class {{classname}} { // authentication ({{name}}) required {{#isApiKey}} {{#isKeyInHeader}} - if (this.APIConfiguration.apiKeys["{{keyParamName}}"]) { + if (this.APIConfiguration.apiKeys && this.APIConfiguration.apiKeys["{{keyParamName}}"]) { headers['{{keyParamName}}'] = this.APIConfiguration.apiKeys["{{keyParamName}}"]; } {{/isKeyInHeader}} {{#isKeyInQuery}} - if (this.APIConfiguration.apiKeys["{{keyParamName}}"]) { + if (this.APIConfiguration.apiKeys && this.APIConfiguration.apiKeys["{{keyParamName}}"]) { queryParameters.push("{{paramName}}="+encodeURIComponent(String(this.APIConfiguration.apiKeys["{{keyParamName}}"]))); } {{/isKeyInQuery}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java index 5183502601f..908249e27fd 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/typescriptnode/TypeScriptNodeClientCodegenTest.java @@ -15,5 +15,6 @@ public class TypeScriptNodeClientCodegenTest { Assert.assertEquals(codegen.toVarName("user-name"), "userName"); Assert.assertEquals(codegen.toVarName("user_name"), "userName"); Assert.assertEquals(codegen.toVarName("user|name"), "userName"); + Assert.assertEquals(codegen.toVarName("user !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~name"), "user$Name"); } } diff --git a/modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml b/modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml index f1400ad8c63..1a9f63770fe 100644 --- a/modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml +++ b/modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml @@ -28,8 +28,7 @@ paths: description: To test code injection */ ' " =end -- \r\n \n \r operationId: testCodeInject */ ' " =end -- \r\n \n \r consumes: - - application/json - - "*/ ' \" =end -- \r\n \n \r" + - application/x-www-form-urlencoded produces: - application/json - "*/ ' \" =end -- \r\n \n \r" diff --git a/samples/client/petstore-security-test/typescript-angular/.openapi-generator/VERSION b/samples/client/petstore-security-test/typescript-angular/.openapi-generator/VERSION index 855ff9501eb..afa63656064 100644 --- a/samples/client/petstore-security-test/typescript-angular/.openapi-generator/VERSION +++ b/samples/client/petstore-security-test/typescript-angular/.openapi-generator/VERSION @@ -1 +1 @@ -2.4.0-SNAPSHOT \ No newline at end of file +4.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore-security-test/typescript-angular/README.md b/samples/client/petstore-security-test/typescript-angular/README.md index f679bcb1320..b6c812a56ef 100644 --- a/samples/client/petstore-security-test/typescript-angular/README.md +++ b/samples/client/petstore-security-test/typescript-angular/README.md @@ -2,7 +2,7 @@ ### Building -To build an compile the typescript sources to javascript use: +To install the required dependencies and to build the typescript sources run: ``` npm install npm run build @@ -10,11 +10,11 @@ npm run build ### publishing -First build the package than run ```npm publish``` +First build the package then run ```npm publish``` ### consuming -navigate to the folder of your consuming project and run one of next commando's. +Navigate to the folder of your consuming project and run one of next commands. _published:_ @@ -22,7 +22,7 @@ _published:_ npm install @ --save ``` -_unPublished (not recommended):_ +_without publishing (not recommended):_ ``` npm install PATH_TO_GENERATED_PACKAGE --save @@ -37,9 +37,16 @@ npm link In your project: ``` -npm link @ +npm link ``` +__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages. +Please refer to this issue https://github.com/angular/angular-cli/issues/8284 for a solution / workaround. +Published packages are not effected by this issue. + + +#### General usage + In your Angular project: @@ -94,8 +101,8 @@ export class AppComponent { Note: The ApiModule is restricted to being instantiated once app wide. This is to ensure that all services are treated as singletons. -#### Using multiple swagger files / APIs / ApiModules -In order to use multiple `ApiModules` generated from different swagger files, +#### Using multiple OpenAPI files / APIs / ApiModules +In order to use multiple `ApiModules` generated from different OpenAPI files, you can create an alias name when importing the modules in order to avoid naming conflicts: ``` @@ -168,4 +175,4 @@ import { environment } from '../environments/environment'; bootstrap: [ AppComponent ] }) export class AppModule { } -``` \ No newline at end of file +``` diff --git a/samples/client/petstore-security-test/typescript-angular/api.module.ts b/samples/client/petstore-security-test/typescript-angular/api.module.ts index a95cda25231..867cee5c7b2 100644 --- a/samples/client/petstore-security-test/typescript-angular/api.module.ts +++ b/samples/client/petstore-security-test/typescript-angular/api.module.ts @@ -17,7 +17,7 @@ export class ApiModule { return { ngModule: ApiModule, providers: [ { provide: Configuration, useFactory: configurationFactory } ] - } + }; } constructor( @Optional() @SkipSelf() parentModule: ApiModule, diff --git a/samples/client/petstore-security-test/typescript-angular/api/fake.service.ts b/samples/client/petstore-security-test/typescript-angular/api/fake.service.ts index d0047d78bee..8f290b5e08b 100644 --- a/samples/client/petstore-security-test/typescript-angular/api/fake.service.ts +++ b/samples/client/petstore-security-test/typescript-angular/api/fake.service.ts @@ -1,12 +1,12 @@ /** - * Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r + * OpenAPI Petstore *_/ ' \" =end -- \\r\\n \\n \\r * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- * * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r - * Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r + * Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech * Do not edit the class manually. */ /* tslint:disable:no-unused-variable member-ordering */ @@ -26,17 +26,18 @@ import { Configuration } from '../configurat @Injectable() export class FakeService { - protected basePath = 'https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'; + protected basePath = 'http://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { - if (basePath) { - this.basePath = basePath; - } + if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.configuration.basePath = configuration.basePath || basePath || this.basePath; + + } else { + this.configuration.basePath = basePath || this.basePath; } } @@ -46,7 +47,7 @@ export class FakeService { */ private canConsumeForm(consumes: string[]): boolean { const form = 'multipart/form-data'; - for (let consume of consumes) { + for (const consume of consumes) { if (form === consume) { return true; } @@ -57,8 +58,8 @@ export class FakeService { /** * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r - * - * @param testCodeInjectEndRnNR To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * @param testCodeInjectEndRnNR To test code injection *_/ ' \\\" =end -- \\\\r\\\\n \\\\n \\\\r * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ @@ -71,23 +72,20 @@ export class FakeService { // to determine the Accept header let httpHeaderAccepts: string[] = [ - 'application/json', - '*_/ =end -- ' ]; - let httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); - if (httpHeaderAcceptSelected != undefined) { - headers = headers.set("Accept", httpHeaderAcceptSelected); + const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); + if (httpHeaderAcceptSelected !== undefined) { + headers = headers.set('Accept', httpHeaderAcceptSelected); } // to determine the Content-Type header - let consumes: string[] = [ - 'application/json', - '*_/ =end -- ' + const consumes: string[] = [ + 'application/x-www-form-urlencoded' ]; const canConsumeForm = this.canConsumeForm(consumes); - let formParams: { append(param: string, value: any): void; }; + let formParams: { append(param: string, value: any): any; }; let useForm = false; let convertFormParamsToString = false; if (useForm) { @@ -100,7 +98,7 @@ export class FakeService { formParams = formParams.append('test code inject */ ' " =end -- \r\n \n \r', testCodeInjectEndRnNR) || formParams; } - return this.httpClient.put(`${this.basePath}/fake`, + return this.httpClient.put(`${this.configuration.basePath}/fake`, convertFormParamsToString ? formParams.toString() : formParams, { withCredentials: this.configuration.withCredentials, diff --git a/samples/client/petstore-security-test/typescript-angular/configuration.ts b/samples/client/petstore-security-test/typescript-angular/configuration.ts index 2ee1824f5f7..5dac1323937 100644 --- a/samples/client/petstore-security-test/typescript-angular/configuration.ts +++ b/samples/client/petstore-security-test/typescript-angular/configuration.ts @@ -28,11 +28,11 @@ export class Configuration { * Select the correct content-type to use for a request. * Uses {@link Configuration#isJsonMime} to determine the correct content-type. * If no content type is found return the first found type if the contentTypes is not empty - * @param {string[]} contentTypes - the array of content types that are available for selection - * @returns {string} the selected content-type or undefined if no selection could be made. + * @param contentTypes - the array of content types that are available for selection + * @returns the selected content-type or undefined if no selection could be made. */ public selectHeaderContentType (contentTypes: string[]): string | undefined { - if (contentTypes.length == 0) { + if (contentTypes.length === 0) { return undefined; } @@ -47,11 +47,11 @@ export class Configuration { * Select the correct accept content-type to use for a request. * Uses {@link Configuration#isJsonMime} to determine the correct accept content-type. * If no content type is found return the first found type if the contentTypes is not empty - * @param {string[]} accepts - the array of content types that are available for selection. - * @returns {string} the selected content-type or undefined if no selection could be made. + * @param accepts - the array of content types that are available for selection. + * @returns the selected content-type or undefined if no selection could be made. */ public selectHeaderAccept(accepts: string[]): string | undefined { - if (accepts.length == 0) { + if (accepts.length === 0) { return undefined; } @@ -69,11 +69,11 @@ export class Configuration { * application/json; charset=UTF8 * APPLICATION/JSON * application/vnd.company+json - * @param {string} mime - MIME (Multipurpose Internet Mail Extensions) - * @return {boolean} True if the given MIME is JSON, false otherwise. + * @param mime - MIME (Multipurpose Internet Mail Extensions) + * @return True if the given MIME is JSON, false otherwise. */ public isJsonMime(mime: string): boolean { const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); + return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); } } diff --git a/samples/client/petstore-security-test/typescript-angular/git_push.sh b/samples/client/petstore-security-test/typescript-angular/git_push.sh index ae01b182ae9..8442b80bb44 100644 --- a/samples/client/petstore-security-test/typescript-angular/git_push.sh +++ b/samples/client/petstore-security-test/typescript-angular/git_push.sh @@ -1,7 +1,7 @@ #!/bin/sh # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ # -# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update" +# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" git_user_id=$1 git_repo_id=$2 diff --git a/samples/client/petstore-security-test/typescript-angular/model/models.ts b/samples/client/petstore-security-test/typescript-angular/model/models.ts index bca4c78d6b0..472428482c7 100644 --- a/samples/client/petstore-security-test/typescript-angular/model/models.ts +++ b/samples/client/petstore-security-test/typescript-angular/model/models.ts @@ -1 +1 @@ -export * from './modelReturn'; +export * from './return'; diff --git a/samples/client/petstore-security-test/typescript-angular/model/return.ts b/samples/client/petstore-security-test/typescript-angular/model/return.ts new file mode 100644 index 00000000000..442d1b5a101 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-angular/model/return.ts @@ -0,0 +1,22 @@ +/** + * OpenAPI Petstore *_/ ' \" =end -- \\r\\n \\n \\r + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- + * + * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r + * Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +/** + * Model for testing reserved words *_/ ' \" =end -- \\r\\n \\n \\r + */ +export interface Return { + /** + * property description *_/ ' \" =end -- \\r\\n \\n \\r + */ + _return?: number; +} diff --git a/samples/client/petstore-security-test/typescript-angular2/.openapi-generator/VERSION b/samples/client/petstore-security-test/typescript-angular2/.openapi-generator/VERSION index 855ff9501eb..afa63656064 100644 --- a/samples/client/petstore-security-test/typescript-angular2/.openapi-generator/VERSION +++ b/samples/client/petstore-security-test/typescript-angular2/.openapi-generator/VERSION @@ -1 +1 @@ -2.4.0-SNAPSHOT \ No newline at end of file +4.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore-security-test/typescript-angular2/README.md b/samples/client/petstore-security-test/typescript-angular2/README.md index f679bcb1320..b6c812a56ef 100644 --- a/samples/client/petstore-security-test/typescript-angular2/README.md +++ b/samples/client/petstore-security-test/typescript-angular2/README.md @@ -2,7 +2,7 @@ ### Building -To build an compile the typescript sources to javascript use: +To install the required dependencies and to build the typescript sources run: ``` npm install npm run build @@ -10,11 +10,11 @@ npm run build ### publishing -First build the package than run ```npm publish``` +First build the package then run ```npm publish``` ### consuming -navigate to the folder of your consuming project and run one of next commando's. +Navigate to the folder of your consuming project and run one of next commands. _published:_ @@ -22,7 +22,7 @@ _published:_ npm install @ --save ``` -_unPublished (not recommended):_ +_without publishing (not recommended):_ ``` npm install PATH_TO_GENERATED_PACKAGE --save @@ -37,9 +37,16 @@ npm link In your project: ``` -npm link @ +npm link ``` +__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages. +Please refer to this issue https://github.com/angular/angular-cli/issues/8284 for a solution / workaround. +Published packages are not effected by this issue. + + +#### General usage + In your Angular project: @@ -94,8 +101,8 @@ export class AppComponent { Note: The ApiModule is restricted to being instantiated once app wide. This is to ensure that all services are treated as singletons. -#### Using multiple swagger files / APIs / ApiModules -In order to use multiple `ApiModules` generated from different swagger files, +#### Using multiple OpenAPI files / APIs / ApiModules +In order to use multiple `ApiModules` generated from different OpenAPI files, you can create an alias name when importing the modules in order to avoid naming conflicts: ``` @@ -168,4 +175,4 @@ import { environment } from '../environments/environment'; bootstrap: [ AppComponent ] }) export class AppModule { } -``` \ No newline at end of file +``` diff --git a/samples/client/petstore-security-test/typescript-angular2/api.module.ts b/samples/client/petstore-security-test/typescript-angular2/api.module.ts index a95cda25231..867cee5c7b2 100644 --- a/samples/client/petstore-security-test/typescript-angular2/api.module.ts +++ b/samples/client/petstore-security-test/typescript-angular2/api.module.ts @@ -17,7 +17,7 @@ export class ApiModule { return { ngModule: ApiModule, providers: [ { provide: Configuration, useFactory: configurationFactory } ] - } + }; } constructor( @Optional() @SkipSelf() parentModule: ApiModule, diff --git a/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts b/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts index d0047d78bee..8f290b5e08b 100644 --- a/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts +++ b/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts @@ -1,12 +1,12 @@ /** - * Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r + * OpenAPI Petstore *_/ ' \" =end -- \\r\\n \\n \\r * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- * * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r - * Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r + * Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech * Do not edit the class manually. */ /* tslint:disable:no-unused-variable member-ordering */ @@ -26,17 +26,18 @@ import { Configuration } from '../configurat @Injectable() export class FakeService { - protected basePath = 'https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'; + protected basePath = 'http://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'; public defaultHeaders = new HttpHeaders(); public configuration = new Configuration(); constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { - if (basePath) { - this.basePath = basePath; - } + if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.configuration.basePath = configuration.basePath || basePath || this.basePath; + + } else { + this.configuration.basePath = basePath || this.basePath; } } @@ -46,7 +47,7 @@ export class FakeService { */ private canConsumeForm(consumes: string[]): boolean { const form = 'multipart/form-data'; - for (let consume of consumes) { + for (const consume of consumes) { if (form === consume) { return true; } @@ -57,8 +58,8 @@ export class FakeService { /** * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r - * - * @param testCodeInjectEndRnNR To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * @param testCodeInjectEndRnNR To test code injection *_/ ' \\\" =end -- \\\\r\\\\n \\\\n \\\\r * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ @@ -71,23 +72,20 @@ export class FakeService { // to determine the Accept header let httpHeaderAccepts: string[] = [ - 'application/json', - '*_/ =end -- ' ]; - let httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); - if (httpHeaderAcceptSelected != undefined) { - headers = headers.set("Accept", httpHeaderAcceptSelected); + const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts); + if (httpHeaderAcceptSelected !== undefined) { + headers = headers.set('Accept', httpHeaderAcceptSelected); } // to determine the Content-Type header - let consumes: string[] = [ - 'application/json', - '*_/ =end -- ' + const consumes: string[] = [ + 'application/x-www-form-urlencoded' ]; const canConsumeForm = this.canConsumeForm(consumes); - let formParams: { append(param: string, value: any): void; }; + let formParams: { append(param: string, value: any): any; }; let useForm = false; let convertFormParamsToString = false; if (useForm) { @@ -100,7 +98,7 @@ export class FakeService { formParams = formParams.append('test code inject */ ' " =end -- \r\n \n \r', testCodeInjectEndRnNR) || formParams; } - return this.httpClient.put(`${this.basePath}/fake`, + return this.httpClient.put(`${this.configuration.basePath}/fake`, convertFormParamsToString ? formParams.toString() : formParams, { withCredentials: this.configuration.withCredentials, diff --git a/samples/client/petstore-security-test/typescript-angular2/configuration.ts b/samples/client/petstore-security-test/typescript-angular2/configuration.ts index 2ee1824f5f7..5dac1323937 100644 --- a/samples/client/petstore-security-test/typescript-angular2/configuration.ts +++ b/samples/client/petstore-security-test/typescript-angular2/configuration.ts @@ -28,11 +28,11 @@ export class Configuration { * Select the correct content-type to use for a request. * Uses {@link Configuration#isJsonMime} to determine the correct content-type. * If no content type is found return the first found type if the contentTypes is not empty - * @param {string[]} contentTypes - the array of content types that are available for selection - * @returns {string} the selected content-type or undefined if no selection could be made. + * @param contentTypes - the array of content types that are available for selection + * @returns the selected content-type or undefined if no selection could be made. */ public selectHeaderContentType (contentTypes: string[]): string | undefined { - if (contentTypes.length == 0) { + if (contentTypes.length === 0) { return undefined; } @@ -47,11 +47,11 @@ export class Configuration { * Select the correct accept content-type to use for a request. * Uses {@link Configuration#isJsonMime} to determine the correct accept content-type. * If no content type is found return the first found type if the contentTypes is not empty - * @param {string[]} accepts - the array of content types that are available for selection. - * @returns {string} the selected content-type or undefined if no selection could be made. + * @param accepts - the array of content types that are available for selection. + * @returns the selected content-type or undefined if no selection could be made. */ public selectHeaderAccept(accepts: string[]): string | undefined { - if (accepts.length == 0) { + if (accepts.length === 0) { return undefined; } @@ -69,11 +69,11 @@ export class Configuration { * application/json; charset=UTF8 * APPLICATION/JSON * application/vnd.company+json - * @param {string} mime - MIME (Multipurpose Internet Mail Extensions) - * @return {boolean} True if the given MIME is JSON, false otherwise. + * @param mime - MIME (Multipurpose Internet Mail Extensions) + * @return True if the given MIME is JSON, false otherwise. */ public isJsonMime(mime: string): boolean { const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); + return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); } } diff --git a/samples/client/petstore-security-test/typescript-angular2/git_push.sh b/samples/client/petstore-security-test/typescript-angular2/git_push.sh index ae01b182ae9..8442b80bb44 100644 --- a/samples/client/petstore-security-test/typescript-angular2/git_push.sh +++ b/samples/client/petstore-security-test/typescript-angular2/git_push.sh @@ -1,7 +1,7 @@ #!/bin/sh # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ # -# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update" +# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" git_user_id=$1 git_repo_id=$2 diff --git a/samples/client/petstore-security-test/typescript-angular2/model/models.ts b/samples/client/petstore-security-test/typescript-angular2/model/models.ts index bca4c78d6b0..472428482c7 100644 --- a/samples/client/petstore-security-test/typescript-angular2/model/models.ts +++ b/samples/client/petstore-security-test/typescript-angular2/model/models.ts @@ -1 +1 @@ -export * from './modelReturn'; +export * from './return'; diff --git a/samples/client/petstore-security-test/typescript-angular2/model/return.ts b/samples/client/petstore-security-test/typescript-angular2/model/return.ts new file mode 100644 index 00000000000..442d1b5a101 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-angular2/model/return.ts @@ -0,0 +1,22 @@ +/** + * OpenAPI Petstore *_/ ' \" =end -- \\r\\n \\n \\r + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- + * + * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r + * Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +/** + * Model for testing reserved words *_/ ' \" =end -- \\r\\n \\n \\r + */ +export interface Return { + /** + * property description *_/ ' \" =end -- \\r\\n \\n \\r + */ + _return?: number; +} diff --git a/samples/client/petstore-security-test/typescript-fetch/.openapi-generator/VERSION b/samples/client/petstore-security-test/typescript-fetch/.openapi-generator/VERSION index 0f58aa04141..afa63656064 100644 --- a/samples/client/petstore-security-test/typescript-fetch/.openapi-generator/VERSION +++ b/samples/client/petstore-security-test/typescript-fetch/.openapi-generator/VERSION @@ -1 +1 @@ -3.1.2-SNAPSHOT \ No newline at end of file +4.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore-security-test/typescript-fetch/apis/FakeApi.ts b/samples/client/petstore-security-test/typescript-fetch/apis/FakeApi.ts new file mode 100644 index 00000000000..9e35a8e6dd2 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-fetch/apis/FakeApi.ts @@ -0,0 +1,56 @@ +// tslint:disable +/** + * OpenAPI Petstore *_/ ' \" =end -- \\r\\n \\n \\r + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- + * + * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r + * Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import * as runtime from '../runtime'; + +export interface TestCodeInjectEndRnNRRequest { + testCodeInjectEndRnNR?: string; +} + +/** + * no description + */ +export class FakeApi extends runtime.BaseAPI { + + /** + * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + */ + async testCodeInjectEndRnNRRaw(requestParameters: TestCodeInjectEndRnNRRequest): Promise> { + const headerParameters: runtime.HTTPHeaders = {}; + + const formData = new FormData(); + if (requestParameters.testCodeInjectEndRnNR !== undefined) { + formData.append('test code inject */ ' " =end -- \r\n \n \r', requestParameters.testCodeInjectEndRnNR as any); + } + + const response = await this.request({ + path: `/fake`, + method: 'PUT', + headers: headerParameters, + body: formData, + }); + + return new runtime.VoidApiResponse(response); + } + + /** + * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + */ + async testCodeInjectEndRnNR(requestParameters: TestCodeInjectEndRnNRRequest): Promise { + await this.testCodeInjectEndRnNRRaw(requestParameters); + } + +} diff --git a/samples/client/petstore-security-test/typescript-fetch/apis/index.ts b/samples/client/petstore-security-test/typescript-fetch/apis/index.ts new file mode 100644 index 00000000000..9525ab85127 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-fetch/apis/index.ts @@ -0,0 +1 @@ +export * from './FakeApi'; diff --git a/samples/client/petstore-security-test/typescript-fetch/index.ts b/samples/client/petstore-security-test/typescript-fetch/index.ts index 06529df41e4..848ecfa4d10 100644 --- a/samples/client/petstore-security-test/typescript-fetch/index.ts +++ b/samples/client/petstore-security-test/typescript-fetch/index.ts @@ -1,16 +1,3 @@ -// tslint:disable -/** - * OpenAPI Petstore *_/ ' \" =end -- \\r\\n \\n \\r - * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- - * - * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r - * Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -export * from "./api"; -export * from "./configuration"; +export * from './runtime'; +export * from './apis'; +export * from './models'; diff --git a/samples/client/petstore-security-test/typescript-fetch/models/Return.ts b/samples/client/petstore-security-test/typescript-fetch/models/Return.ts new file mode 100644 index 00000000000..2c7c5bde635 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-fetch/models/Return.ts @@ -0,0 +1,44 @@ +// tslint:disable +/** + * OpenAPI Petstore *_/ ' \" =end -- \\r\\n \\n \\r + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- + * + * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r + * Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { exists } from '../runtime'; +/** + * Model for testing reserved words *_/ ' \" =end -- \\r\\n \\n \\r + * @export + * @interface Return + */ +export interface Return { + /** + * property description *_/ ' \" =end -- \\r\\n \\n \\r + * @type {number} + * @memberof Return + */ + _return?: number; +} + +export function ReturnFromJSON(json: any): Return { + return { + '_return': !exists(json, 'return') ? undefined : json['return'], + }; +} + +export function ReturnToJSON(value?: Return): any { + if (value === undefined) { + return undefined; + } + return { + 'return': value._return, + }; +} + + diff --git a/samples/client/petstore-security-test/typescript-fetch/models/index.ts b/samples/client/petstore-security-test/typescript-fetch/models/index.ts new file mode 100644 index 00000000000..8d45f62a1d6 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-fetch/models/index.ts @@ -0,0 +1 @@ +export * from './Return'; diff --git a/samples/client/petstore-security-test/typescript-fetch/runtime.ts b/samples/client/petstore-security-test/typescript-fetch/runtime.ts new file mode 100644 index 00000000000..95664acaf56 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-fetch/runtime.ts @@ -0,0 +1,267 @@ +// tslint:disable +/** + * OpenAPI Petstore *_/ ' \" =end -- \\r\\n \\n \\r + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- + * + * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r + * Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export const BASE_PATH = "http://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r".replace(/\/+$/, ""); + +/** + * This is the base class for all generated API classes. + */ +export class BaseAPI { + + private middleware: Middleware[]; + + constructor(protected configuration = new Configuration()) { + this.middleware = configuration.middleware; + } + + withMiddleware(this: T, ...middlewares: Middleware[]) { + const next = this.clone(); + next.middleware = next.middleware.concat(...middlewares); + return next; + } + + withPreMiddleware(this: T, ...preMiddlewares: Array) { + const middlewares = preMiddlewares.map((pre) => ({ pre })); + return this.withMiddleware(...middlewares); + } + + withPostMiddleware(this: T, ...postMiddlewares: Array) { + const middlewares = postMiddlewares.map((post) => ({ post })); + return this.withMiddleware(...middlewares); + } + + protected async request(context: RequestOpts): Promise { + const { url, init } = this.createFetchParams(context); + const response = await this.fetchApi(url, init); + if (response.status >= 200 && response.status < 300) { + return response; + } + throw response; + } + + private createFetchParams(context: RequestOpts) { + let url = this.configuration.basePath + context.path; + if (context.query !== undefined && Object.keys(context.query).length !== 0) { + // only add the querystring to the URL if there are query parameters. + // this is done to avoid urls ending with a "?" character which buggy webservers + // do not handle correctly sometimes. + url += '?' + querystring(context.query); + } + const body = context.body instanceof FormData ? context.body : JSON.stringify(context.body); + const init = { + method: context.method, + headers: context.headers, + body, + }; + return { url, init }; + } + + private fetchApi = async (url: string, init: RequestInit) => { + let fetchParams = { url, init }; + for (const middleware of this.middleware) { + if (middleware.pre) { + fetchParams = await middleware.pre({ + fetch: this.fetchApi, + ...fetchParams, + }) || fetchParams; + } + } + let response = await this.configuration.fetchApi(fetchParams.url, fetchParams.init); + for (const middleware of this.middleware) { + if (middleware.post) { + response = await middleware.post({ + fetch: this.fetchApi, + url, + init, + response: response.clone(), + }) || response; + } + } + return response; + } + + /** + * Create a shallow clone of `this` by constructing a new instance + * and then shallow cloning data members. + */ + private clone(this: T): T { + const constructor = this.constructor as any; + const next = new constructor(this.configuration); + next.middleware = this.middleware.slice(); + return next; + } +}; + +export class RequiredError extends Error { + name: "RequiredError" = "RequiredError"; + constructor(public field: string, msg?: string) { + super(msg); + } +} + +export const COLLECTION_FORMATS = { + csv: ",", + ssv: " ", + tsv: "\t", + pipes: "|", +}; + +export type FetchAPI = GlobalFetch['fetch']; + +export interface ConfigurationParameters { + basePath?: string; // override base path + fetchApi?: FetchAPI; // override for fetch implementation + middleware?: Middleware[]; // middleware to apply before/after fetch requests + username?: string; // parameter for basic security + password?: string; // parameter for basic security + apiKey?: string | ((name: string) => string); // parameter for apiKey security + accessToken?: string | ((name: string, scopes?: string[]) => string); // parameter for oauth2 security +} + +export class Configuration { + constructor(private configuration: ConfigurationParameters = {}) {} + + get basePath(): string { + return this.configuration.basePath || BASE_PATH; + } + + get fetchApi(): FetchAPI { + return this.configuration.fetchApi || window.fetch.bind(window); + } + + get middleware(): Middleware[] { + return this.configuration.middleware || []; + } + + get username(): string | undefined { + return this.configuration.username; + } + + get password(): string | undefined { + return this.configuration.password; + } + + get apiKey(): ((name: string) => string) | undefined { + const apiKey = this.configuration.apiKey; + if (apiKey) { + return typeof apiKey === 'function' ? apiKey : () => apiKey; + } + return undefined; + } + + get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { + const accessToken = this.configuration.accessToken; + if (accessToken) { + return typeof accessToken === 'function' ? accessToken : () => accessToken; + } + return undefined; + } +} + +export type Json = any; +export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'; +export type HTTPHeaders = { [key: string]: string }; +export type HTTPQuery = { [key: string]: string | number | null | boolean | Array }; +export type HTTPBody = Json | FormData; +export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original'; + +export interface FetchParams { + url: string; + init: RequestInit; +} + +export interface RequestOpts { + path: string; + method: HTTPMethod; + headers: HTTPHeaders; + query?: HTTPQuery; + body?: HTTPBody; +} + +export function exists(json: any, key: string) { + const value = json[key]; + return value !== null && value !== undefined; +} + +export function querystring(params: HTTPQuery) { + return Object.keys(params) + .map((key) => { + const value = params[key]; + if (value instanceof Array) { + const multiValue = value.join(`&${encodeURIComponent(key)}=`); + return `${encodeURIComponent(key)}=${multiValue}`; + } + return `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}` + }) + .join('&'); +} + +export interface RequestContext { + fetch: FetchAPI; + url: string; + init: RequestInit; +} + +export interface ResponseContext { + fetch: FetchAPI; + url: string; + init: RequestInit; + response: Response; +} + +export interface Middleware { + pre?(context: RequestContext): Promise; + post?(context: ResponseContext): Promise; +} + +export interface ApiResponse { + raw: Response; + value(): Promise; +} + +export interface ResponseTransformer { + (json: any): T; +} + +export class JSONApiResponse { + constructor(public raw: Response, private transformer: ResponseTransformer = (jsonValue: any) => jsonValue) {} + + async value() { + return this.transformer(await this.raw.json()); + } +} + +export class VoidApiResponse { + constructor(public raw: Response) {} + + async value() { + return undefined; + } +} + +export class BlobApiResponse { + constructor(public raw: Response) {} + + async value() { + return await this.raw.blob(); + }; +} + +export class TextApiResponse { + constructor(public raw: Response) {} + + async value() { + return await this.raw.text(); + }; +} diff --git a/samples/client/petstore-security-test/typescript-fetch/tsconfig.json b/samples/client/petstore-security-test/typescript-fetch/tsconfig.json new file mode 100644 index 00000000000..5a7e3c19352 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-fetch/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "declaration": true, + "target": "es5", + "module": "commonjs", + "outDir": "dist", + "rootDir": ".", + "lib": [ + "es6", + "dom" + ] + }, + "exclude": [ + "dist", + "node_modules" + ] +} diff --git a/samples/client/petstore-security-test/typescript-inversify/.openapi-generator/VERSION b/samples/client/petstore-security-test/typescript-inversify/.openapi-generator/VERSION index 855ff9501eb..afa63656064 100644 --- a/samples/client/petstore-security-test/typescript-inversify/.openapi-generator/VERSION +++ b/samples/client/petstore-security-test/typescript-inversify/.openapi-generator/VERSION @@ -1 +1 @@ -2.4.0-SNAPSHOT \ No newline at end of file +4.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore-security-test/typescript-inversify/api/fake.service.ts b/samples/client/petstore-security-test/typescript-inversify/api/fake.service.ts index 418d247b156..f3bf6b579e4 100644 --- a/samples/client/petstore-security-test/typescript-inversify/api/fake.service.ts +++ b/samples/client/petstore-security-test/typescript-inversify/api/fake.service.ts @@ -1,12 +1,12 @@ /** - * Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r + * OpenAPI Petstore *_/ ' \" =end -- \\r\\n \\n \\r * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- * * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r - * Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r + * Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r * - * NOTE: This class is auto generated by the swagger code generator program. - * https://github.com/swagger-api/swagger-codegen.git + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech * Do not edit the class manually. */ /* tslint:disable:no-unused-variable member-ordering */ @@ -27,7 +27,7 @@ import { COLLECTION_FORMATS } from '../variables'; @injectable() export class FakeService { - private basePath: string = 'https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'; + private basePath: string = 'http://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'; constructor(@inject("IApiHttpClient") private httpClient: IHttpClient, @inject("IAPIConfiguration") private APIConfiguration: IAPIConfiguration ) { @@ -37,8 +37,8 @@ export class FakeService { /** * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r - * - * @param testCodeInjectEndRnNR To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r + * @param testCodeInjectEndRnNR To test code injection *_/ ' \\\" =end -- \\\\r\\\\n \\\\n \\\\r */ public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe?: 'body', headers?: Headers): Observable; diff --git a/samples/client/petstore-security-test/typescript-inversify/model/return.ts b/samples/client/petstore-security-test/typescript-inversify/model/return.ts new file mode 100644 index 00000000000..442d1b5a101 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-inversify/model/return.ts @@ -0,0 +1,22 @@ +/** + * OpenAPI Petstore *_/ ' \" =end -- \\r\\n \\n \\r + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- + * + * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r + * Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +/** + * Model for testing reserved words *_/ ' \" =end -- \\r\\n \\n \\r + */ +export interface Return { + /** + * property description *_/ ' \" =end -- \\r\\n \\n \\r + */ + _return?: number; +} diff --git a/samples/client/petstore-security-test/typescript-node/.openapi-generator/VERSION b/samples/client/petstore-security-test/typescript-node/.openapi-generator/VERSION index 82602aa4190..afa63656064 100644 --- a/samples/client/petstore-security-test/typescript-node/.openapi-generator/VERSION +++ b/samples/client/petstore-security-test/typescript-node/.openapi-generator/VERSION @@ -1 +1 @@ -3.0.3-SNAPSHOT \ No newline at end of file +4.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore-security-test/typescript-node/api/fakeApi.ts b/samples/client/petstore-security-test/typescript-node/api/fakeApi.ts index e40f35702d4..ce68adb739b 100644 --- a/samples/client/petstore-security-test/typescript-node/api/fakeApi.ts +++ b/samples/client/petstore-security-test/typescript-node/api/fakeApi.ts @@ -18,7 +18,7 @@ import Promise = require('bluebird'); import { ObjectSerializer, Authentication, HttpBasicAuth, ApiKeyAuth, OAuth, VoidAuth } from '../model/models'; -let defaultBasePath = 'petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'; +let defaultBasePath = 'http://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'; // =============================================== // This file is autogenerated - Please do not edit @@ -70,11 +70,11 @@ export class FakeApi { } /** - * + * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r * @summary To test code injection *_/ ' \" =end -- \\r\\n \\n \\r - * @param UNKNOWN_BASE_TYPE + * @param testCodeInjectEndRnNR To test code injection *_/ ' \\\" =end -- \\\\r\\\\n \\\\n \\\\r */ - public testCodeInjectEndRnNR (UNKNOWN_BASE_TYPE?: any) : Promise<{ response: http.ClientResponse; body?: any; }> { + public testCodeInjectEndRnNR (testCodeInjectEndRnNR?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { const localVarPath = this.basePath + '/fake'; let localVarQueryParameters: any = {}; let localVarHeaderParams: any = (Object).assign({}, this.defaultHeaders); @@ -83,6 +83,10 @@ export class FakeApi { let localVarUseFormData = false; + if (testCodeInjectEndRnNR !== undefined) { + localVarFormParams['test code inject */ ' " =end -- \r\n \n \r'] = ObjectSerializer.serialize(testCodeInjectEndRnNR, "string"); + } + let localVarRequestOptions: localVarRequest.Options = { method: 'PUT', qs: localVarQueryParameters, @@ -90,7 +94,6 @@ export class FakeApi { uri: localVarPath, useQuerystring: this._useQuerystring, json: true, - body: ObjectSerializer.serialize(UNKNOWN_BASE_TYPE, "any") }; this.authentications.default.applyToRequest(localVarRequestOptions); diff --git a/samples/client/petstore-security-test/typescript-node/model/models.ts b/samples/client/petstore-security-test/typescript-node/model/models.ts index 37288a0f189..b278ea07e6f 100644 --- a/samples/client/petstore-security-test/typescript-node/model/models.ts +++ b/samples/client/petstore-security-test/typescript-node/model/models.ts @@ -1,8 +1,8 @@ -export * from './modelReturn'; +export * from './return'; import localVarRequest = require('request'); -import { ModelReturn } from './modelReturn'; +import { Return } from './return'; /* tslint:disable:no-unused-variable */ let primitives = [ @@ -20,7 +20,7 @@ let enumsMap: {[index: string]: any} = { } let typeMap: {[index: string]: any} = { - "ModelReturn": ModelReturn, + "Return": Return, } export class ObjectSerializer { @@ -74,7 +74,7 @@ export class ObjectSerializer { } return transformedData; } else if (type === "Date") { - return data.toString(); + return data.toISOString(); } else { if (enumsMap[type]) { return data; diff --git a/samples/client/petstore-security-test/typescript-node/model/return.ts b/samples/client/petstore-security-test/typescript-node/model/return.ts new file mode 100644 index 00000000000..1f8181f2396 --- /dev/null +++ b/samples/client/petstore-security-test/typescript-node/model/return.ts @@ -0,0 +1,36 @@ +/** + * OpenAPI Petstore *_/ ' \" =end -- \\r\\n \\n \\r + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end -- + * + * OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r + * Contact: something@something.abc *_/ ' \" =end -- \\r\\n \\n \\r + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +/** +* Model for testing reserved words *_/ ' \" =end -- \\r\\n \\n \\r +*/ +export class Return { + /** + * property description *_/ ' \" =end -- \\r\\n \\n \\r + */ + '_return'?: number; + + static discriminator: string | undefined = undefined; + + static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [ + { + "name": "_return", + "baseName": "return", + "type": "number" + } ]; + + static getAttributeTypeMap() { + return Return.attributeTypeMap; + } +} + diff --git a/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts index 6692083bc3c..f15094ee111 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts @@ -418,7 +418,7 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts index 01ad2dd7e36..53e52d1accb 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts @@ -170,7 +170,7 @@ export class StoreService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts index 6692083bc3c..f15094ee111 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts @@ -418,7 +418,7 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts index 01ad2dd7e36..53e52d1accb 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts @@ -170,7 +170,7 @@ export class StoreService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts index ce0fff0717f..8b5a9dc9b18 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts @@ -419,7 +419,7 @@ export class PetService implements PetServiceInterface { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts index 8a09472ef08..14a080468ec 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts @@ -171,7 +171,7 @@ export class StoreService implements StoreServiceInterface { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts index a982e419569..b8859f688a0 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts @@ -291,7 +291,7 @@ export class PetService { let headers = this.defaultHeaders; // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts index 460e1e59042..225138a71f5 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts @@ -110,7 +110,7 @@ export class StoreService { let headers = this.defaultHeaders; // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts index 6692083bc3c..f15094ee111 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts @@ -418,7 +418,7 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts index 01ad2dd7e36..53e52d1accb 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts @@ -170,7 +170,7 @@ export class StoreService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/api/pet.service.ts b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/api/pet.service.ts index 82575f519aa..b434fd2cd19 100644 --- a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/api/pet.service.ts @@ -291,7 +291,7 @@ export class PetService { let headers = this.defaultHeaders; // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/api/store.service.ts b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/api/store.service.ts index 1f1abb0b9e0..b1e7651cc80 100644 --- a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/api/store.service.ts @@ -110,7 +110,7 @@ export class StoreService { let headers = this.defaultHeaders; // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/api/pet.service.ts index 82575f519aa..b434fd2cd19 100644 --- a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/api/pet.service.ts @@ -291,7 +291,7 @@ export class PetService { let headers = this.defaultHeaders; // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/api/store.service.ts index 1f1abb0b9e0..b1e7651cc80 100644 --- a/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/api/store.service.ts @@ -110,7 +110,7 @@ export class StoreService { let headers = this.defaultHeaders; // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/api/pet.service.ts b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/api/pet.service.ts index e002c9a15cd..3da62e0e5f9 100644 --- a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/api/pet.service.ts @@ -293,7 +293,7 @@ export class PetService { let headers = this.defaultHeaders; // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/api/store.service.ts b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/api/store.service.ts index cae817406d7..efe62c694a6 100644 --- a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/api/store.service.ts @@ -112,7 +112,7 @@ export class StoreService { let headers = this.defaultHeaders; // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/api/pet.service.ts index e002c9a15cd..3da62e0e5f9 100644 --- a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/api/pet.service.ts @@ -293,7 +293,7 @@ export class PetService { let headers = this.defaultHeaders; // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/api/store.service.ts index cae817406d7..efe62c694a6 100644 --- a/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/api/store.service.ts @@ -112,7 +112,7 @@ export class StoreService { let headers = this.defaultHeaders; // authentication (api_key) required - if (this.configuration.apiKeys["api_key"]) { + if (this.configuration.apiKeys && this.configuration.apiKeys["api_key"]) { headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } diff --git a/samples/client/petstore/typescript-inversify/api/pet.service.ts b/samples/client/petstore/typescript-inversify/api/pet.service.ts index 34879a5c4d7..28462745307 100644 --- a/samples/client/petstore/typescript-inversify/api/pet.service.ts +++ b/samples/client/petstore/typescript-inversify/api/pet.service.ts @@ -187,7 +187,7 @@ export class PetService { } // authentication (api_key) required - if (this.APIConfiguration.apiKeys["api_key"]) { + if (this.APIConfiguration.apiKeys && this.APIConfiguration.apiKeys["api_key"]) { headers['api_key'] = this.APIConfiguration.apiKeys["api_key"]; } headers['Accept'] = 'application/xml'; diff --git a/samples/client/petstore/typescript-inversify/api/store.service.ts b/samples/client/petstore/typescript-inversify/api/store.service.ts index 45e65c489ba..f72d5bf1f28 100644 --- a/samples/client/petstore/typescript-inversify/api/store.service.ts +++ b/samples/client/petstore/typescript-inversify/api/store.service.ts @@ -68,7 +68,7 @@ export class StoreService { public getInventory(observe?: 'response', headers?: Headers): Observable>; public getInventory(observe: any = 'body', headers: Headers = {}): Observable { // authentication (api_key) required - if (this.APIConfiguration.apiKeys["api_key"]) { + if (this.APIConfiguration.apiKeys && this.APIConfiguration.apiKeys["api_key"]) { headers['api_key'] = this.APIConfiguration.apiKeys["api_key"]; } headers['Accept'] = 'application/json';