|
34 | 34 | import java.util.List;
|
35 | 35 | import java.util.Map;
|
36 | 36 |
|
| 37 | +import io.swagger.codegen.v3.CodegenArgument; |
37 | 38 | import org.apache.maven.plugin.AbstractMojo;
|
38 | 39 | import org.apache.maven.plugin.MojoExecutionException;
|
39 | 40 | import org.apache.maven.plugins.annotations.LifecyclePhase;
|
@@ -423,10 +424,12 @@ public void execute() throws MojoExecutionException {
|
423 | 424 | System.clearProperty(CodegenConstants.SUPPORTING_FILES);
|
424 | 425 | }
|
425 | 426 |
|
426 |
| - System.setProperty(CodegenConstants.MODEL_TESTS, generateModelTests.toString()); |
427 |
| - System.setProperty(CodegenConstants.MODEL_DOCS, generateModelDocumentation.toString()); |
428 |
| - System.setProperty(CodegenConstants.API_TESTS, generateApiTests.toString()); |
429 |
| - System.setProperty(CodegenConstants.API_DOCS, generateApiDocumentation.toString()); |
| 427 | + // do not override config if already present (e.g. config read from file) |
| 428 | + addCodegenArgumentIfAbsent(CodegenConstants.MODEL_TESTS_OPTION, "boolean", generateModelTests.toString(), configurator); |
| 429 | + addCodegenArgumentIfAbsent(CodegenConstants.API_TESTS_OPTION , "boolean", generateApiTests.toString(), configurator); |
| 430 | + addCodegenArgumentIfAbsent(CodegenConstants.MODEL_DOCS_OPTION, "boolean", generateModelDocumentation.toString(), configurator); |
| 431 | + addCodegenArgumentIfAbsent(CodegenConstants.API_DOCS_OPTION, "boolean", generateApiDocumentation.toString(), configurator); |
| 432 | + |
430 | 433 | System.setProperty(CodegenConstants.WITH_XML, withXml.toString());
|
431 | 434 |
|
432 | 435 | if (configOptions != null) {
|
@@ -519,7 +522,6 @@ public void execute() throws MojoExecutionException {
|
519 | 522 | configurator.addSystemProperty(key, value);
|
520 | 523 | }
|
521 | 524 | }
|
522 |
| - |
523 | 525 | final ClientOptInput input = configurator.toClientOptInput();
|
524 | 526 | final CodegenConfig config = input.getConfig();
|
525 | 527 |
|
@@ -578,4 +580,12 @@ private void addCompileSourceRootIfConfigured() {
|
578 | 580 | }
|
579 | 581 | }
|
580 | 582 | }
|
| 583 | + |
| 584 | + |
| 585 | + private void addCodegenArgumentIfAbsent(String option, String type, String value, CodegenConfigurator configurator) { |
| 586 | + if (configurator.getCodegenArguments().stream() |
| 587 | + .noneMatch(codegenArgument -> option.equals(codegenArgument.getOption()))) { |
| 588 | + configurator.getCodegenArguments().add(new CodegenArgument().option(option).type(type).value(value)); |
| 589 | + } |
| 590 | + } |
581 | 591 | }
|
0 commit comments