From 40b6fd0068d7db6f999af76f972fb60d9edafa68 Mon Sep 17 00:00:00 2001 From: Brian Towles Date: Sun, 12 Mar 2017 19:25:38 -0500 Subject: [PATCH 1/2] Updated maven plugin to allow for selective generation --- .../swagger/codegen/plugin/CodeGenMojo.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) 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 613c2b9186f..11b4c279399 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 @@ -174,6 +174,53 @@ public class CodeGenMojo extends AbstractMojo { @Parameter(name = "configOptions") private Map configOptions; + /** + * Generate the apis + */ + @Parameter(name = "generateApis", required = false) + private Boolean generateApis = true; + + /** + * Generate the models + */ + @Parameter(name = "generateModels", required = false) + private Boolean generateModels = true; + + @Parameter(name = "modelsToGenerate", required = false) + private String modelsToGenerate = ""; + + /** + * Generate the supporting files + */ + @Parameter(name = "generateSupportingFiles", required = false) + private Boolean generateSupportingFiles = true; + + /** + * Generate the model tests + */ + @Parameter(name = "generateModelTests", required = false) + private Boolean generateModelTests = true; + + /** + * Generate the model documentation + */ + @Parameter(name = "generateModelDocumentation", required = false) + private Boolean generateModelDocumentation = true; + + /** + * Generate the api tests + */ + @Parameter(name = "generateApiTests", required = false) + private Boolean generateApiTests = true; + + /** + * Generate the api documentation + */ + @Parameter(name = "generateApiDocumentation", required = false) + private Boolean generateApiDocumentation = true; + + + /** * Add the output directory to the project as a source root, so that the * generated java types are compiled and included in the project artifact. @@ -274,6 +321,23 @@ public void execute() throws MojoExecutionException { configurator.setTemplateDir(templateDirectory.getAbsolutePath()); } + // Set generation options + if (null != generateApis && generateApis) { + System.setProperty("apis", ""); + } + if (null != generateModels && generateModels) { + System.setProperty("models", modelsToGenerate); + } + + if (null != generateSupportingFiles && generateSupportingFiles) { + System.setProperty("supportingFiles", ""); + } + + System.setProperty("modelTests", generateModelTests.toString()); + System.setProperty("modelDocs", generateModelDocumentation.toString()); + System.setProperty("apiTests", generateApiTests.toString()); + System.setProperty("apiDocs", generateApiDocumentation.toString()); + if (configOptions != null) { if(configOptions.containsKey("instantiation-types")) { From d645b51459cb9bf9f55524a14f41e8c1940f799a Mon Sep 17 00:00:00 2001 From: Brian Towles Date: Sun, 12 Mar 2017 20:11:06 -0500 Subject: [PATCH 2/2] Documentation of Selective generation options. --- modules/swagger-codegen-maven-plugin/README.md | 9 +++++++++ .../java/io/swagger/codegen/plugin/CodeGenMojo.java | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen-maven-plugin/README.md b/modules/swagger-codegen-maven-plugin/README.md index 64382be8678..0b71c64b68f 100644 --- a/modules/swagger-codegen-maven-plugin/README.md +++ b/modules/swagger-codegen-maven-plugin/README.md @@ -50,6 +50,15 @@ mvn clean compile - `configOptions` - a map of language-specific parameters (see below) - `configHelp` - dumps the configuration help for the specified library (generates no sources) - `ignoreFileOverride` - specifies the full path to a `.swagger-codegen-ignore` used for pattern based overrides of generated outputs +- `generateApis` - generate the apis (`true` by default) +- `generateApiTests` - generate the api tests (`true` by default. Only available if `generateApis` is `true`) +- `generateApiDocumentation` - generate the api documentation (`true` by default. Only available if `generateApis` is `true`) +- `generateModels` - generate the models (`true` by default) +- `modelsToGenerate` - A comma separated list of models to generate. All models is the default. +- `generateModelTests` - generate the model tests (`true` by default. Only available if `generateModels` is `true`) +- `generateModelDocumentation` - generate the model documentation (`true` by default. Only available if `generateModels` is `true`) +- `generateSupportingFiles` - generate the supporting files (`true` by default) +- `supportingFilesToGenerate` - A comma separated list of supporting files to generate. All files is the default. ### Custom Generator 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 11b4c279399..15d3b4a86da 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 @@ -186,6 +186,9 @@ public class CodeGenMojo extends AbstractMojo { @Parameter(name = "generateModels", required = false) private Boolean generateModels = true; + /** + * A comma separated list of models to generate. All models is the default. + */ @Parameter(name = "modelsToGenerate", required = false) private String modelsToGenerate = ""; @@ -195,6 +198,12 @@ public class CodeGenMojo extends AbstractMojo { @Parameter(name = "generateSupportingFiles", required = false) private Boolean generateSupportingFiles = true; + /** + * A comma separated list of models to generate. All models is the default. + */ + @Parameter(name = "supportingFilesToGenerate", required = false) + private String supportingFilesToGenerate = ""; + /** * Generate the model tests */ @@ -330,7 +339,7 @@ public void execute() throws MojoExecutionException { } if (null != generateSupportingFiles && generateSupportingFiles) { - System.setProperty("supportingFiles", ""); + System.setProperty("supportingFiles", supportingFilesToGenerate); } System.setProperty("modelTests", generateModelTests.toString());