Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.0.0' into generator-issue-334
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMario committed Apr 22, 2019
2 parents 3967e6d + 305924c commit 07e2b7f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.List;
import java.util.Map;

import io.swagger.codegen.v3.CodegenArgument;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
Expand Down Expand Up @@ -423,10 +424,12 @@ public void execute() throws MojoExecutionException {
System.clearProperty(CodegenConstants.SUPPORTING_FILES);
}

System.setProperty(CodegenConstants.MODEL_TESTS, generateModelTests.toString());
System.setProperty(CodegenConstants.MODEL_DOCS, generateModelDocumentation.toString());
System.setProperty(CodegenConstants.API_TESTS, generateApiTests.toString());
System.setProperty(CodegenConstants.API_DOCS, generateApiDocumentation.toString());
// do not override config if already present (e.g. config read from file)
addCodegenArgumentIfAbsent(CodegenConstants.MODEL_TESTS_OPTION, "boolean", generateModelTests.toString(), configurator);
addCodegenArgumentIfAbsent(CodegenConstants.API_TESTS_OPTION , "boolean", generateApiTests.toString(), configurator);
addCodegenArgumentIfAbsent(CodegenConstants.MODEL_DOCS_OPTION, "boolean", generateModelDocumentation.toString(), configurator);
addCodegenArgumentIfAbsent(CodegenConstants.API_DOCS_OPTION, "boolean", generateApiDocumentation.toString(), configurator);

System.setProperty(CodegenConstants.WITH_XML, withXml.toString());

if (configOptions != null) {
Expand Down Expand Up @@ -519,7 +522,6 @@ public void execute() throws MojoExecutionException {
configurator.addSystemProperty(key, value);
}
}

final ClientOptInput input = configurator.toClientOptInput();
final CodegenConfig config = input.getConfig();

Expand Down Expand Up @@ -578,4 +580,12 @@ private void addCompileSourceRootIfConfigured() {
}
}
}


private void addCodegenArgumentIfAbsent(String option, String type, String value, CodegenConfigurator configurator) {
if (configurator.getCodegenArguments().stream()
.noneMatch(codegenArgument -> option.equals(codegenArgument.getOption()))) {
configurator.getCodegenArguments().add(new CodegenArgument().option(option).type(type).value(value));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -70,7 +71,7 @@ public class CodegenConfigurator implements Serializable {
private String artifactVersion;
private String library;
private String ignoreFileOverride;
private List<CodegenArgument> codegenArguments;
private List<CodegenArgument> codegenArguments = new ArrayList<>();
private Map<String, String> systemProperties = new HashMap<String, String>();
private Map<String, String> instantiationTypes = new HashMap<String, String>();
private Map<String, String> typeMappings = new HashMap<String, String>();
Expand Down Expand Up @@ -581,6 +582,10 @@ public void setCodegenArguments(List<CodegenArgument> codegenArguments) {
this.codegenArguments = codegenArguments;
}

public List<CodegenArgument> getCodegenArguments() {
return this.codegenArguments;
}

private void setSystemProperties() {
for (Map.Entry<String, String> entry : systemProperties.entrySet()) {
System.setProperty(entry.getKey(), entry.getValue());
Expand Down

0 comments on commit 07e2b7f

Please # to comment.