Skip to content

Commit

Permalink
Merge pull request #12339 from swagger-api/kodonnell-heila-patch-1
Browse files Browse the repository at this point in the history
Local Variable Prefix option for maven plugin
  • Loading branch information
HugoMario authored Feb 10, 2024
2 parents 7242d20 + 9602627 commit 67a018a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/swagger-codegen-maven-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 67a018a

Please sign in to comment.