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:
wing328 2017-01-23 01:29:11 +08:00 committed by GitHub
parent 2e50a65a1c
commit 8e71dfb512
38 changed files with 193 additions and 148 deletions

View File

@ -502,11 +502,22 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
@Override @Override
public String toModelName(final String name) { 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 // camelize the model name
// phone_number => PhoneNumber // phone_number => PhoneNumber
final String camelizedName = camelize(sanitizedName); final String camelizedName = camelize(nameWithPrefixSuffix);
// model name cannot use reserved keyword, e.g. return // model name cannot use reserved keyword, e.g. return
if (isReservedWord(camelizedName)) { if (isReservedWord(camelizedName)) {
@ -516,7 +527,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
} }
// model name starts with number // model name starts with number
if (name.matches("^\\d.*")) { if (camelizedName.matches("^\\d.*")) {
final String modelName = "Model" + camelizedName; // e.g. 200Response => Model200Response (after camelize) 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); LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + modelName);
return modelName; return modelName;

View File

@ -108,7 +108,6 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
} }
} }
@Override @Override
public CodegenType getTag() { public CodegenType getTag() {
return CodegenType.CLIENT; return CodegenType.CLIENT;

View File

@ -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) // add prefix and/or suffic only if name does not start wth \ (e.g. \DateTime)
if (!name.matches("^\\\\.*")) { 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 // camelize the model name

View File

@ -26,11 +26,10 @@ use \ArrayAccess;
/** /**
* {{classname}} Class Doc Comment * {{classname}} Class Doc Comment
* *
* @category Class */ * @category Class
{{#description}} {{#description}}
// @description {{description}} * @description {{description}}
{{/description}} {{/description}}
/**
* @package {{invokerPackage}} * @package {{invokerPackage}}
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View 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

View File

@ -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

View 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

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* AdditionalPropertiesClass Class Doc Comment * AdditionalPropertiesClass Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* Animal Class Doc Comment * Animal Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* AnimalFarm Class Doc Comment * AnimalFarm Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* ApiResponse Class Doc Comment * ApiResponse Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* ArrayOfArrayOfNumberOnly Class Doc Comment * ArrayOfArrayOfNumberOnly Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* ArrayOfNumberOnly Class Doc Comment * ArrayOfNumberOnly Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* ArrayTest Class Doc Comment * ArrayTest Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* Cat Class Doc Comment * Cat Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* Category Class Doc Comment * Category Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,9 +34,8 @@ use \ArrayAccess;
/** /**
* ClassModel Class Doc Comment * ClassModel Class Doc Comment
* *
* @category Class */ * @category Class
// @description Model for testing model with \"_class\" property * @description Model for testing model with \"_class\" property
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* Client Class Doc Comment * Client Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* Dog Class Doc Comment * Dog Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* EnumArrays Class Doc Comment * EnumArrays Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* EnumClass Class Doc Comment * EnumClass Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* EnumTest Class Doc Comment * EnumTest Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* FormatTest Class Doc Comment * FormatTest Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* HasOnlyReadOnly Class Doc Comment * HasOnlyReadOnly Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* MapTest Class Doc Comment * MapTest Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* MixedPropertiesAndAdditionalPropertiesClass Class Doc Comment * MixedPropertiesAndAdditionalPropertiesClass Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,9 +34,8 @@ use \ArrayAccess;
/** /**
* Model200Response Class Doc Comment * Model200Response Class Doc Comment
* *
* @category Class */ * @category Class
// @description Model for testing model name starting with number * @description Model for testing model name starting with number
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* ModelList Class Doc Comment * ModelList Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,9 +34,8 @@ use \ArrayAccess;
/** /**
* ModelReturn Class Doc Comment * ModelReturn Class Doc Comment
* *
* @category Class */ * @category Class
// @description Model for testing reserved words * @description Model for testing reserved words
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,9 +34,8 @@ use \ArrayAccess;
/** /**
* Name Class Doc Comment * Name Class Doc Comment
* *
* @category Class */ * @category Class
// @description Model for testing model name same as property name * @description Model for testing model name same as property name
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* NumberOnly Class Doc Comment * NumberOnly Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* Order Class Doc Comment * Order Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* OuterEnum Class Doc Comment * OuterEnum Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* Pet Class Doc Comment * Pet Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* ReadOnlyFirst Class Doc Comment * ReadOnlyFirst Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* SpecialModelName Class Doc Comment * SpecialModelName Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* Tag Class Doc Comment * Tag Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen

View File

@ -34,8 +34,7 @@ use \ArrayAccess;
/** /**
* User Class Doc Comment * User Class Doc Comment
* *
* @category Class */ * @category Class
/**
* @package Swagger\Client * @package Swagger\Client
* @author Swagger Codegen team * @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen * @link https://github.com/swagger-api/swagger-codegen