diff --git a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/SwaggerCodegen.java b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/SwaggerCodegen.java
index 1b73ec6e98cd..335e9a8e944c 100644
--- a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/SwaggerCodegen.java
+++ b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/SwaggerCodegen.java
@@ -10,12 +10,9 @@ import io.swagger.codegen.cmd.Validate;
import io.swagger.codegen.cmd.Version;
/**
- * User: lanwen
- * Date: 24.03.15
- * Time: 17:56
+ * User: lanwen Date: 24.03.15 Time: 17:56
*
- * Command line interface for swagger codegen
- * use `swagger-codegen-cli.jar help` for more info
+ * Command line interface for swagger codegen use `swagger-codegen-cli.jar help` for more info
*
* @since 2.1.3-M1
*/
@@ -25,20 +22,15 @@ public class SwaggerCodegen {
public static void main(String[] args) {
String version = Version.readVersionFromResources();
@SuppressWarnings("unchecked")
- Cli.CliBuilder builder = Cli.builder("swagger-codegen-cli")
- .withDescription(String.format(
- "Swagger code generator CLI (version %s). More info on swagger.io",
- version))
- .withDefaultCommand(Langs.class)
- .withCommands(
- Generate.class,
- Meta.class,
- Langs.class,
- Help.class,
- ConfigHelp.class,
- Validate.class,
- Version.class
- );
+ Cli.CliBuilder builder =
+ Cli.builder("swagger-codegen-cli")
+ .withDescription(
+ String.format(
+ "Swagger code generator CLI (version %s). More info on swagger.io",
+ version))
+ .withDefaultCommand(Langs.class)
+ .withCommands(Generate.class, Meta.class, Langs.class, Help.class,
+ ConfigHelp.class, Validate.class, Version.class);
builder.build().parse(args).run();
}
diff --git a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/ConfigHelp.java b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/ConfigHelp.java
index eb2f8afea922..1ff3dfbb84f1 100644
--- a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/ConfigHelp.java
+++ b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/ConfigHelp.java
@@ -20,7 +20,8 @@ public class ConfigHelp implements Runnable {
System.out.println("CONFIG OPTIONS");
for (CliOption langCliOption : config.cliOptions()) {
System.out.println("\t" + langCliOption.getOpt());
- System.out.println("\t " + langCliOption.getOptionHelp().replaceAll("\n", "\n\t "));
+ System.out.println("\t "
+ + langCliOption.getOptionHelp().replaceAll("\n", "\n\t "));
System.out.println();
}
}
diff --git a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Generate.java b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Generate.java
index 1f4e40185143..57a9cbe8af86 100644
--- a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Generate.java
+++ b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Generate.java
@@ -16,9 +16,7 @@ import java.util.ArrayList;
import java.util.List;
/**
- * User: lanwen
- * Date: 24.03.15
- * Time: 20:22
+ * User: lanwen Date: 24.03.15 Time: 20:22
*/
@Command(name = "generate", description = "Generate code with chosen lang")
@@ -45,173 +43,209 @@ public class Generate implements Runnable {
description = "folder containing the template files")
private String templateDir;
- @Option(name = {"-a", "--auth"}, title = "authorization",
- description = "adds authorization headers when fetching the swagger definitions remotely. " +
- "Pass in a URL-encoded string of name:header with a comma separating multiple values")
+ @Option(
+ name = {"-a", "--auth"},
+ title = "authorization",
+ description = "adds authorization headers when fetching the swagger definitions remotely. "
+ + "Pass in a URL-encoded string of name:header with a comma separating multiple values")
private String auth;
- @Option(name = {"-D"}, title = "system properties", description = "sets specified system properties in " +
- "the format of name=value,name=value (or multiple options, each with name=value)")
+ @Option(
+ name = {"-D"},
+ title = "system properties",
+ description = "sets specified system properties in "
+ + "the format of name=value,name=value (or multiple options, each with name=value)")
private List systemProperties = new ArrayList<>();
- @Option(name = {"-c", "--config"}, title = "configuration file", description = "Path to json configuration file. " +
- "File content should be in a json format {\"optionKey\":\"optionValue\", \"optionKey1\":\"optionValue1\"...} " +
- "Supported options can be different for each language. Run config-help -l {lang} command for language specific config options.")
+ @Option(
+ name = {"-c", "--config"},
+ title = "configuration file",
+ description = "Path to json configuration file. "
+ + "File content should be in a json format {\"optionKey\":\"optionValue\", \"optionKey1\":\"optionValue1\"...} "
+ + "Supported options can be different for each language. Run config-help -l {lang} command for language specific config options.")
private String configFile;
- @Option(name = {"-s", "--skip-overwrite"}, title = "skip overwrite", description = "specifies if the existing files should be " +
- "overwritten during the generation.")
+ @Option(name = {"-s", "--skip-overwrite"}, title = "skip overwrite",
+ description = "specifies if the existing files should be "
+ + "overwritten during the generation.")
private Boolean skipOverwrite;
- @Option(name = {"--api-package"}, title = "api package", description = CodegenConstants.API_PACKAGE_DESC)
+ @Option(name = {"--api-package"}, title = "api package",
+ description = CodegenConstants.API_PACKAGE_DESC)
private String apiPackage;
- @Option(name = {"--model-package"}, title = "model package", description = CodegenConstants.MODEL_PACKAGE_DESC)
+ @Option(name = {"--model-package"}, title = "model package",
+ description = CodegenConstants.MODEL_PACKAGE_DESC)
private String modelPackage;
- @Option(name = {"--model-name-prefix"}, title = "model name prefix", description = CodegenConstants.MODEL_NAME_PREFIX_DESC)
+ @Option(name = {"--model-name-prefix"}, title = "model name prefix",
+ description = CodegenConstants.MODEL_NAME_PREFIX_DESC)
private String modelNamePrefix;
- @Option(name = {"--model-name-suffix"}, title = "model name suffix", description = CodegenConstants.MODEL_NAME_SUFFIX_DESC)
+ @Option(name = {"--model-name-suffix"}, title = "model name suffix",
+ description = CodegenConstants.MODEL_NAME_SUFFIX_DESC)
private String modelNameSuffix;
- @Option(name = {"--instantiation-types"}, title = "instantiation types", description = "sets instantiation type mappings in the format of type=instantiatedType,type=instantiatedType." +
- "For example (in Java): array=ArrayList,map=HashMap. In other words array types will get instantiated as ArrayList in generated code."
- + " You can also have multiple occurrences of this option.")
+ @Option(
+ name = {"--instantiation-types"},
+ title = "instantiation types",
+ description = "sets instantiation type mappings in the format of type=instantiatedType,type=instantiatedType."
+ + "For example (in Java): array=ArrayList,map=HashMap. In other words array types will get instantiated as ArrayList in generated code."
+ + " You can also have multiple occurrences of this option.")
private List instantiationTypes = new ArrayList<>();
- @Option(name = {"--type-mappings"}, title = "type mappings", description = "sets mappings between swagger spec types and generated code types " +
- "in the format of swaggerType=generatedType,swaggerType=generatedType. For example: array=List,map=Map,string=String."
- + " You can also have multiple occurrences of this option.")
+ @Option(
+ name = {"--type-mappings"},
+ title = "type mappings",
+ description = "sets mappings between swagger spec types and generated code types "
+ + "in the format of swaggerType=generatedType,swaggerType=generatedType. For example: array=List,map=Map,string=String."
+ + " You can also have multiple occurrences of this option.")
private List typeMappings = new ArrayList<>();
- @Option(name = {"--additional-properties"}, title = "additional properties",
+ @Option(
+ name = {"--additional-properties"},
+ title = "additional properties",
description = "sets additional properties that can be referenced by the mustache templates in the format of name=value,name=value."
+ " You can also have multiple occurrences of this option.")
private List additionalProperties = new ArrayList<>();
- @Option(name = {"--language-specific-primitives"}, title = "language specific primitives",
+ @Option(
+ name = {"--language-specific-primitives"},
+ title = "language specific primitives",
description = "specifies additional language specific primitive types in the format of type1,type2,type3,type3. For example: String,boolean,Boolean,Double."
+ " You can also have multiple occurrences of this option.")
private List languageSpecificPrimitives = new ArrayList<>();
- @Option(name = {"--import-mappings"}, title = "import mappings",
+ @Option(
+ name = {"--import-mappings"},
+ title = "import mappings",
description = "specifies mappings between a given class and the import that should be used for that class in the format of type=import,type=import."
+ " You can also have multiple occurrences of this option.")
private List importMappings = new ArrayList<>();
- @Option(name = {"--invoker-package"}, title = "invoker package", description = CodegenConstants.INVOKER_PACKAGE_DESC)
+ @Option(name = {"--invoker-package"}, title = "invoker package",
+ description = CodegenConstants.INVOKER_PACKAGE_DESC)
private String invokerPackage;
@Option(name = {"--group-id"}, title = "group id", description = CodegenConstants.GROUP_ID_DESC)
private String groupId;
- @Option(name = {"--artifact-id"}, title = "artifact id", description = CodegenConstants.ARTIFACT_ID_DESC)
+ @Option(name = {"--artifact-id"}, title = "artifact id",
+ description = CodegenConstants.ARTIFACT_ID_DESC)
private String artifactId;
- @Option(name = {"--artifact-version"}, title = "artifact version", description = CodegenConstants.ARTIFACT_VERSION_DESC)
+ @Option(name = {"--artifact-version"}, title = "artifact version",
+ description = CodegenConstants.ARTIFACT_VERSION_DESC)
private String artifactVersion;
@Option(name = {"--library"}, title = "library", description = CodegenConstants.LIBRARY_DESC)
private String library;
-
- @Option(name = {"--git-user-id"}, title = "git user id", description = CodegenConstants.GIT_USER_ID_DESC)
+
+ @Option(name = {"--git-user-id"}, title = "git user id",
+ description = CodegenConstants.GIT_USER_ID_DESC)
private String gitUserId;
- @Option(name = {"--git-repo-id"}, title = "git repo id", description = CodegenConstants.GIT_REPO_ID_DESC)
+ @Option(name = {"--git-repo-id"}, title = "git repo id",
+ description = CodegenConstants.GIT_REPO_ID_DESC)
private String gitRepoId;
- @Option(name = {"--release-note"}, title = "release note", description = CodegenConstants.RELEASE_NOTE_DESC)
+ @Option(name = {"--release-note"}, title = "release note",
+ description = CodegenConstants.RELEASE_NOTE_DESC)
private String releaseNote;
- @Option(name = {"--http-user-agent"}, title = "http user agent", description = CodegenConstants.HTTP_USER_AGENT_DESC)
+ @Option(name = {"--http-user-agent"}, title = "http user agent",
+ description = CodegenConstants.HTTP_USER_AGENT_DESC)
private String httpUserAgent;
-
- @Option(name = {"--reserved-words-mappings"}, title = "reserved word mappings",
+
+ @Option(
+ name = {"--reserved-words-mappings"},
+ title = "reserved word mappings",
description = "specifies how a reserved name should be escaped to. Otherwise, the default _ is used. For example id=identifier."
+ " You can also have multiple occurrences of this option.")
private List reservedWordsMappings = new ArrayList<>();
- @Option(name = {"--ignore-file-override"}, title = "ignore file override location", description = CodegenConstants.IGNORE_FILE_OVERRIDE_DESC)
+ @Option(name = {"--ignore-file-override"}, title = "ignore file override location",
+ description = CodegenConstants.IGNORE_FILE_OVERRIDE_DESC)
private String ignoreFileOverride;
-
- @Option(name = {"--remove-operation-id-prefix"}, title = "remove prefix of the operationId", description = CodegenConstants.REMOVE_OPERATION_ID_PREFIX_DESC)
+
+ @Option(name = {"--remove-operation-id-prefix"}, title = "remove prefix of the operationId",
+ description = CodegenConstants.REMOVE_OPERATION_ID_PREFIX_DESC)
private Boolean removeOperationIdPrefix;
@Override
public void run() {
- //attempt to read from config file
+ // attempt to read from config file
CodegenConfigurator configurator = CodegenConfigurator.fromFile(configFile);
- //if a config file wasn't specified or we were unable to read it
- if(configurator == null) {
- //createa a fresh configurator
+ // if a config file wasn't specified or we were unable to read it
+ if (configurator == null) {
+ // createa a fresh configurator
configurator = new CodegenConfigurator();
}
- //now override with any specified parameters
+ // now override with any specified parameters
if (verbose != null) {
configurator.setVerbose(verbose);
}
- if(skipOverwrite != null) {
+ if (skipOverwrite != null) {
configurator.setSkipOverwrite(skipOverwrite);
}
- if(isNotEmpty(spec)) {
+ if (isNotEmpty(spec)) {
configurator.setInputSpec(spec);
}
- if(isNotEmpty(lang)) {
+ if (isNotEmpty(lang)) {
configurator.setLang(lang);
}
- if(isNotEmpty(output)) {
+ if (isNotEmpty(output)) {
configurator.setOutputDir(output);
}
- if(isNotEmpty(auth)) {
+ if (isNotEmpty(auth)) {
configurator.setAuth(auth);
}
- if(isNotEmpty(templateDir)) {
+ if (isNotEmpty(templateDir)) {
configurator.setTemplateDir(templateDir);
}
- if(isNotEmpty(apiPackage)) {
+ if (isNotEmpty(apiPackage)) {
configurator.setApiPackage(apiPackage);
}
- if(isNotEmpty(modelPackage)) {
+ if (isNotEmpty(modelPackage)) {
configurator.setModelPackage(modelPackage);
}
- if(isNotEmpty(modelNamePrefix)){
+ if (isNotEmpty(modelNamePrefix)) {
configurator.setModelNamePrefix(modelNamePrefix);
}
- if(isNotEmpty(modelNameSuffix)){
+ if (isNotEmpty(modelNameSuffix)) {
configurator.setModelNameSuffix(modelNameSuffix);
}
- if(isNotEmpty(invokerPackage)) {
+ if (isNotEmpty(invokerPackage)) {
configurator.setInvokerPackage(invokerPackage);
}
- if(isNotEmpty(groupId)) {
+ if (isNotEmpty(groupId)) {
configurator.setGroupId(groupId);
}
- if(isNotEmpty(artifactId)) {
+ if (isNotEmpty(artifactId)) {
configurator.setArtifactId(artifactId);
}
- if(isNotEmpty(artifactVersion)) {
+ if (isNotEmpty(artifactVersion)) {
configurator.setArtifactVersion(artifactVersion);
}
- if(isNotEmpty(library)) {
+ if (isNotEmpty(library)) {
configurator.setLibrary(library);
}
diff --git a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Langs.java b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Langs.java
index c3d7391579ed..007da38d2f68 100644
--- a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Langs.java
+++ b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Langs.java
@@ -9,15 +9,14 @@ import static ch.lambdaj.collection.LambdaCollections.with;
import static java.util.ServiceLoader.load;
/**
- * User: lanwen
- * Date: 24.03.15
- * Time: 20:25
+ * User: lanwen Date: 24.03.15 Time: 20:25
*/
@Command(name = "langs", description = "Shows available langs")
public class Langs implements Runnable {
@Override
public void run() {
- LambdaIterable langs = with(load(CodegenConfig.class)).extract(on(CodegenConfig.class).getName());
+ LambdaIterable langs =
+ with(load(CodegenConfig.class)).extract(on(CodegenConfig.class).getName());
System.out.printf("Available languages: %s%n", langs);
}
}
diff --git a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Meta.java b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Meta.java
index 3b5d71eec9fc..e52e121e8011 100644
--- a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Meta.java
+++ b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Meta.java
@@ -23,14 +23,12 @@ import static ch.lambdaj.collection.LambdaCollections.with;
import static com.google.common.base.Joiner.on;
/**
- * User: lanwen
- * Date: 24.03.15
- * Time: 20:22
+ * User: lanwen Date: 24.03.15 Time: 20:22
*/
-@Command(name = "meta", description = "MetaGenerator. Generator for creating a new template set " +
- "and configuration for Codegen. The output will be based on the language you " +
- "specify, and includes default templates to include.")
+@Command(name = "meta", description = "MetaGenerator. Generator for creating a new template set "
+ + "and configuration for Codegen. The output will be based on the language you "
+ + "specify, and includes default templates to include.")
public class Meta implements Runnable {
private static final Logger LOGGER = LoggerFactory.getLogger(Meta.class);
@@ -57,58 +55,62 @@ public class Meta implements Runnable {
String mainClass = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, name) + "Generator";
- List supportingFiles = ImmutableList.of(
- new SupportingFile("pom.mustache", "", "pom.xml"),
- new SupportingFile("generatorClass.mustache",
- on(File.separator).join("src/main/java", asPath(targetPackage)), mainClass.concat(".java")),
- new SupportingFile("README.mustache", "", "README.md"),
- new SupportingFile("api.template", "src/main/resources" + File.separator + name, "api.mustache"),
- new SupportingFile("model.template", "src/main/resources" + File.separator + name, "model.mustache"),
- new SupportingFile("services.mustache",
- "src/main/resources/META-INF/services", "io.swagger.codegen.CodegenConfig")
- );
+ List supportingFiles =
+ ImmutableList
+ .of(new SupportingFile("pom.mustache", "", "pom.xml"),
+ new SupportingFile("generatorClass.mustache", on(File.separator)
+ .join("src/main/java", asPath(targetPackage)), mainClass
+ .concat(".java")), new SupportingFile("README.mustache",
+ "", "README.md"), new SupportingFile("api.template",
+ "src/main/resources" + File.separator + name,
+ "api.mustache"), new SupportingFile("model.template",
+ "src/main/resources" + File.separator + name,
+ "model.mustache"), new SupportingFile("services.mustache",
+ "src/main/resources/META-INF/services",
+ "io.swagger.codegen.CodegenConfig"));
String swaggerVersion = Version.readVersionFromResources();
- Map data = new ImmutableMap.Builder()
- .put("generatorPackage", targetPackage)
- .put("generatorClass", mainClass)
- .put("name", name)
- .put("fullyQualifiedGeneratorClass", targetPackage + "." + mainClass)
- .put("swaggerCodegenVersion", swaggerVersion).build();
+ Map data =
+ new ImmutableMap.Builder().put("generatorPackage", targetPackage)
+ .put("generatorClass", mainClass).put("name", name)
+ .put("fullyQualifiedGeneratorClass", targetPackage + "." + mainClass)
+ .put("swaggerCodegenVersion", swaggerVersion).build();
with(supportingFiles).convert(processFiles(targetDir, data));
}
/**
- * Converter method to process supporting files: execute with mustache,
- * or simply copy to destination directory
+ * Converter method to process supporting files: execute with mustache, or simply copy to
+ * destination directory
*
* @param targetDir - destination directory
- * @param data - map with additional params needed to process templates
+ * @param data - map with additional params needed to process templates
* @return converter object to pass to lambdaj
*/
- private static Converter processFiles(final File targetDir, final Map data) {
+ private static Converter processFiles(final File targetDir,
+ final Map data) {
return new Converter() {
private DefaultGenerator generator = new DefaultGenerator();
@Override
public File convert(SupportingFile support) {
try {
- File destinationFolder = new File(new File(targetDir.getAbsolutePath()), support.folder);
+ File destinationFolder =
+ new File(new File(targetDir.getAbsolutePath()), support.folder);
File outputFile = new File(destinationFolder, support.destinationFilename);
- String template = generator
- .readTemplate(new File(TEMPLATE_DIR_CLASSPATH, support.templateFile).getPath());
+ String template =
+ generator.readTemplate(new File(TEMPLATE_DIR_CLASSPATH,
+ support.templateFile).getPath());
String formatted = template;
if (support.templateFile.endsWith(MUSTACHE_EXTENSION)) {
LOGGER.info("writing file to {}", outputFile.getAbsolutePath());
- formatted = Mustache.compiler().withLoader(loader(generator))
- .defaultValue("")
- .compile(template)
- .execute(data);
+ formatted =
+ Mustache.compiler().withLoader(loader(generator)).defaultValue("")
+ .compile(template).execute(data);
} else {
LOGGER.info("copying file to {}", outputFile.getAbsolutePath());
}
@@ -133,8 +135,8 @@ public class Meta implements Runnable {
return new Mustache.TemplateLoader() {
@Override
public Reader getTemplate(String name) {
- return generator.getTemplateReader(TEMPLATE_DIR_CLASSPATH
- + File.separator + name.concat(MUSTACHE_EXTENSION));
+ return generator.getTemplateReader(TEMPLATE_DIR_CLASSPATH + File.separator
+ + name.concat(MUSTACHE_EXTENSION));
}
};
}
diff --git a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Validate.java b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Validate.java
index 832e008f282a..9369926f351a 100644
--- a/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Validate.java
+++ b/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Validate.java
@@ -26,7 +26,7 @@ public class Validate implements Runnable {
List messageList = result.getMessages();
Set messages = new HashSet(messageList);
- for (String message: messages) {
+ for (String message : messages) {
System.out.println(message);
}
@@ -34,4 +34,4 @@ public class Validate implements Runnable {
throw new ValidateException();
}
}
-}
\ No newline at end of file
+}
diff --git a/modules/swagger-codegen-cli/src/test/java/io/swagger/codegen/cmd/GenerateTest.java b/modules/swagger-codegen-cli/src/test/java/io/swagger/codegen/cmd/GenerateTest.java
index 275c516ca621..55e87052df33 100644
--- a/modules/swagger-codegen-cli/src/test/java/io/swagger/codegen/cmd/GenerateTest.java
+++ b/modules/swagger-codegen-cli/src/test/java/io/swagger/codegen/cmd/GenerateTest.java
@@ -28,31 +28,40 @@ public class GenerateTest {
public void testVerbose() throws Exception {
setupAndRunGenericTest("-v");
- new FullVerifications() {{
- configurator.setVerbose(true);
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setVerbose(true);
+ times = 1;
+ }
+ };
setupAndRunGenericTest("--verbose");
- new FullVerifications() {{
- configurator.setVerbose(true);
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setVerbose(true);
+ times = 1;
+ }
+ };
}
@Test
public void testRequiredArgs_ShortArgs() throws Exception {
setupAndRunTest("-i", "swagger.yaml", "-l", "java", "-o", "src/main/java", false, null);
- new FullVerifications() {{
- }};
+ new FullVerifications() {
+ {
+ }
+ };
}
@Test
public void testRequiredArgs_LongArgs() throws Exception {
- setupAndRunTest("--input-spec", "swagger.yaml", "--lang", "java", "--output", "src/main/java", false, null);
- new FullVerifications() {{
- }};
+ setupAndRunTest("--input-spec", "swagger.yaml", "--lang", "java", "--output",
+ "src/main/java", false, null);
+ new FullVerifications() {
+ {
+ }
+ };
}
@Test
@@ -62,17 +71,21 @@ public class GenerateTest {
setupAndRunGenericTest("--template-dir", templateDir);
- new FullVerifications() {{
- configurator.setTemplateDir(templateDir);
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setTemplateDir(templateDir);
+ times = 1;
+ }
+ };
setupAndRunGenericTest("-t", templateDir);
- new FullVerifications() {{
- configurator.setTemplateDir(templateDir);
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setTemplateDir(templateDir);
+ times = 1;
+ }
+ };
}
@Test
@@ -82,24 +95,30 @@ public class GenerateTest {
setupAndRunGenericTest("--auth", auth);
- new FullVerifications() {{
- configurator.setAuth(auth);
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setAuth(auth);
+ times = 1;
+ }
+ };
setupAndRunGenericTest("-a", auth);
- new FullVerifications() {{
- configurator.setAuth(auth);
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setAuth(auth);
+ times = 1;
+ }
+ };
setupAndRunGenericTest();
- new FullVerifications() {{
- configurator.setAuth(anyString);
- times = 0;
- }};
+ new FullVerifications() {
+ {
+ configurator.setAuth(anyString);
+ times = 0;
+ }
+ };
}
@Test
@@ -107,92 +126,118 @@ public class GenerateTest {
setupAndRunGenericTest("-D", "hello=world,foo=bar");
- new FullVerifications() {{
- configurator.addSystemProperty("hello", "world");
- times = 1;
- configurator.addSystemProperty("foo", "bar");
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.addSystemProperty("hello", "world");
+ times = 1;
+ configurator.addSystemProperty("foo", "bar");
+ times = 1;
+ }
+ };
setupAndRunGenericTest("-Dhello=world,foo=bar");
- new FullVerifications() {{
- configurator.addSystemProperty("hello", "world");
- times = 1;
- configurator.addSystemProperty("foo", "bar");
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.addSystemProperty("hello", "world");
+ times = 1;
+ configurator.addSystemProperty("foo", "bar");
+ times = 1;
+ }
+ };
setupAndRunGenericTest("-D", "hello=world,key=,foo=bar");
- new FullVerifications() {{
- configurator.addSystemProperty("hello", "world");
- times = 1;
- configurator.addSystemProperty("foo", "bar");
- times = 1;
- configurator.addSystemProperty("key", "");
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.addSystemProperty("hello", "world");
+ times = 1;
+ configurator.addSystemProperty("foo", "bar");
+ times = 1;
+ configurator.addSystemProperty("key", "");
+ times = 1;
+ }
+ };
setupAndRunGenericTest("-D", "hello=world,key,foo=bar");
- new FullVerifications() {{
- configurator.addSystemProperty("hello", "world");
- times = 1;
- configurator.addSystemProperty("foo", "bar");
- times = 1;
- configurator.addSystemProperty("key", "");
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.addSystemProperty("hello", "world");
+ times = 1;
+ configurator.addSystemProperty("foo", "bar");
+ times = 1;
+ configurator.addSystemProperty("key", "");
+ times = 1;
+ }
+ };
setupAndRunGenericTest("-D", "hello=world", "-D", "key", "-D", "foo=bar");
- new FullVerifications() {{
- configurator.addSystemProperty("hello", "world");
- times = 1;
- configurator.addSystemProperty("foo", "bar");
- times = 1;
- configurator.addSystemProperty("key", "");
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.addSystemProperty("hello", "world");
+ times = 1;
+ configurator.addSystemProperty("foo", "bar");
+ times = 1;
+ configurator.addSystemProperty("key", "");
+ times = 1;
+ }
+ };
setupAndRunGenericTest("-Dhello=world", "-Dkey", "-Dfoo=bar");
- new FullVerifications() {{
- configurator.addSystemProperty("hello", "world");
- times = 1;
- configurator.addSystemProperty("foo", "bar");
- times = 1;
- configurator.addSystemProperty("key", "");
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.addSystemProperty("hello", "world");
+ times = 1;
+ configurator.addSystemProperty("foo", "bar");
+ times = 1;
+ configurator.addSystemProperty("key", "");
+ times = 1;
+ }
+ };
}
@Test
public void testConfig() throws Exception {
- setupAndRunTest("-i", "swagger.yaml", "-l", "java", "-o", "src/main/java", true, "config.json", "-c", "config.json");
+ setupAndRunTest("-i", "swagger.yaml", "-l", "java", "-o", "src/main/java", true,
+ "config.json", "-c", "config.json");
- new FullVerifications(){{}};
+ new FullVerifications() {
+ {
+ }
+ };
- setupAndRunTest("-i", "swagger.yaml", "-l", "java", "-o", "src/main/java", true, "config.json", "--config", "config.json");
+ setupAndRunTest("-i", "swagger.yaml", "-l", "java", "-o", "src/main/java", true,
+ "config.json", "--config", "config.json");
- new FullVerifications(){{}};
+ new FullVerifications() {
+ {
+ }
+ };
}
@Test
public void testSkipOverwrite() throws Exception {
setupAndRunGenericTest("-s");
- new FullVerifications(){{
- configurator.setSkipOverwrite(true); times=1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setSkipOverwrite(true);
+ times = 1;
+ }
+ };
setupAndRunGenericTest("--skip-overwrite");
- new FullVerifications(){{
- configurator.setSkipOverwrite(true); times=1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setSkipOverwrite(true);
+ times = 1;
+ }
+ };
}
@Test
@@ -200,9 +245,12 @@ public class GenerateTest {
final String value = "io.foo.bar.api";
setupAndRunGenericTest("--api-package", value);
- new FullVerifications(){{
- configurator.setApiPackage(value); times=1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setApiPackage(value);
+ times = 1;
+ }
+ };
}
@Test
@@ -210,9 +258,12 @@ public class GenerateTest {
final String value = "io.foo.bar.api";
setupAndRunGenericTest("--model-package", value);
- new FullVerifications(){{
- configurator.setModelPackage(value); times=1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setModelPackage(value);
+ times = 1;
+ }
+ };
}
@Test
@@ -220,145 +271,155 @@ public class GenerateTest {
setupAndRunGenericTest("--instantiation-types", "hello=world,key=,foo=bar,key2");
- new FullVerifications() {{
- configurator.addInstantiationType("hello", "world");
- times = 1;
- configurator.addInstantiationType("foo", "bar");
- times = 1;
- configurator.addInstantiationType("key", "");
- times = 1;
- configurator.addInstantiationType("key2", "");
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.addInstantiationType("hello", "world");
+ times = 1;
+ configurator.addInstantiationType("foo", "bar");
+ times = 1;
+ configurator.addInstantiationType("key", "");
+ times = 1;
+ configurator.addInstantiationType("key2", "");
+ times = 1;
+ }
+ };
- setupAndRunGenericTest("--instantiation-types", "hello=world",
- "--instantiation-types", "key=",
- "--instantiation-types", "foo=bar",
- "--instantiation-types", "key2");
+ setupAndRunGenericTest("--instantiation-types", "hello=world", "--instantiation-types",
+ "key=", "--instantiation-types", "foo=bar", "--instantiation-types", "key2");
- new FullVerifications() {{
- configurator.addInstantiationType("hello", "world");
- times = 1;
- configurator.addInstantiationType("foo", "bar");
- times = 1;
- configurator.addInstantiationType("key", "");
- times = 1;
- configurator.addInstantiationType("key2", "");
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.addInstantiationType("hello", "world");
+ times = 1;
+ configurator.addInstantiationType("foo", "bar");
+ times = 1;
+ configurator.addInstantiationType("key", "");
+ times = 1;
+ configurator.addInstantiationType("key2", "");
+ times = 1;
+ }
+ };
}
@Test
public void testTypeMappings() throws Exception {
setupAndRunGenericTest("--type-mappings", "hello=world,key=,foo=bar,key2");
- new FullVerifications() {{
- configurator.addTypeMapping("hello", "world");
- times = 1;
- configurator.addTypeMapping("foo", "bar");
- times = 1;
- configurator.addTypeMapping("key", "");
- times = 1;
- configurator.addTypeMapping("key2", "");
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.addTypeMapping("hello", "world");
+ times = 1;
+ configurator.addTypeMapping("foo", "bar");
+ times = 1;
+ configurator.addTypeMapping("key", "");
+ times = 1;
+ configurator.addTypeMapping("key2", "");
+ times = 1;
+ }
+ };
- setupAndRunGenericTest("--type-mappings", "hello=world",
- "--type-mappings", "key=",
- "--type-mappings", "foo=bar",
- "--type-mappings", "key2");
+ setupAndRunGenericTest("--type-mappings", "hello=world", "--type-mappings", "key=",
+ "--type-mappings", "foo=bar", "--type-mappings", "key2");
- new FullVerifications() {{
- configurator.addTypeMapping("hello", "world");
- times = 1;
- configurator.addTypeMapping("foo", "bar");
- times = 1;
- configurator.addTypeMapping("key", "");
- times = 1;
- configurator.addTypeMapping("key2", "");
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.addTypeMapping("hello", "world");
+ times = 1;
+ configurator.addTypeMapping("foo", "bar");
+ times = 1;
+ configurator.addTypeMapping("key", "");
+ times = 1;
+ configurator.addTypeMapping("key2", "");
+ times = 1;
+ }
+ };
}
@Test
public void testAdditionalProperties() throws Exception {
setupAndRunGenericTest("--additional-properties", "hello=world,key=,foo=bar,key2");
- new FullVerifications() {{
- configurator.addAdditionalProperty("hello", "world");
- times = 1;
- configurator.addAdditionalProperty("foo", "bar");
- times = 1;
- configurator.addAdditionalProperty("key", "");
- times = 1;
- configurator.addAdditionalProperty("key2", "");
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.addAdditionalProperty("hello", "world");
+ times = 1;
+ configurator.addAdditionalProperty("foo", "bar");
+ times = 1;
+ configurator.addAdditionalProperty("key", "");
+ times = 1;
+ configurator.addAdditionalProperty("key2", "");
+ times = 1;
+ }
+ };
- setupAndRunGenericTest("--additional-properties", "hello=world",
- "--additional-properties", "key=",
- "--additional-properties", "foo=bar",
- "--additional-properties", "key2");
+ setupAndRunGenericTest("--additional-properties", "hello=world", "--additional-properties",
+ "key=", "--additional-properties", "foo=bar", "--additional-properties", "key2");
- new FullVerifications() {{
- configurator.addAdditionalProperty("hello", "world");
- times = 1;
- configurator.addAdditionalProperty("foo", "bar");
- times = 1;
- configurator.addAdditionalProperty("key", "");
- times = 1;
- configurator.addAdditionalProperty("key2", "");
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.addAdditionalProperty("hello", "world");
+ times = 1;
+ configurator.addAdditionalProperty("foo", "bar");
+ times = 1;
+ configurator.addAdditionalProperty("key", "");
+ times = 1;
+ configurator.addAdditionalProperty("key2", "");
+ times = 1;
+ }
+ };
}
@Test
public void testLanguageSpecificPrimitives() throws Exception {
setupAndRunGenericTest("--language-specific-primitives", "foo,,bar",
- "--language-specific-primitives", "hello,world");
+ "--language-specific-primitives", "hello,world");
- new FullVerifications() {{
- configurator.addLanguageSpecificPrimitive("foo");
- times = 1;
- configurator.addLanguageSpecificPrimitive("bar");
- times = 1;
- configurator.addLanguageSpecificPrimitive("hello");
- times = 1;
- configurator.addLanguageSpecificPrimitive("world");
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.addLanguageSpecificPrimitive("foo");
+ times = 1;
+ configurator.addLanguageSpecificPrimitive("bar");
+ times = 1;
+ configurator.addLanguageSpecificPrimitive("hello");
+ times = 1;
+ configurator.addLanguageSpecificPrimitive("world");
+ times = 1;
+ }
+ };
}
@Test
public void testImportMappings() throws Exception {
setupAndRunGenericTest("--import-mappings", "hello=world,key=,foo=bar,key2");
- new FullVerifications() {{
- configurator.addImportMapping("hello", "world");
- times = 1;
- configurator.addImportMapping("foo", "bar");
- times = 1;
- configurator.addImportMapping("key", "");
- times = 1;
- configurator.addImportMapping("key2", "");
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.addImportMapping("hello", "world");
+ times = 1;
+ configurator.addImportMapping("foo", "bar");
+ times = 1;
+ configurator.addImportMapping("key", "");
+ times = 1;
+ configurator.addImportMapping("key2", "");
+ times = 1;
+ }
+ };
- setupAndRunGenericTest("--import-mappings", "hello=world",
- "--import-mappings", "key=",
- "--import-mappings", "foo=bar",
- "--import-mappings", "key2");
+ setupAndRunGenericTest("--import-mappings", "hello=world", "--import-mappings", "key=",
+ "--import-mappings", "foo=bar", "--import-mappings", "key2");
- new FullVerifications() {{
- configurator.addImportMapping("hello", "world");
- times = 1;
- configurator.addImportMapping("foo", "bar");
- times = 1;
- configurator.addImportMapping("key", "");
- times = 1;
- configurator.addImportMapping("key2", "");
- times = 1;
- }};
+ new FullVerifications() {
+ {
+ configurator.addImportMapping("hello", "world");
+ times = 1;
+ configurator.addImportMapping("foo", "bar");
+ times = 1;
+ configurator.addImportMapping("key", "");
+ times = 1;
+ configurator.addImportMapping("key2", "");
+ times = 1;
+ }
+ };
}
@Test
@@ -366,9 +427,12 @@ public class GenerateTest {
final String value = "io.foo.bar.api";
setupAndRunGenericTest("--invoker-package", value);
- new FullVerifications(){{
- configurator.setInvokerPackage(value); times=1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setInvokerPackage(value);
+ times = 1;
+ }
+ };
}
@Test
@@ -376,9 +440,12 @@ public class GenerateTest {
final String value = "io.foo.bar.api";
setupAndRunGenericTest("--group-id", value);
- new FullVerifications(){{
- configurator.setGroupId(value); times=1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setGroupId(value);
+ times = 1;
+ }
+ };
}
@Test
@@ -386,9 +453,12 @@ public class GenerateTest {
final String value = "awesome-api";
setupAndRunGenericTest("--artifact-id", value);
- new FullVerifications(){{
- configurator.setArtifactId(value); times=1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setArtifactId(value);
+ times = 1;
+ }
+ };
}
@Test
@@ -396,9 +466,12 @@ public class GenerateTest {
final String value = "1.2.3";
setupAndRunGenericTest("--artifact-version", value);
- new FullVerifications(){{
- configurator.setArtifactVersion(value); times=1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setArtifactVersion(value);
+ times = 1;
+ }
+ };
}
@Test
@@ -406,68 +479,81 @@ public class GenerateTest {
final String value = "library1";
setupAndRunGenericTest("--library", value);
- new FullVerifications(){{
- configurator.setLibrary(value); times=1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setLibrary(value);
+ times = 1;
+ }
+ };
}
- private void setupAndRunTest(String specFlag, final String spec, String langFlag, final String lang,
- String outputDirFlag, final String outputDir, boolean configuratorFromFile,
- final String configFile, String... additionalParameters) {
- final String[] commonArgs = {"generate", langFlag, lang, outputDirFlag, outputDir, specFlag, spec};
+ private void setupAndRunTest(String specFlag, final String spec, String langFlag,
+ final String lang, String outputDirFlag, final String outputDir,
+ boolean configuratorFromFile, final String configFile, String... additionalParameters) {
+ final String[] commonArgs =
+ {"generate", langFlag, lang, outputDirFlag, outputDir, specFlag, spec};
String[] argsToUse = ArrayUtils.addAll(commonArgs, additionalParameters);
if (configuratorFromFile) {
- new Expectations(){{
- CodegenConfigurator.fromFile(configFile);
- times = 1;
- result = configurator;
- }};
+ new Expectations() {
+ {
+ CodegenConfigurator.fromFile(configFile);
+ times = 1;
+ result = configurator;
+ }
+ };
} else {
- new Expectations() {{
- CodegenConfigurator.fromFile(anyString);
- result = null;
+ new Expectations() {
+ {
+ CodegenConfigurator.fromFile(anyString);
+ result = null;
- new CodegenConfigurator();
- times = 1;
- result = configurator;
- }};
+ new CodegenConfigurator();
+ times = 1;
+ result = configurator;
+ }
+ };
}
- new Expectations() {{
+ new Expectations() {
+ {
- configurator.toClientOptInput();
- times = 1;
- result = clientOptInput;
+ configurator.toClientOptInput();
+ times = 1;
+ result = clientOptInput;
- new DefaultGenerator();
- times = 1;
- result = generator;
+ new DefaultGenerator();
+ times = 1;
+ result = generator;
- generator.opts(clientOptInput);
- times = 1;
- result = generator;
+ generator.opts(clientOptInput);
+ times = 1;
+ result = generator;
- generator.generate();
- times = 1;
+ generator.generate();
+ times = 1;
- }};
+ }
+ };
SwaggerCodegen.main(argsToUse);
- new Verifications() {{
- configurator.setLang(lang);
- times = 1;
- configurator.setInputSpec(spec);
- times = 1;
- configurator.setOutputDir(outputDir);
- }};
+ new Verifications() {
+ {
+ configurator.setLang(lang);
+ times = 1;
+ configurator.setInputSpec(spec);
+ times = 1;
+ configurator.setOutputDir(outputDir);
+ }
+ };
}
private void setupAndRunGenericTest(String... additionalParameters) {
- setupAndRunTest("-i", "swagger.yaml", "-l", "java", "-o", "src/main/java", false, null, additionalParameters);
+ setupAndRunTest("-i", "swagger.yaml", "-l", "java", "-o", "src/main/java", false, null,
+ additionalParameters);
}
}
diff --git a/modules/swagger-codegen-cli/src/test/java/io/swagger/codegen/cmd/utils/OptionUtilsTest.java b/modules/swagger-codegen-cli/src/test/java/io/swagger/codegen/cmd/utils/OptionUtilsTest.java
index ec26a84be9d4..aade0dedf447 100644
--- a/modules/swagger-codegen-cli/src/test/java/io/swagger/codegen/cmd/utils/OptionUtilsTest.java
+++ b/modules/swagger-codegen-cli/src/test/java/io/swagger/codegen/cmd/utils/OptionUtilsTest.java
@@ -24,16 +24,19 @@ public class OptionUtilsTest {
@Test
public void testParseCommaSeparatedTuples() throws Exception {
- doTupleListTest("a=1,b=2,c=3", asList(Pair.of("a", "1"), Pair.of("b", "2"), Pair.of("c", "3")));
+ doTupleListTest("a=1,b=2,c=3",
+ asList(Pair.of("a", "1"), Pair.of("b", "2"), Pair.of("c", "3")));
doTupleListTest("xyz", asList(Pair.of("xyz", "")));
doTupleListTest("a=1,,c=3", asList(Pair.of("a", "1"), Pair.of("c", "3")));
- doTupleListTest("a=1,xyz=,c=3", asList(Pair.of("a", "1"), Pair.of("xyz", ""), Pair.of("c", "3")));
- doTupleListTest("a=1,xyz,c=3", asList(Pair.of("a", "1"), Pair.of("xyz", ""), Pair.of("c", "3")));
+ doTupleListTest("a=1,xyz=,c=3",
+ asList(Pair.of("a", "1"), Pair.of("xyz", ""), Pair.of("c", "3")));
+ doTupleListTest("a=1,xyz,c=3",
+ asList(Pair.of("a", "1"), Pair.of("xyz", ""), Pair.of("c", "3")));
doTupleListTest("a=1,=,c=3", asList(Pair.of("a", "1"), Pair.of("c", "3")));
doTupleListTest("", emptyPairList());
doTupleListTest(null, emptyPairList());
}
-
+
private static void doTupleListTest(String input, List> expectedResults) {
final List> result = OptionUtils.parseCommaSeparatedTuples(input);
assertNotNull(result);
@@ -45,10 +48,11 @@ public class OptionUtilsTest {
assertNotNull(result);
assertEquals(result, expectedResults);
}
- private static List> emptyPairList() {
+
+ private static List> emptyPairList() {
return Collections.emptyList();
}
-
+
private static List emptyList() {
return Collections.emptyList();
}
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 845a63190acf..5d415dbf0f7f 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
@@ -2,18 +2,16 @@ package io.swagger.codegen.plugin;
/*
* Copyright 2001-2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
*/
import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyAdditionalPropertiesKvp;
@@ -49,7 +47,7 @@ import io.swagger.codegen.config.CodegenConfigurator;
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
public class CodeGenMojo extends AbstractMojo {
- @Parameter(name="verbose", required = false, defaultValue = "false")
+ @Parameter(name = "verbose", required = false, defaultValue = "false")
private boolean verbose;
/**
@@ -61,8 +59,7 @@ public class CodeGenMojo extends AbstractMojo {
/**
* Location of the output directory.
*/
- @Parameter(name = "output",
- property = "swagger.codegen.maven.plugin.output",
+ @Parameter(name = "output", property = "swagger.codegen.maven.plugin.output",
defaultValue = "${project.build.directory}/generated-sources/swagger")
private File output;
@@ -91,10 +88,10 @@ public class CodeGenMojo extends AbstractMojo {
private File templateDirectory;
/**
- * Adds authorization headers when fetching the swagger definitions remotely.
- " Pass in a URL-encoded string of name:header with a comma separating multiple values
+ * Adds authorization headers when fetching the swagger definitions remotely. " Pass in a
+ * URL-encoded string of name:header with a comma separating multiple values
*/
- @Parameter(name="auth")
+ @Parameter(name = "auth")
private String auth;
/**
@@ -106,13 +103,13 @@ public class CodeGenMojo extends AbstractMojo {
/**
* Specifies if the existing files should be overwritten during the generation.
*/
- @Parameter(name="skipOverwrite", required=false)
+ @Parameter(name = "skipOverwrite", required = false)
private Boolean skipOverwrite;
/**
* Specifies if the existing files should be overwritten during the generation.
*/
- @Parameter(name="removeOperationIdPrefix", required=false)
+ @Parameter(name = "removeOperationIdPrefix", required = false)
private Boolean removeOperationIdPrefix;
/**
@@ -197,7 +194,7 @@ public class CodeGenMojo extends AbstractMojo {
private Boolean generateModels = true;
/**
- * A comma separated list of models to generate. All models is the default.
+ * A comma separated list of models to generate. All models is the default.
*/
@Parameter(name = "modelsToGenerate", required = false)
private String modelsToGenerate = "";
@@ -209,11 +206,11 @@ public class CodeGenMojo extends AbstractMojo {
private Boolean generateSupportingFiles = true;
/**
- * A comma separated list of models to generate. All models is the default.
+ * 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
*/
@@ -251,8 +248,8 @@ public class CodeGenMojo extends AbstractMojo {
private Boolean skip;
/**
- * 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.
+ * 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.
*/
@Parameter(defaultValue = "true")
private boolean addCompileSourceRoot = true;
@@ -277,7 +274,7 @@ public class CodeGenMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException {
- if(skip) {
+ if (skip) {
getLog().info("Code generation is skipped.");
// Even when no new sources are generated, the existing ones should
// still be compiled if needed.
@@ -285,37 +282,37 @@ public class CodeGenMojo extends AbstractMojo {
return;
}
- //attempt to read from config file
+ // attempt to read from config file
CodegenConfigurator configurator = CodegenConfigurator.fromFile(configurationFile);
- //if a config file wasn't specified or we were unable to read it
- if(configurator == null) {
+ // if a config file wasn't specified or we were unable to read it
+ if (configurator == null) {
configurator = new CodegenConfigurator();
}
configurator.setVerbose(verbose);
- if(skipOverwrite != null) {
+ if (skipOverwrite != null) {
configurator.setSkipOverwrite(skipOverwrite);
}
- if(removeOperationIdPrefix != null) {
+ if (removeOperationIdPrefix != null) {
configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix);
}
- if(isNotEmpty(inputSpec)) {
+ if (isNotEmpty(inputSpec)) {
configurator.setInputSpec(inputSpec);
}
- if(isNotEmpty(gitUserId)) {
+ if (isNotEmpty(gitUserId)) {
configurator.setGitUserId(gitUserId);
}
- if(isNotEmpty(gitRepoId)) {
+ if (isNotEmpty(gitRepoId)) {
configurator.setGitRepoId(gitRepoId);
}
- if(isNotEmpty(ignoreFileOverride)) {
+ if (isNotEmpty(ignoreFileOverride)) {
configurator.setIgnoreFileOverride(ignoreFileOverride);
}
@@ -323,43 +320,43 @@ public class CodeGenMojo extends AbstractMojo {
configurator.setOutputDir(output.getAbsolutePath());
- if(isNotEmpty(auth)) {
+ if (isNotEmpty(auth)) {
configurator.setAuth(auth);
}
- if(isNotEmpty(apiPackage)) {
+ if (isNotEmpty(apiPackage)) {
configurator.setApiPackage(apiPackage);
}
- if(isNotEmpty(modelPackage)) {
+ if (isNotEmpty(modelPackage)) {
configurator.setModelPackage(modelPackage);
}
- if(isNotEmpty(invokerPackage)) {
+ if (isNotEmpty(invokerPackage)) {
configurator.setInvokerPackage(invokerPackage);
}
- if(isNotEmpty(groupId)) {
+ if (isNotEmpty(groupId)) {
configurator.setGroupId(groupId);
}
- if(isNotEmpty(artifactId)) {
+ if (isNotEmpty(artifactId)) {
configurator.setArtifactId(artifactId);
}
- if(isNotEmpty(artifactVersion)) {
+ if (isNotEmpty(artifactVersion)) {
configurator.setArtifactVersion(artifactVersion);
}
- if(isNotEmpty(library)) {
+ if (isNotEmpty(library)) {
configurator.setLibrary(library);
}
- if(isNotEmpty(modelNamePrefix)) {
+ if (isNotEmpty(modelNamePrefix)) {
configurator.setModelNamePrefix(modelNamePrefix);
}
- if(isNotEmpty(modelNameSuffix)) {
+ if (isNotEmpty(modelNameSuffix)) {
configurator.setModelNameSuffix(modelNameSuffix);
}
@@ -385,7 +382,7 @@ public class CodeGenMojo extends AbstractMojo {
} else {
System.clearProperty("supportingFiles");
}
-
+
System.setProperty("modelTests", generateModelTests.toString());
System.setProperty("modelDocs", generateModelDocumentation.toString());
System.setProperty("apiTests", generateApiTests.toString());
@@ -394,42 +391,49 @@ public class CodeGenMojo extends AbstractMojo {
if (configOptions != null) {
- if(configOptions.containsKey("instantiation-types")) {
- applyInstantiationTypesKvp(configOptions.get("instantiation-types").toString(), configurator);
+ if (configOptions.containsKey("instantiation-types")) {
+ applyInstantiationTypesKvp(configOptions.get("instantiation-types").toString(),
+ configurator);
}
- if(importMappings == null && configOptions.containsKey("import-mappings")) {
- applyImportMappingsKvp(configOptions.get("import-mappings").toString(), configurator);
+ if (importMappings == null && configOptions.containsKey("import-mappings")) {
+ applyImportMappingsKvp(configOptions.get("import-mappings").toString(),
+ configurator);
}
- if(configOptions.containsKey("type-mappings")) {
+ if (configOptions.containsKey("type-mappings")) {
applyTypeMappingsKvp(configOptions.get("type-mappings").toString(), configurator);
}
- if(configOptions.containsKey("language-specific-primitives")) {
- applyLanguageSpecificPrimitivesCsv(configOptions.get("language-specific-primitives").toString(), configurator);
+ if (configOptions.containsKey("language-specific-primitives")) {
+ applyLanguageSpecificPrimitivesCsv(configOptions
+ .get("language-specific-primitives").toString(), configurator);
}
- if(configOptions.containsKey("additional-properties")) {
- applyAdditionalPropertiesKvp(configOptions.get("additional-properties").toString(), configurator);
+ if (configOptions.containsKey("additional-properties")) {
+ applyAdditionalPropertiesKvp(configOptions.get("additional-properties").toString(),
+ configurator);
}
- if(configOptions.containsKey("reserved-words-mappings")) {
- applyReservedWordsMappingsKvp(configOptions.get("reserved-words-mappings").toString(), configurator);
+ if (configOptions.containsKey("reserved-words-mappings")) {
+ applyReservedWordsMappingsKvp(configOptions.get("reserved-words-mappings")
+ .toString(), configurator);
}
}
if (importMappings != null && !configOptions.containsKey("import-mappings")) {
String importMappingsAsString = importMappings.toString();
- applyImportMappingsKvp(importMappingsAsString.substring(0, importMappingsAsString.length() - 1), configurator);
+ applyImportMappingsKvp(
+ importMappingsAsString.substring(0, importMappingsAsString.length() - 1),
+ configurator);
}
if (environmentVariables != null) {
- for(String key : environmentVariables.keySet()) {
+ for (String key : environmentVariables.keySet()) {
originalEnvironmentVariables.put(key, System.getProperty(key));
String value = environmentVariables.get(key);
- if(value == null) {
+ if (value == null) {
// don't put null values
value = "";
}
@@ -437,23 +441,24 @@ public class CodeGenMojo extends AbstractMojo {
configurator.addSystemProperty(key, value);
}
}
-
+
final ClientOptInput input = configurator.toClientOptInput();
final CodegenConfig config = input.getConfig();
- if(configOptions != null) {
+ if (configOptions != null) {
for (CliOption langCliOption : config.cliOptions()) {
if (configOptions.containsKey(langCliOption.getOpt())) {
- input.getConfig().additionalProperties().put(langCliOption.getOpt(),
- configOptions.get(langCliOption.getOpt()));
+ input.getConfig().additionalProperties()
+ .put(langCliOption.getOpt(), configOptions.get(langCliOption.getOpt()));
}
}
}
- if(configHelp) {
+ if (configHelp) {
for (CliOption langCliOption : config.cliOptions()) {
System.out.println("\t" + langCliOption.getOpt());
- System.out.println("\t " + langCliOption.getOptionHelp().replaceAll("\n", "\n\t "));
+ System.out.println("\t "
+ + langCliOption.getOptionHelp().replaceAll("\n", "\n\t "));
System.out.println();
}
return;
@@ -464,26 +469,31 @@ public class CodeGenMojo extends AbstractMojo {
// Maven logs exceptions thrown by plugins only if invoked with -e
// I find it annoying to jump through hoops to get basic diagnostic information,
// so let's log it in any case:
- getLog().error(e);
- throw new MojoExecutionException("Code generation failed. See above for the full exception.");
+ getLog().error(e);
+ throw new MojoExecutionException(
+ "Code generation failed. See above for the full exception.");
}
addCompileSourceRootIfConfigured();
}
private void addCompileSourceRootIfConfigured() {
- if(addCompileSourceRoot) {
- final Object sourceFolderObject = configOptions == null ? null : configOptions.get(CodegenConstants.SOURCE_FOLDER);
- final String sourceFolder = sourceFolderObject == null ? "src/main/java" : sourceFolderObject.toString();
+ if (addCompileSourceRoot) {
+ final Object sourceFolderObject =
+ configOptions == null ? null : configOptions
+ .get(CodegenConstants.SOURCE_FOLDER);
+ final String sourceFolder =
+ sourceFolderObject == null ? "src/main/java" : sourceFolderObject.toString();
String sourceJavaFolder = output.toString() + "/" + sourceFolder;
project.addCompileSourceRoot(sourceJavaFolder);
}
- // Reset all environment variables to their original value. This prevents unexpected behaviour
+ // Reset all environment variables to their original value. This prevents unexpected
+ // behaviour
// when running the plugin multiple consecutive times with different configurations.
- for(Map.Entry entry : originalEnvironmentVariables.entrySet()) {
- if(entry.getValue() == null) {
+ for (Map.Entry entry : originalEnvironmentVariables.entrySet()) {
+ if (entry.getValue() == null) {
System.clearProperty(entry.getKey());
} else {
System.setProperty(entry.getKey(), entry.getValue());