Add removeOperationIdPrefix option (#5674)

* add removeOperationIdPrefix option

* remove removeOperationIdPrefix from cli option for generators
This commit is contained in:
wing328 2017-05-21 01:28:06 +08:00 committed by GitHub
parent 7edf744426
commit 8314f4e78a
13 changed files with 74 additions and 18 deletions

View File

@ -125,6 +125,9 @@ public class Generate implements Runnable {
@Option(name = {"--ignore-file-override"}, title = "ignore file override location", description = CodegenConstants.IGNORE_FILE_OVERRIDE_DESC) @Option(name = {"--ignore-file-override"}, title = "ignore file override location", description = CodegenConstants.IGNORE_FILE_OVERRIDE_DESC)
private String ignoreFileOverride; private String ignoreFileOverride;
@Option(name = {"--remove-operation-id-prefix"}, title = "remove prefix of the operationId", description = CodegenConstants.REMOVE_OPERATION_ID_PREFIX_DESC)
private Boolean removeOperationIdPrefix;
@Override @Override
public void run() { public void run() {
@ -222,6 +225,10 @@ public class Generate implements Runnable {
configurator.setIgnoreFileOverride(ignoreFileOverride); configurator.setIgnoreFileOverride(ignoreFileOverride);
} }
if (removeOperationIdPrefix != null) {
configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix);
}
applySystemPropertiesKvp(systemProperties, configurator); applySystemPropertiesKvp(systemProperties, configurator);
applyInstantiationTypesKvp(instantiationTypes, configurator); applyInstantiationTypesKvp(instantiationTypes, configurator);
applyImportMappingsKvp(importMappings, configurator); applyImportMappingsKvp(importMappings, configurator);

View File

@ -108,6 +108,12 @@ public class CodeGenMojo extends AbstractMojo {
@Parameter(name="skipOverwrite", required=false) @Parameter(name="skipOverwrite", required=false)
private Boolean skipOverwrite; private Boolean skipOverwrite;
/**
* Specifies if the existing files should be overwritten during the generation.
*/
@Parameter(name="removeOperationIdPrefix", required=false)
private Boolean removeOperationIdPrefix;
/** /**
* The package to use for generated api objects/classes * The package to use for generated api objects/classes
*/ */
@ -283,6 +289,10 @@ public class CodeGenMojo extends AbstractMojo {
configurator.setSkipOverwrite(skipOverwrite); configurator.setSkipOverwrite(skipOverwrite);
} }
if(removeOperationIdPrefix != null) {
configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix);
}
if(isNotEmpty(inputSpec)) { if(isNotEmpty(inputSpec)) {
configurator.setInputSpec(inputSpec); configurator.setInputSpec(inputSpec);
} }

View File

@ -171,6 +171,10 @@ public interface CodegenConfig {
void setSkipOverwrite(boolean skipOverwrite); void setSkipOverwrite(boolean skipOverwrite);
boolean isRemoveOperationIdPrefix();
void setRemoveOperationIdPrefix(boolean removeOperationIdPrefix);
Map<String, String> supportedLibraries(); Map<String, String> supportedLibraries();
void setLibrary(String library); void setLibrary(String library);

View File

@ -191,4 +191,6 @@ public class CodegenConstants {
public static final String IGNORE_FILE_OVERRIDE = "ignoreFileOverride"; public static final String IGNORE_FILE_OVERRIDE = "ignoreFileOverride";
public static final String IGNORE_FILE_OVERRIDE_DESC = "Specifies an override location for the .swagger-codegen-ignore file. Most useful on initial generation."; public static final String IGNORE_FILE_OVERRIDE_DESC = "Specifies an override location for the .swagger-codegen-ignore file. Most useful on initial generation.";
public static final String REMOVE_OPERATION_ID_PREFIX = "removeOperationIdPrefix";
public static final String REMOVE_OPERATION_ID_PREFIX_DESC = "Remove prefix of operationId, e.g. config_getId => getId";
} }

View File

@ -102,6 +102,7 @@ public class DefaultCodegen {
protected List<SupportingFile> supportingFiles = new ArrayList<SupportingFile>(); protected List<SupportingFile> supportingFiles = new ArrayList<SupportingFile>();
protected List<CliOption> cliOptions = new ArrayList<CliOption>(); protected List<CliOption> cliOptions = new ArrayList<CliOption>();
protected boolean skipOverwrite; protected boolean skipOverwrite;
protected boolean removeOperationIdPrefix;
protected boolean supportsInheritance; protected boolean supportsInheritance;
protected boolean supportsMixins; protected boolean supportsMixins;
protected Map<String, String> supportedLibraries = new LinkedHashMap<String, String>(); protected Map<String, String> supportedLibraries = new LinkedHashMap<String, String>();
@ -160,6 +161,11 @@ public class DefaultCodegen {
if(additionalProperties.containsKey(CodegenConstants.MODEL_NAME_SUFFIX)){ if(additionalProperties.containsKey(CodegenConstants.MODEL_NAME_SUFFIX)){
this.setModelNameSuffix((String) additionalProperties.get(CodegenConstants.MODEL_NAME_SUFFIX)); this.setModelNameSuffix((String) additionalProperties.get(CodegenConstants.MODEL_NAME_SUFFIX));
} }
if (additionalProperties.containsKey(CodegenConstants.REMOVE_OPERATION_ID_PREFIX)) {
this.setSortParamsByRequiredFlag(Boolean.valueOf(additionalProperties
.get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX).toString()));
}
} }
// override with any special post-processing for all models // override with any special post-processing for all models
@ -849,7 +855,7 @@ public class DefaultCodegen {
cliOptions.add(CliOption.newBoolean(CodegenConstants.ENSURE_UNIQUE_PARAMS, CodegenConstants cliOptions.add(CliOption.newBoolean(CodegenConstants.ENSURE_UNIQUE_PARAMS, CodegenConstants
.ENSURE_UNIQUE_PARAMS_DESC).defaultValue(Boolean.TRUE.toString())); .ENSURE_UNIQUE_PARAMS_DESC).defaultValue(Boolean.TRUE.toString()));
//name formatting options // name formatting options
cliOptions.add(CliOption.newBoolean(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, CodegenConstants cliOptions.add(CliOption.newBoolean(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, CodegenConstants
.ALLOW_UNICODE_IDENTIFIERS_DESC).defaultValue(Boolean.FALSE.toString())); .ALLOW_UNICODE_IDENTIFIERS_DESC).defaultValue(Boolean.FALSE.toString()));
@ -1982,6 +1988,13 @@ public class DefaultCodegen {
op.vendorExtensions = operation.getVendorExtensions(); op.vendorExtensions = operation.getVendorExtensions();
String operationId = getOrGenerateOperationId(operation, path, httpMethod); String operationId = getOrGenerateOperationId(operation, path, httpMethod);
// remove prefix in operationId
if (removeOperationIdPrefix) {
int offset = operationId.indexOf('_');
if (offset > -1) {
operationId = operationId.substring(offset+1);
}
}
operationId = removeNonNameElementToCamelCase(operationId); operationId = removeNonNameElementToCamelCase(operationId);
op.path = path; op.path = path;
op.operationId = toOperationId(operationId); op.operationId = toOperationId(operationId);
@ -3195,6 +3208,14 @@ public class DefaultCodegen {
this.skipOverwrite = skipOverwrite; this.skipOverwrite = skipOverwrite;
} }
public boolean isRemoveOperationIdPrefix() {
return removeOperationIdPrefix;
}
public void setRemoveOperationIdPrefix(boolean removeOperationIdPrefix) {
this.removeOperationIdPrefix = removeOperationIdPrefix;
}
/** /**
* All library templates supported. * All library templates supported.
* (key: library name, value: library description) * (key: library name, value: library description)

View File

@ -44,6 +44,7 @@ public class CodegenConfigurator implements Serializable {
private String outputDir; private String outputDir;
private boolean verbose; private boolean verbose;
private boolean skipOverwrite; private boolean skipOverwrite;
private boolean removeOperationIdPrefix;
private String templateDir; private String templateDir;
private String auth; private String auth;
private String apiPackage; private String apiPackage;
@ -116,6 +117,15 @@ public class CodegenConfigurator implements Serializable {
return this; return this;
} }
public boolean getRemoveOperationIdPrefix() {
return removeOperationIdPrefix;
}
public CodegenConfigurator setRemoveOperationIdPrefix(boolean removeOperationIdPrefix) {
this.removeOperationIdPrefix = removeOperationIdPrefix;
return this;
}
public String getModelNameSuffix() { public String getModelNameSuffix() {
return modelNameSuffix; return modelNameSuffix;
} }
@ -383,6 +393,7 @@ public class CodegenConfigurator implements Serializable {
config.setOutputDir(outputDir); config.setOutputDir(outputDir);
config.setSkipOverwrite(skipOverwrite); config.setSkipOverwrite(skipOverwrite);
config.setIgnoreFilePathOverride(ignoreFileOverride); config.setIgnoreFilePathOverride(ignoreFileOverride);
config.setRemoveOperationIdPrefix(removeOperationIdPrefix);
config.instantiationTypes().putAll(instantiationTypes); config.instantiationTypes().putAll(instantiationTypes);
config.typeMapping().putAll(typeMappings); config.typeMapping().putAll(typeMappings);

View File

@ -56,7 +56,6 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
// at the moment // at the moment
importMapping.clear(); importMapping.clear();
supportsInheritance = true; supportsInheritance = true;
outputFolder = "generated-code" + File.separator + "php"; outputFolder = "generated-code" + File.separator + "php";
modelTemplateFiles.put("model.mustache", ".php"); modelTemplateFiles.put("model.mustache", ".php");

View File

@ -228,7 +228,8 @@ use \{{invokerPackage}}\ObjectSerializer;
{{/isFile}} {{/isFile}}
} }
{{/formParams}} {{/formParams}}
{{#bodyParams}}// body params {{#bodyParams}}
// body params
$_tempBody = null; $_tempBody = null;
if (isset(${{paramName}})) { if (isset(${{paramName}})) {
$_tempBody = ${{paramName}}; $_tempBody = ${{paramName}};

View File

@ -0,0 +1 @@
2.2.3-SNAPSHOT

View File

@ -649,7 +649,7 @@ class FakeApi
if ($callback !== null) { if ($callback !== null) {
$formParams['callback'] = $this->apiClient->getSerializer()->toFormValue($callback); $formParams['callback'] = $this->apiClient->getSerializer()->toFormValue($callback);
} }
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present $httpBody = $_tempBody; // $_tempBody is the method argument, if present
@ -771,7 +771,7 @@ class FakeApi
if ($enum_query_double !== null) { if ($enum_query_double !== null) {
$formParams['enum_query_double'] = $this->apiClient->getSerializer()->toFormValue($enum_query_double); $formParams['enum_query_double'] = $this->apiClient->getSerializer()->toFormValue($enum_query_double);
} }
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present $httpBody = $_tempBody; // $_tempBody is the method argument, if present

View File

@ -222,7 +222,7 @@ class PetApi
$resourcePath $resourcePath
); );
} }
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present $httpBody = $_tempBody; // $_tempBody is the method argument, if present
@ -303,7 +303,7 @@ class PetApi
if ($status !== null) { if ($status !== null) {
$queryParams['status'] = $this->apiClient->getSerializer()->toQueryValue($status); $queryParams['status'] = $this->apiClient->getSerializer()->toQueryValue($status);
} }
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present $httpBody = $_tempBody; // $_tempBody is the method argument, if present
@ -388,7 +388,7 @@ class PetApi
if ($tags !== null) { if ($tags !== null) {
$queryParams['tags'] = $this->apiClient->getSerializer()->toQueryValue($tags); $queryParams['tags'] = $this->apiClient->getSerializer()->toQueryValue($tags);
} }
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present $httpBody = $_tempBody; // $_tempBody is the method argument, if present
@ -474,7 +474,7 @@ class PetApi
$resourcePath $resourcePath
); );
} }
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present $httpBody = $_tempBody; // $_tempBody is the method argument, if present
@ -652,7 +652,7 @@ class PetApi
if ($status !== null) { if ($status !== null) {
$formParams['status'] = $this->apiClient->getSerializer()->toFormValue($status); $formParams['status'] = $this->apiClient->getSerializer()->toFormValue($status);
} }
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present $httpBody = $_tempBody; // $_tempBody is the method argument, if present
@ -752,7 +752,7 @@ class PetApi
$formParams['file'] = '@' . $this->apiClient->getSerializer()->toFormValue($file); $formParams['file'] = '@' . $this->apiClient->getSerializer()->toFormValue($file);
} }
} }
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present $httpBody = $_tempBody; // $_tempBody is the method argument, if present

View File

@ -137,7 +137,7 @@ class StoreApi
$resourcePath $resourcePath
); );
} }
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present $httpBody = $_tempBody; // $_tempBody is the method argument, if present
@ -201,7 +201,7 @@ class StoreApi
} }
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType([]); $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType([]);
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present $httpBody = $_tempBody; // $_tempBody is the method argument, if present
@ -295,7 +295,7 @@ class StoreApi
$resourcePath $resourcePath
); );
} }
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present $httpBody = $_tempBody; // $_tempBody is the method argument, if present

View File

@ -362,7 +362,7 @@ class UserApi
$resourcePath $resourcePath
); );
} }
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present $httpBody = $_tempBody; // $_tempBody is the method argument, if present
@ -440,7 +440,7 @@ class UserApi
$resourcePath $resourcePath
); );
} }
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present $httpBody = $_tempBody; // $_tempBody is the method argument, if present
@ -528,7 +528,7 @@ class UserApi
if ($password !== null) { if ($password !== null) {
$queryParams['password'] = $this->apiClient->getSerializer()->toQueryValue($password); $queryParams['password'] = $this->apiClient->getSerializer()->toQueryValue($password);
} }
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present $httpBody = $_tempBody; // $_tempBody is the method argument, if present
@ -596,7 +596,7 @@ class UserApi
} }
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType([]); $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType([]);
// for model (json/xml) // for model (json/xml)
if (isset($_tempBody)) { if (isset($_tempBody)) {
$httpBody = $_tempBody; // $_tempBody is the method argument, if present $httpBody = $_tempBody; // $_tempBody is the method argument, if present