Skip to content

Commit 67a018a

Browse files
authored
Merge pull request #12339 from swagger-api/kodonnell-heila-patch-1
Local Variable Prefix option for maven plugin
2 parents 7242d20 + 9602627 commit 67a018a

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

modules/swagger-codegen-maven-plugin/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ mvn clean compile
4646
- `apiPackage` - the package to use for generated api objects/classes
4747
- `invokerPackage` - the package to use for the generated invoker objects
4848
- `modelNamePrefix` and `modelNameSuffix` - Sets the pre- or suffix for model classes and enums
49+
- `localVariablePrefix` - adds a prefix for all generated local variables. Helps if your API has method names that conflict with local variable names.
4950
- `withXml` - enable XML annotations inside the generated models and API (only works with Java `language` and libraries that provide support for JSON and XML)
5051
- `configOptions` - a map of language-specific parameters (see below)
5152
- `configHelp` - dumps the configuration help for the specified library (generates no sources)

modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java

+10
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ public class CodeGenMojo extends AbstractMojo {
172172
@Parameter(name = "modelNameSuffix", required = false)
173173
private String modelNameSuffix;
174174

175+
/**
176+
* Adds a prefix for all generated local variables
177+
*/
178+
@Parameter(name = "localVariablePrefix", required = false)
179+
private String localVariablePrefix;
180+
175181
/**
176182
* Sets an optional ignoreFileOverride path
177183
*/
@@ -409,6 +415,10 @@ protected void execute_() throws MojoExecutionException {
409415
configurator.setModelNameSuffix(modelNameSuffix);
410416
}
411417

418+
if (isNotEmpty(localVariablePrefix)) {
419+
configurator.setLocalVariablePrefix(localVariablePrefix);
420+
}
421+
412422
if (null != templateDirectory) {
413423
configurator.setTemplateDir(templateDirectory.getAbsolutePath());
414424
}

modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java

+11
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class CodegenConfigurator implements Serializable {
5454
private String invokerPackage;
5555
private String modelNamePrefix;
5656
private String modelNameSuffix;
57+
private String localVariablePrefix;
5758
private String groupId;
5859
private String artifactId;
5960
private String artifactVersion;
@@ -142,6 +143,15 @@ public CodegenConfigurator setModelNameSuffix(String suffix) {
142143
return this;
143144
}
144145

146+
public String getLocalVariablePrefix() {
147+
return localVariablePrefix;
148+
}
149+
150+
public CodegenConfigurator setLocalVariablePrefix(String localVariablePrefix) {
151+
this.localVariablePrefix = localVariablePrefix;
152+
return this;
153+
}
154+
145155
public boolean isVerbose() {
146156
return verbose;
147157
}
@@ -427,6 +437,7 @@ public ClientOptInput toClientOptInput() {
427437
checkAndSetAdditionalProperty(templateDir, toAbsolutePathStr(templateDir), CodegenConstants.TEMPLATE_DIR);
428438
checkAndSetAdditionalProperty(modelNamePrefix, CodegenConstants.MODEL_NAME_PREFIX);
429439
checkAndSetAdditionalProperty(modelNameSuffix, CodegenConstants.MODEL_NAME_SUFFIX);
440+
checkAndSetAdditionalProperty(localVariablePrefix, CodegenConstants.LOCAL_VARIABLE_PREFIX);
430441
checkAndSetAdditionalProperty(gitUserId, CodegenConstants.GIT_USER_ID);
431442
checkAndSetAdditionalProperty(gitRepoId, CodegenConstants.GIT_REPO_ID);
432443
checkAndSetAdditionalProperty(releaseNote, CodegenConstants.RELEASE_NOTE);

0 commit comments

Comments
 (0)