diff --git a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Generate.java b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Generate.java index 01303e64559..4f0d1b7d6e7 100644 --- a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Generate.java +++ b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Generate.java @@ -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) 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 public void run() { @@ -222,6 +225,10 @@ public class Generate implements Runnable { configurator.setIgnoreFileOverride(ignoreFileOverride); } + if (removeOperationIdPrefix != null) { + configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix); + } + applySystemPropertiesKvp(systemProperties, configurator); applyInstantiationTypesKvp(instantiationTypes, configurator); applyImportMappingsKvp(importMappings, configurator); diff --git a/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java b/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java index dd8c08dfb68..510326cb365 100644 --- a/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java +++ b/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java @@ -108,6 +108,12 @@ public class CodeGenMojo extends AbstractMojo { @Parameter(name="skipOverwrite", required=false) 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 */ @@ -283,6 +289,10 @@ public class CodeGenMojo extends AbstractMojo { configurator.setSkipOverwrite(skipOverwrite); } + if(removeOperationIdPrefix != null) { + configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix); + } + if(isNotEmpty(inputSpec)) { configurator.setInputSpec(inputSpec); } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java index 4ffb9558230..682388b766f 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java @@ -171,6 +171,10 @@ public interface CodegenConfig { void setSkipOverwrite(boolean skipOverwrite); + boolean isRemoveOperationIdPrefix(); + + void setRemoveOperationIdPrefix(boolean removeOperationIdPrefix); + Map supportedLibraries(); void setLibrary(String library); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java index 974c65b0580..47a97e4d89d 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java @@ -191,4 +191,6 @@ public class CodegenConstants { 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 REMOVE_OPERATION_ID_PREFIX = "removeOperationIdPrefix"; + public static final String REMOVE_OPERATION_ID_PREFIX_DESC = "Remove prefix of operationId, e.g. config_getId => getId"; } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index d0f3b332c4a..4bf245894a9 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -102,6 +102,7 @@ public class DefaultCodegen { protected List supportingFiles = new ArrayList(); protected List cliOptions = new ArrayList(); protected boolean skipOverwrite; + protected boolean removeOperationIdPrefix; protected boolean supportsInheritance; protected boolean supportsMixins; protected Map supportedLibraries = new LinkedHashMap(); @@ -160,6 +161,11 @@ public class DefaultCodegen { if(additionalProperties.containsKey(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 @@ -849,7 +855,7 @@ public class DefaultCodegen { cliOptions.add(CliOption.newBoolean(CodegenConstants.ENSURE_UNIQUE_PARAMS, CodegenConstants .ENSURE_UNIQUE_PARAMS_DESC).defaultValue(Boolean.TRUE.toString())); - //name formatting options + // name formatting options cliOptions.add(CliOption.newBoolean(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, CodegenConstants .ALLOW_UNICODE_IDENTIFIERS_DESC).defaultValue(Boolean.FALSE.toString())); @@ -1982,6 +1988,13 @@ public class DefaultCodegen { op.vendorExtensions = operation.getVendorExtensions(); 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); op.path = path; op.operationId = toOperationId(operationId); @@ -3195,6 +3208,14 @@ public class DefaultCodegen { this.skipOverwrite = skipOverwrite; } + public boolean isRemoveOperationIdPrefix() { + return removeOperationIdPrefix; + } + + public void setRemoveOperationIdPrefix(boolean removeOperationIdPrefix) { + this.removeOperationIdPrefix = removeOperationIdPrefix; + } + /** * All library templates supported. * (key: library name, value: library description) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java index 86a7238cf04..92d411fe933 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java @@ -44,6 +44,7 @@ public class CodegenConfigurator implements Serializable { private String outputDir; private boolean verbose; private boolean skipOverwrite; + private boolean removeOperationIdPrefix; private String templateDir; private String auth; private String apiPackage; @@ -116,6 +117,15 @@ public class CodegenConfigurator implements Serializable { return this; } + public boolean getRemoveOperationIdPrefix() { + return removeOperationIdPrefix; + } + + public CodegenConfigurator setRemoveOperationIdPrefix(boolean removeOperationIdPrefix) { + this.removeOperationIdPrefix = removeOperationIdPrefix; + return this; + } + public String getModelNameSuffix() { return modelNameSuffix; } @@ -383,6 +393,7 @@ public class CodegenConfigurator implements Serializable { config.setOutputDir(outputDir); config.setSkipOverwrite(skipOverwrite); config.setIgnoreFilePathOverride(ignoreFileOverride); + config.setRemoveOperationIdPrefix(removeOperationIdPrefix); config.instantiationTypes().putAll(instantiationTypes); config.typeMapping().putAll(typeMappings); diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java index 3eb4aa68cdb..dd7489a57d9 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java @@ -56,7 +56,6 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { // at the moment importMapping.clear(); - supportsInheritance = true; outputFolder = "generated-code" + File.separator + "php"; modelTemplateFiles.put("model.mustache", ".php"); diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 7520a48d044..dfde3fc3b5b 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -228,7 +228,8 @@ use \{{invokerPackage}}\ObjectSerializer; {{/isFile}} } {{/formParams}} - {{#bodyParams}}// body params + {{#bodyParams}} + // body params $_tempBody = null; if (isset(${{paramName}})) { $_tempBody = ${{paramName}}; diff --git a/samples/client/petstore/php/.swagger-codegen/VERSION b/samples/client/petstore/php/.swagger-codegen/VERSION new file mode 100644 index 00000000000..7fea99011a6 --- /dev/null +++ b/samples/client/petstore/php/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php index d555ef5357e..ec943d9906f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -649,7 +649,7 @@ class FakeApi if ($callback !== null) { $formParams['callback'] = $this->apiClient->getSerializer()->toFormValue($callback); } - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -771,7 +771,7 @@ class FakeApi if ($enum_query_double !== null) { $formParams['enum_query_double'] = $this->apiClient->getSerializer()->toFormValue($enum_query_double); } - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index 2a83fec174f..b6b7455fad2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -222,7 +222,7 @@ class PetApi $resourcePath ); } - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -303,7 +303,7 @@ class PetApi if ($status !== null) { $queryParams['status'] = $this->apiClient->getSerializer()->toQueryValue($status); } - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -388,7 +388,7 @@ class PetApi if ($tags !== null) { $queryParams['tags'] = $this->apiClient->getSerializer()->toQueryValue($tags); } - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -474,7 +474,7 @@ class PetApi $resourcePath ); } - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -652,7 +652,7 @@ class PetApi if ($status !== null) { $formParams['status'] = $this->apiClient->getSerializer()->toFormValue($status); } - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -752,7 +752,7 @@ class PetApi $formParams['file'] = '@' . $this->apiClient->getSerializer()->toFormValue($file); } } - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php index bfa8fd71583..b609960c5f1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -137,7 +137,7 @@ class StoreApi $resourcePath ); } - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -201,7 +201,7 @@ class StoreApi } $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType([]); - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -295,7 +295,7 @@ class StoreApi $resourcePath ); } - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php index 8d893d055ec..e628149a818 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -362,7 +362,7 @@ class UserApi $resourcePath ); } - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -440,7 +440,7 @@ class UserApi $resourcePath ); } - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -528,7 +528,7 @@ class UserApi if ($password !== null) { $queryParams['password'] = $this->apiClient->getSerializer()->toQueryValue($password); } - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present @@ -596,7 +596,7 @@ class UserApi } $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType([]); - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present