diff --git a/modules/swagger-codegen-maven-plugin/README.md b/modules/swagger-codegen-maven-plugin/README.md index 6a155604cd6..413650c317a 100644 --- a/modules/swagger-codegen-maven-plugin/README.md +++ b/modules/swagger-codegen-maven-plugin/README.md @@ -46,6 +46,7 @@ mvn clean compile - `apiPackage` - the package to use for generated api objects/classes - `invokerPackage` - the package to use for the generated invoker objects - `modelNamePrefix` and `modelNameSuffix` - Sets the pre- or suffix for model classes and enums +- `localVariablePrefix` - adds a prefix for all generated local variables. Helps if your API has method names that conflict with local variable names. - `withXml` - enable XML annotations inside the generated models and API (only works with Java `language` and libraries that provide support for JSON and XML) - `configOptions` - a map of language-specific parameters (see below) - `configHelp` - dumps the configuration help for the specified library (generates no sources) 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 bb5aedd81d1..d7539f1d03a 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 @@ -172,6 +172,12 @@ public class CodeGenMojo extends AbstractMojo { @Parameter(name = "modelNameSuffix", required = false) private String modelNameSuffix; + /** + * Adds a prefix for all generated local variables + */ + @Parameter(name = "localVariablePrefix", required = false) + private String localVariablePrefix; + /** * Sets an optional ignoreFileOverride path */ @@ -409,6 +415,10 @@ protected void execute_() throws MojoExecutionException { configurator.setModelNameSuffix(modelNameSuffix); } + if (isNotEmpty(localVariablePrefix)) { + configurator.setLocalVariablePrefix(localVariablePrefix); + } + if (null != templateDirectory) { configurator.setTemplateDir(templateDirectory.getAbsolutePath()); } 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 28f9145e1c1..032822bc8b5 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 @@ -54,6 +54,7 @@ public class CodegenConfigurator implements Serializable { private String invokerPackage; private String modelNamePrefix; private String modelNameSuffix; + private String localVariablePrefix; private String groupId; private String artifactId; private String artifactVersion; @@ -142,6 +143,15 @@ public CodegenConfigurator setModelNameSuffix(String suffix) { return this; } + public String getLocalVariablePrefix() { + return localVariablePrefix; + } + + public CodegenConfigurator setLocalVariablePrefix(String localVariablePrefix) { + this.localVariablePrefix = localVariablePrefix; + return this; + } + public boolean isVerbose() { return verbose; } @@ -427,6 +437,7 @@ public ClientOptInput toClientOptInput() { checkAndSetAdditionalProperty(templateDir, toAbsolutePathStr(templateDir), CodegenConstants.TEMPLATE_DIR); checkAndSetAdditionalProperty(modelNamePrefix, CodegenConstants.MODEL_NAME_PREFIX); checkAndSetAdditionalProperty(modelNameSuffix, CodegenConstants.MODEL_NAME_SUFFIX); + checkAndSetAdditionalProperty(localVariablePrefix, CodegenConstants.LOCAL_VARIABLE_PREFIX); checkAndSetAdditionalProperty(gitUserId, CodegenConstants.GIT_USER_ID); checkAndSetAdditionalProperty(gitRepoId, CodegenConstants.GIT_REPO_ID); checkAndSetAdditionalProperty(releaseNote, CodegenConstants.RELEASE_NOTE);