forked from loafle/openapi-generator-original
Fix model prefix/suffix with incorrect camelization (#4621)
* fix camelized name with suffix/prefix in java client * fix php model name with prefix, suffix * fix indentation in ts abstrat generator * replace tab with spaces in ts abstract generator
This commit is contained in:
parent
2e50a65a1c
commit
8e71dfb512
@ -502,11 +502,22 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String toModelName(final String name) {
|
||||
final String sanitizedName = sanitizeName(modelNamePrefix + name + modelNameSuffix);
|
||||
final String sanitizedName = sanitizeName(name);
|
||||
|
||||
String nameWithPrefixSuffix = sanitizedName;
|
||||
if (!StringUtils.isEmpty(modelNamePrefix)) {
|
||||
// add '_' so that model name can be camelized correctly
|
||||
nameWithPrefixSuffix = modelNamePrefix + "_" + nameWithPrefixSuffix;
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(modelNameSuffix)) {
|
||||
// add '_' so that model name can be camelized correctly
|
||||
nameWithPrefixSuffix = nameWithPrefixSuffix + "_" + modelNameSuffix;
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
final String camelizedName = camelize(sanitizedName);
|
||||
final String camelizedName = camelize(nameWithPrefixSuffix);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(camelizedName)) {
|
||||
@ -516,7 +527,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
}
|
||||
|
||||
// model name starts with number
|
||||
if (name.matches("^\\d.*")) {
|
||||
if (camelizedName.matches("^\\d.*")) {
|
||||
final String modelName = "Model" + camelizedName; // 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;
|
||||
|
@ -108,7 +108,6 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
|
@ -483,7 +483,13 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// add prefix and/or suffic only if name does not start wth \ (e.g. \DateTime)
|
||||
if (!name.matches("^\\\\.*")) {
|
||||
name = modelNamePrefix + name + modelNameSuffix;
|
||||
if (!StringUtils.isEmpty(modelNamePrefix)) {
|
||||
name = modelNamePrefix + "_" + name;
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(modelNameSuffix)) {
|
||||
name = name + "_" + modelNameSuffix;
|
||||
}
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
|
@ -26,11 +26,10 @@ use \ArrayAccess;
|
||||
/**
|
||||
* {{classname}} Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
* @category Class
|
||||
{{#description}}
|
||||
// @description {{description}}
|
||||
* @description {{description}}
|
||||
{{/description}}
|
||||
/**
|
||||
* @package {{invokerPackage}}
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
21
samples/client/petstore/java/okhttp-gson/.gitignore
vendored
Normal file
21
samples/client/petstore/java/okhttp-gson/.gitignore
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
*.class
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
|
||||
# exclude jar for gradle wrapper
|
||||
!gradle/wrapper/*.jar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
# build files
|
||||
**/target
|
||||
target
|
||||
.gradle
|
||||
build
|
@ -0,0 +1,23 @@
|
||||
# Swagger Codegen Ignore
|
||||
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
|
||||
|
||||
# Use this file to prevent files from being overwritten by the generator.
|
||||
# The patterns follow closely to .gitignore or .dockerignore.
|
||||
|
||||
# As an example, the C# client generator defines ApiClient.cs.
|
||||
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
|
||||
#ApiClient.cs
|
||||
|
||||
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||
#foo/*/qux
|
||||
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||
|
||||
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||
#foo/**/qux
|
||||
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||
|
||||
# You can also negate patterns with an exclamation (!).
|
||||
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||
#docs/*.md
|
||||
# Then explicitly reverse the ignore rule for a single file:
|
||||
#!docs/README.md
|
17
samples/client/petstore/java/okhttp-gson/.travis.yml
Normal file
17
samples/client/petstore/java/okhttp-gson/.travis.yml
Normal file
@ -0,0 +1,17 @@
|
||||
#
|
||||
# Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||
#
|
||||
language: java
|
||||
jdk:
|
||||
- oraclejdk8
|
||||
- oraclejdk7
|
||||
before_install:
|
||||
# ensure gradlew has proper permission
|
||||
- chmod a+x ./gradlew
|
||||
script:
|
||||
# test using maven
|
||||
- mvn test
|
||||
# uncomment below to test using gradle
|
||||
# - gradle test
|
||||
# uncomment below to test using sbt
|
||||
# - sbt test
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* AdditionalPropertiesClass Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* Animal Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* AnimalFarm Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* ApiResponse Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* ArrayOfArrayOfNumberOnly Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* ArrayOfNumberOnly Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* ArrayTest Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* Cat Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* Category Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,9 +34,8 @@ use \ArrayAccess;
|
||||
/**
|
||||
* ClassModel Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
// @description Model for testing model with \"_class\" property
|
||||
/**
|
||||
* @category Class
|
||||
* @description Model for testing model with \"_class\" property
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* Client Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* Dog Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* EnumArrays Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* EnumClass Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* EnumTest Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* FormatTest Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* HasOnlyReadOnly Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* MapTest Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* MixedPropertiesAndAdditionalPropertiesClass Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,9 +34,8 @@ use \ArrayAccess;
|
||||
/**
|
||||
* Model200Response Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
// @description Model for testing model name starting with number
|
||||
/**
|
||||
* @category Class
|
||||
* @description Model for testing model name starting with number
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* ModelList Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,9 +34,8 @@ use \ArrayAccess;
|
||||
/**
|
||||
* ModelReturn Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
// @description Model for testing reserved words
|
||||
/**
|
||||
* @category Class
|
||||
* @description Model for testing reserved words
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,9 +34,8 @@ use \ArrayAccess;
|
||||
/**
|
||||
* Name Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
// @description Model for testing model name same as property name
|
||||
/**
|
||||
* @category Class
|
||||
* @description Model for testing model name same as property name
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* NumberOnly Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* Order Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* OuterEnum Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* Pet Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* ReadOnlyFirst Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* SpecialModelName Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* Tag Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
@ -34,8 +34,7 @@ use \ArrayAccess;
|
||||
/**
|
||||
* User Class Doc Comment
|
||||
*
|
||||
* @category Class */
|
||||
/**
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
|
Loading…
x
Reference in New Issue
Block a user