From 0ada53435c5909bb1b97ff58bfecabc85400790e Mon Sep 17 00:00:00 2001 From: christian Date: Mon, 4 Jul 2016 19:51:38 +0200 Subject: [PATCH] #3284: Made modelNamePrefix and -Suffix available through maven --- .../swagger-codegen-maven-plugin/README.md | 1 + .../swagger/codegen/plugin/CodeGenMojo.java | 24 +++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/modules/swagger-codegen-maven-plugin/README.md b/modules/swagger-codegen-maven-plugin/README.md index d9282c97ebf..b32cacacc2c 100644 --- a/modules/swagger-codegen-maven-plugin/README.md +++ b/modules/swagger-codegen-maven-plugin/README.md @@ -45,6 +45,7 @@ mvn clean compile - `modelPackage` - the package to use for generated model objects/classes - `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. - `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 261d539e2e5..8ad3c073bfb 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 @@ -21,8 +21,6 @@ import io.swagger.codegen.ClientOptInput; import io.swagger.codegen.CodegenConfig; import io.swagger.codegen.DefaultGenerator; import io.swagger.codegen.config.CodegenConfigurator; -import io.swagger.models.Swagger; -import io.swagger.parser.SwaggerParser; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.LifecyclePhase; @@ -32,9 +30,7 @@ import org.apache.maven.project.MavenProject; import java.io.File; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import static io.swagger.codegen.config.CodegenConfiguratorUtils.*; import static org.apache.commons.lang3.StringUtils.isNotEmpty; @@ -135,6 +131,18 @@ public class CodeGenMojo extends AbstractMojo { @Parameter(name = "library", required = false) private String library; + /** + * Sets the prefix for model enums and classes + */ + @Parameter(name = "modelNamePrefix", required = false) + private String modelNamePrefix; + + /** + * Sets the suffix for model enums and classes + */ + @Parameter(name = "modelNameSuffix", required = false) + private String modelNameSuffix; + /** * A map of language-specific parameters as passed with the -c option to the command line */ @@ -217,6 +225,14 @@ public class CodeGenMojo extends AbstractMojo { configurator.setLibrary(library); } + if(isNotEmpty(modelNamePrefix)) { + configurator.setModelNamePrefix(modelNamePrefix); + } + + if(isNotEmpty(modelNameSuffix)) { + configurator.setModelNamePrefix(modelNameSuffix); + } + if (null != templateDirectory) { configurator.setTemplateDir(templateDirectory.getAbsolutePath()); }