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 94b64be8d02..cfdbd91851d 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
@@ -9,12 +9,9 @@
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
*/
@@ -24,19 +21,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,
- 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, 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 eb2f8afea92..1ff3dfbb84f 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 void run() {
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 01303e64559..b5bccaa9811 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
@@ -13,9 +13,7 @@
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
/**
- * 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")
@@ -42,163 +40,197 @@ 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")
+ @Option(name = {"-D"}, title = "system properties",
+ description = "sets specified system properties in "
+ + "the format of name=value,name=value")
private String systemProperties;
- @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.")
+ @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.")
private String instantiationTypes;
- @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")
+ @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")
private String typeMappings;
- @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")
+ @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")
private String additionalProperties;
- @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")
private String languageSpecificPrimitives;
- @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")
private String importMappings;
- @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 = "import mappings",
+
+ @Option(
+ name = {"--reserved-words-mappings"},
+ title = "import mappings",
description = "specifies how a reserved name should be escaped to. Otherwise, the default _ is used. For example id=identifier")
private String reservedWordsMappings;
- @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;
-
+
@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 c3d7391579e..007da38d2f6 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 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 3b5d71eec9f..e52e121e801 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 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 void run() {
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 @@ private static Mustache.TemplateLoader loader(final DefaultGenerator generator)
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/test/java/io/swagger/codegen/cmd/GenerateTest.java b/modules/swagger-codegen-cli/src/test/java/io/swagger/codegen/cmd/GenerateTest.java
index 36a560b776d..397495927d4 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 void testTemplateDir() throws Exception {
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 void testAuth() throws Exception {
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,50 +126,68 @@ public void testSystemProperties() throws Exception {
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("-D", "hello=world,key=,foo=bar");
- new FullVerifications() {{
- configurator.addSystemProperty("hello", "world");
- times = 1;
- configurator.addSystemProperty("foo", "bar");
- times = 1;
- configurator.addSystemProperty("key", anyString);
- times = 0;
- }};
+ new FullVerifications() {
+ {
+ configurator.addSystemProperty("hello", "world");
+ times = 1;
+ configurator.addSystemProperty("foo", "bar");
+ times = 1;
+ configurator.addSystemProperty("key", anyString);
+ times = 0;
+ }
+ };
}
@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
@@ -158,9 +195,12 @@ public void testApiPackage() throws Exception {
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
@@ -168,9 +208,12 @@ public void testModelPackage() throws Exception {
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
@@ -178,72 +221,82 @@ public void testInstantiationTypes() throws Exception {
setupAndRunGenericTest("--instantiation-types", "hello=world,key=,foo=bar");
- new FullVerifications() {{
- configurator.addInstantiationType("hello", "world");
- times = 1;
- configurator.addInstantiationType("foo", "bar");
- times = 1;
- configurator.addInstantiationType("key", anyString);
- times = 0;
- }};
+ new FullVerifications() {
+ {
+ configurator.addInstantiationType("hello", "world");
+ times = 1;
+ configurator.addInstantiationType("foo", "bar");
+ times = 1;
+ configurator.addInstantiationType("key", anyString);
+ times = 0;
+ }
+ };
}
@Test
public void testTypeMappings() throws Exception {
setupAndRunGenericTest("--type-mappings", "hello=world,key=,foo=bar");
- new FullVerifications() {{
- configurator.addTypeMapping("hello", "world");
- times = 1;
- configurator.addTypeMapping("foo", "bar");
- times = 1;
- configurator.addTypeMapping("key", anyString);
- times = 0;
- }};
+ new FullVerifications() {
+ {
+ configurator.addTypeMapping("hello", "world");
+ times = 1;
+ configurator.addTypeMapping("foo", "bar");
+ times = 1;
+ configurator.addTypeMapping("key", anyString);
+ times = 0;
+ }
+ };
}
@Test
public void testAdditionalProperties() throws Exception {
setupAndRunGenericTest("--additional-properties", "hello=world,key=,foo=bar");
- new FullVerifications() {{
- configurator.addAdditionalProperty("hello", "world");
- times = 1;
- configurator.addAdditionalProperty("foo", "bar");
- times = 1;
- configurator.addAdditionalProperty("key", anyString);
- times = 0;
- }};
+ new FullVerifications() {
+ {
+ configurator.addAdditionalProperty("hello", "world");
+ times = 1;
+ configurator.addAdditionalProperty("foo", "bar");
+ times = 1;
+ configurator.addAdditionalProperty("key", anyString);
+ times = 0;
+ }
+ };
}
@Test
public void testLanguageSpecificPrimitives() throws Exception {
setupAndRunGenericTest("--language-specific-primitives", "foo,bar,,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");
- new FullVerifications() {{
- configurator.addImportMapping("hello", "world");
- times = 1;
- configurator.addImportMapping("foo", "bar");
- times = 1;
- configurator.addImportMapping("key", anyString);
- times = 0;
- }};
+ new FullVerifications() {
+ {
+ configurator.addImportMapping("hello", "world");
+ times = 1;
+ configurator.addImportMapping("foo", "bar");
+ times = 1;
+ configurator.addImportMapping("key", anyString);
+ times = 0;
+ }
+ };
}
@Test
@@ -251,9 +304,12 @@ public void testInvokerPackage() throws Exception {
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
@@ -261,9 +317,12 @@ public void testGroupId() throws Exception {
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
@@ -271,9 +330,12 @@ public void testArtifactId() throws Exception {
final String value = "awesome-api";
setupAndRunGenericTest("--artifact-id", value);
- new FullVerifications(){{
- configurator.setArtifactId(value); times=1;
- }};
+ new FullVerifications() {
+ {
+ configurator.setArtifactId(value);
+ times = 1;
+ }
+ };
}
@Test
@@ -281,9 +343,12 @@ public void testArtifactVersion() throws Exception {
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
@@ -291,68 +356,81 @@ public void testLibrary() throws Exception {
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 CodegenConfigurator();
- times = 1;
- result = configurator;
- }};
+ new Expectations() {
+ {
+ CodegenConfigurator.fromFile(anyString);
+ result = null;
+
+ 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 db88cdcdb9d..292a5d5520e 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,7 +24,8 @@ public void splitCommaSeparatedList() throws Exception {
@Test
public void testParseCommaSeparatedTuples() throws Exception {
- doTupleListTest("a=1,b=2,c=3", Arrays.asList(Pair.of("a", "1"), Pair.of("b", "2"), Pair.of("c", "3")));
+ doTupleListTest("a=1,b=2,c=3",
+ Arrays.asList(Pair.of("a", "1"), Pair.of("b", "2"), Pair.of("c", "3")));
doTupleListTest("a=1,,c=3", Arrays.asList(Pair.of("a", "1"), Pair.of("c", "3")));
doTupleListTest("a=1,xyz,c=3", Arrays.asList(Pair.of("a", "1"), Pair.of("c", "3")));
doTupleListTest("a=1,=,c=3", Arrays.asList(Pair.of("a", "1"), Pair.of("c", "3")));
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..e681a940fa1 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 @@
/*
* 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;
@@ -48,7 +46,7 @@
@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;
/**
@@ -60,8 +58,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;
@@ -90,10 +87,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;
/**
@@ -105,7 +102,7 @@ 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;
/**
@@ -175,8 +172,8 @@ public class CodeGenMojo extends AbstractMojo {
private Map, ?> configOptions;
/**
- * 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;
@@ -196,33 +193,33 @@ public class CodeGenMojo extends AbstractMojo {
@Override
public void execute() throws MojoExecutionException {
- //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(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);
}
@@ -230,43 +227,43 @@ public void execute() throws MojoExecutionException {
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);
}
@@ -276,36 +273,41 @@ public void execute() throws MojoExecutionException {
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(configOptions.containsKey("import-mappings")) {
- applyImportMappingsKvp(configOptions.get("import-mappings").toString(), configurator);
+ if (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 (environmentVariables != null) {
- for(String key : environmentVariables.keySet()) {
+ for (String key : environmentVariables.keySet()) {
String value = environmentVariables.get(key);
- if(value == null) {
+ if (value == null) {
// don't put null values
value = "";
}
@@ -313,23 +315,24 @@ public void execute() throws MojoExecutionException {
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;
@@ -340,13 +343,17 @@ public void execute() throws MojoExecutionException {
// 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.");
}
if (addCompileSourceRoot) {
- final Object sourceFolderObject = configOptions == null ? null : configOptions.get(CodegenConstants.SOURCE_FOLDER);
- final String sourceFolder = sourceFolderObject == null ? "src/main/java" : sourceFolderObject.toString();
+ 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);
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/AbstractGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/AbstractGenerator.java
index abf77b59cb1..94ae8390ebd 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/AbstractGenerator.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/AbstractGenerator.java
@@ -28,8 +28,8 @@ public File writeToFile(String filename, String contents) throws IOException {
File parent = new File(output.getParent());
parent.mkdirs();
}
- Writer out = new BufferedWriter(new OutputStreamWriter(
- new FileOutputStream(output), "UTF-8"));
+ Writer out =
+ new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output), "UTF-8"));
out.write(contents);
out.close();
@@ -52,7 +52,8 @@ public String readTemplate(String name) {
public Reader getTemplateReader(String name) {
try {
- InputStream is = this.getClass().getClassLoader().getResourceAsStream(getCPResourcePath(name));
+ InputStream is =
+ this.getClass().getClassLoader().getResourceAsStream(getCPResourcePath(name));
if (is == null) {
is = new FileInputStream(new File(name)); // May throw but never return a null value
}
@@ -64,8 +65,8 @@ public Reader getTemplateReader(String name) {
}
/**
- * Get the template file path with template dir prepended, and use the
- * library template if exists.
+ * Get the template file path with template dir prepended, and use the library template if
+ * exists.
*
* @param config Codegen config
* @param templateFile Template file
@@ -78,9 +79,9 @@ public String getFullTemplateFile(CodegenConfig config, String templateFile) {
} else {
String library = config.getLibrary();
if (library != null && !"".equals(library)) {
- String libTemplateFile = config.embeddedTemplateDir() + File.separator +
- "libraries" + File.separator + library + File.separator +
- templateFile;
+ String libTemplateFile =
+ config.embeddedTemplateDir() + File.separator + "libraries"
+ + File.separator + library + File.separator + templateFile;
if (embeddedTemplateExists(libTemplateFile)) {
// Fall back to the template file embedded/packaged in the JAR file...
return libTemplateFile;
@@ -93,7 +94,9 @@ public String getFullTemplateFile(CodegenConfig config, String templateFile) {
public String readResourceContents(String resourceFilePath) {
StringBuilder sb = new StringBuilder();
- Scanner scanner = new Scanner(this.getClass().getResourceAsStream(getCPResourcePath(resourceFilePath)), "UTF-8");
+ Scanner scanner =
+ new Scanner(this.getClass()
+ .getResourceAsStream(getCPResourcePath(resourceFilePath)), "UTF-8");
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
sb.append(line).append('\n');
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CliOption.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CliOption.java
index aacae1808e0..8d18af3c40c 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CliOption.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CliOption.java
@@ -80,7 +80,8 @@ public void setEnum(Map enumValues) {
}
public static CliOption newBoolean(String opt, String description) {
- return new CliOption(opt, description, BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString());
+ return new CliOption(opt, description, BooleanProperty.TYPE).defaultValue(Boolean.FALSE
+ .toString());
}
public static CliOption newString(String opt, String description) {
@@ -90,7 +91,7 @@ public static CliOption newString(String opt, String description) {
@JsonIgnore
public String getOptionHelp() {
StringBuilder sb = new StringBuilder(description);
- if(defaultValue != null) {
+ if (defaultValue != null) {
sb.append(" (Default: ").append(defaultValue).append(")");
}
if (enumValues != null) {
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/ClientOptInput.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/ClientOptInput.java
index 57918dd9b35..5d1d7ef0913 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/ClientOptInput.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/ClientOptInput.java
@@ -73,4 +73,4 @@ public Swagger getSwagger() {
public void setSwagger(Swagger swagger) {
this.swagger = swagger;
}
-}
\ No newline at end of file
+}
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/ClientOpts.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/ClientOpts.java
index 172a057ea43..022a814ece5 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/ClientOpts.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/ClientOpts.java
@@ -57,8 +57,10 @@ public String toString() {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
ClientOpts that = (ClientOpts) o;
@@ -70,7 +72,8 @@ public boolean equals(Object o) {
return false;
if (properties != null ? !properties.equals(that.properties) : that.properties != null)
return false;
- return outputDirectory != null ? outputDirectory.equals(that.outputDirectory) : that.outputDirectory == null;
+ return outputDirectory != null ? outputDirectory.equals(that.outputDirectory)
+ : that.outputDirectory == null;
}
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/Codegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/Codegen.java
index 839f0800e15..19fc8f3e828 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/Codegen.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/Codegen.java
@@ -20,8 +20,8 @@
import io.swagger.parser.SwaggerParser;
/**
- * @deprecated use instead {@link io.swagger.codegen.DefaultGenerator}
- * or cli interface from https://github.com/swagger-api/swagger-codegen/pull/547
+ * @deprecated use instead {@link io.swagger.codegen.DefaultGenerator} or cli interface from
+ * https://github.com/swagger-api/swagger-codegen/pull/547
*/
@Deprecated
public class Codegen extends DefaultGenerator {
@@ -30,23 +30,30 @@ public class Codegen extends DefaultGenerator {
static Map configs = new HashMap();
static String configString;
- static String debugInfoOptions = "\nThe following additional debug options are available for all codegen targets:" +
- "\n -DdebugSwagger prints the swagger specification as interpreted by the codegen" +
- "\n -DdebugModels prints models passed to the template engine" +
- "\n -DdebugOperations prints operations passed to the template engine" +
- "\n -DdebugSupportingFiles prints additional data passed to the template engine";
+ static String debugInfoOptions =
+ "\nThe following additional debug options are available for all codegen targets:"
+ + "\n -DdebugSwagger prints the swagger specification as interpreted by the codegen"
+ + "\n -DdebugModels prints models passed to the template engine"
+ + "\n -DdebugOperations prints operations passed to the template engine"
+ + "\n -DdebugSupportingFiles prints additional data passed to the template engine";
@SuppressWarnings("deprecation")
public static void main(String[] args) {
Options options = new Options();
options.addOption("h", "help", false, "shows this message");
- options.addOption("l", "lang", true, "client language to generate.\nAvailable languages include:\n\t[" + configString + "]");
+ options.addOption("l", "lang", true,
+ "client language to generate.\nAvailable languages include:\n\t[" + configString
+ + "]");
options.addOption("o", "output", true, "where to write the generated files");
options.addOption("i", "input-spec", true, "location of the swagger spec, as URL or file");
options.addOption("t", "template-dir", true, "folder containing the template files");
options.addOption("d", "debug-info", false, "prints additional info for debugging");
- options.addOption("a", "auth", true, "adds authorization headers when fetching the swagger definitions remotely. Pass in a URL-encoded string of name:header with a comma separating multiple values");
+ options.addOption(
+ "a",
+ "auth",
+ true,
+ "adds authorization headers when fetching the swagger definitions remotely. Pass in a URL-encoded string of name:header with a comma separating multiple values");
options.addOption("c", "config", true, "location of the configuration file");
ClientOptInput clientOptInput = new ClientOptInput();
@@ -89,7 +96,9 @@ public static void main(String[] args) {
return;
}
if (cmd.hasOption("i")) {
- swagger = new SwaggerParser().read(cmd.getOptionValue("i"), clientOptInput.getAuthorizationValues(), true);
+ swagger =
+ new SwaggerParser().read(cmd.getOptionValue("i"),
+ clientOptInput.getAuthorizationValues(), true);
}
if (cmd.hasOption("c")) {
String configFile = cmd.getOptionValue("c");
@@ -98,22 +107,22 @@ public static void main(String[] args) {
if (null != genConfig && null != config) {
for (CliOption langCliOption : config.cliOptions()) {
if (genConfig.hasOption(langCliOption.getOpt())) {
- config.additionalProperties().put(langCliOption.getOpt(), genConfig.getOption(langCliOption.getOpt()));
+ config.additionalProperties().put(langCliOption.getOpt(),
+ genConfig.getOption(langCliOption.getOpt()));
}
}
}
}
if (cmd.hasOption("t")) {
- clientOpts.getProperties().put(CodegenConstants.TEMPLATE_DIR, String.valueOf(cmd.getOptionValue("t")));
+ clientOpts.getProperties().put(CodegenConstants.TEMPLATE_DIR,
+ String.valueOf(cmd.getOptionValue("t")));
}
} catch (Exception e) {
usage(options);
return;
}
try {
- clientOptInput
- .opts(clientOpts)
- .swagger(swagger);
+ clientOptInput.opts(clientOpts).swagger(swagger);
new Codegen().opts(clientOptInput).generate();
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java
index 4ffb9558230..a03b9ffb96e 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java
@@ -14,13 +14,13 @@
public interface CodegenConfig {
CodegenType getTag();
-
+
String getName();
String getHelp();
Map additionalProperties();
-
+
Map vendorExtensions();
String testPackage();
@@ -91,9 +91,11 @@ public interface CodegenConfig {
CodegenModel fromModel(String name, Model model, Map allDefinitions);
- CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map definitions, Swagger swagger);
-
- CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map definitions);
+ CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation,
+ Map definitions, Swagger swagger);
+
+ CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation,
+ Map definitions);
List fromSecurity(Map schemes);
@@ -118,7 +120,7 @@ public interface CodegenConfig {
Map modelDocTemplateFiles();
Set languageSpecificPrimitives();
-
+
Map reservedWordsMappings();
void preprocessSwagger(Swagger swagger);
@@ -136,19 +138,20 @@ public interface CodegenConfig {
String toApiTestFilename(String name);
String toModelTestFilename(String name);
-
+
String toApiDocFilename(String name);
String toModelDocFilename(String name);
-
+
String toModelImport(String name);
String toApiImport(String name);
- void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map> operations);
+ void addOperationToGroup(String tag, String resourcePath, Operation operation,
+ CodegenOperation co, Map> operations);
Map postProcessAllModels(Map objs);
-
+
Map postProcessModels(Map objs);
Map postProcessOperations(Map objs);
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfigLoader.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfigLoader.java
index 45a57e7bb3a..c77d5a483ba 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfigLoader.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfigLoader.java
@@ -28,7 +28,8 @@ public static CodegenConfig forName(String name) {
try {
return (CodegenConfig) Class.forName(name).newInstance();
} catch (Exception e) {
- throw new RuntimeException("Can't load config class with name ".concat(name) + " Available: " + availableConfigs.toString(), e);
+ throw new RuntimeException("Can't load config class with name ".concat(name)
+ + " Available: " + availableConfigs.toString(), e);
}
}
}
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java
index 30707bce341..9754c8240f9 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java
@@ -13,7 +13,8 @@ public class CodegenConstants {
public static final String TEMPLATE_DIR = "templateDir";
public static final String ALLOW_UNICODE_IDENTIFIERS = "allowUnicodeIdentifiers";
- public static final String ALLOW_UNICODE_IDENTIFIERS_DESC = "boolean, toggles whether unicode identifiers are allowed in names or not, default is false";
+ public static final String ALLOW_UNICODE_IDENTIFIERS_DESC =
+ "boolean, toggles whether unicode identifiers are allowed in names or not, default is false";
public static final String INVOKER_PACKAGE = "invokerPackage";
public static final String INVOKER_PACKAGE_DESC = "root package for generated code";
@@ -40,13 +41,15 @@ public class CodegenConstants {
public static final String ARTIFACT_URL_DESC = "artifact URL in generated pom.xml";
public static final String ARTIFACT_DESCRIPTION = "artifactDescription";
- public static final String ARTIFACT_DESCRIPTION_DESC = "artifact description in generated pom.xml";
+ public static final String ARTIFACT_DESCRIPTION_DESC =
+ "artifact description in generated pom.xml";
public static final String SCM_CONNECTION = "scmConnection";
public static final String SCM_CONNECTION_DESC = "SCM connection in generated pom.xml";
public static final String SCM_DEVELOPER_CONNECTION = "scmDeveloperConnection";
- public static final String SCM_DEVELOPER_CONNECTION_DESC = "SCM developer connection in generated pom.xml";
+ public static final String SCM_DEVELOPER_CONNECTION_DESC =
+ "SCM developer connection in generated pom.xml";
public static final String SCM_URL = "scmUrl";
public static final String SCM_URL_DESC = "SCM URL in generated pom.xml";
@@ -58,10 +61,12 @@ public class CodegenConstants {
public static final String DEVELOPER_EMAIL_DESC = "developer email in generated pom.xml";
public static final String DEVELOPER_ORGANIZATION = "developerOrganization";
- public static final String DEVELOPER_ORGANIZATION_DESC = "developer organization in generated pom.xml";
+ public static final String DEVELOPER_ORGANIZATION_DESC =
+ "developer organization in generated pom.xml";
public static final String DEVELOPER_ORGANIZATION_URL = "developerOrganizationUrl";
- public static final String DEVELOPER_ORGANIZATION_URL_DESC = "developer organization URL in generated pom.xml";
+ public static final String DEVELOPER_ORGANIZATION_URL_DESC =
+ "developer organization URL in generated pom.xml";
public static final String LICENSE_NAME = "licenseName";
public static final String LICENSE_NAME_DESC = "The name of the license";
@@ -76,79 +81,101 @@ public class CodegenConstants {
public static final String IMPL_FOLDER_DESC = "folder for generated implementation code";
public static final String LOCAL_VARIABLE_PREFIX = "localVariablePrefix";
- public static final String LOCAL_VARIABLE_PREFIX_DESC = "prefix for generated code members and local variables";
+ public static final String LOCAL_VARIABLE_PREFIX_DESC =
+ "prefix for generated code members and local variables";
public static final String SERIALIZABLE_MODEL = "serializableModel";
- public static final String SERIALIZABLE_MODEL_DESC = "boolean - toggle \"implements Serializable\" for generated models";
+ public static final String SERIALIZABLE_MODEL_DESC =
+ "boolean - toggle \"implements Serializable\" for generated models";
public static final String SERIALIZE_BIG_DECIMAL_AS_STRING = "bigDecimalAsString";
- public static final String SERIALIZE_BIG_DECIMAL_AS_STRING_DESC = "Treat BigDecimal values as Strings to avoid precision loss.";
+ public static final String SERIALIZE_BIG_DECIMAL_AS_STRING_DESC =
+ "Treat BigDecimal values as Strings to avoid precision loss.";
public static final String LIBRARY = "library";
public static final String LIBRARY_DESC = "library template (sub-template)";
public static final String SORT_PARAMS_BY_REQUIRED_FLAG = "sortParamsByRequiredFlag";
- public static final String SORT_PARAMS_BY_REQUIRED_FLAG_DESC = "Sort method arguments to place required parameters before optional parameters.";
+ public static final String SORT_PARAMS_BY_REQUIRED_FLAG_DESC =
+ "Sort method arguments to place required parameters before optional parameters.";
public static final String USE_DATETIME_OFFSET = "useDateTimeOffset";
- public static final String USE_DATETIME_OFFSET_DESC = "Use DateTimeOffset to model date-time properties";
+ public static final String USE_DATETIME_OFFSET_DESC =
+ "Use DateTimeOffset to model date-time properties";
public static final String ENSURE_UNIQUE_PARAMS = "ensureUniqueParams";
- public static final String ENSURE_UNIQUE_PARAMS_DESC = "Whether to ensure parameter names are unique in an operation (rename parameters that are not).";
+ public static final String ENSURE_UNIQUE_PARAMS_DESC =
+ "Whether to ensure parameter names are unique in an operation (rename parameters that are not).";
public static final String PACKAGE_NAME = "packageName";
public static final String PACKAGE_VERSION = "packageVersion";
public static final String PACKAGE_TITLE = "packageTitle";
- public static final String PACKAGE_TITLE_DESC = "Specifies an AssemblyTitle for the .NET Framework global assembly attributes stored in the AssemblyInfo file.";
+ public static final String PACKAGE_TITLE_DESC =
+ "Specifies an AssemblyTitle for the .NET Framework global assembly attributes stored in the AssemblyInfo file.";
public static final String PACKAGE_PRODUCTNAME = "packageProductName";
- public static final String PACKAGE_PRODUCTNAME_DESC = "Specifies an AssemblyProduct for the .NET Framework global assembly attributes stored in the AssemblyInfo file.";
+ public static final String PACKAGE_PRODUCTNAME_DESC =
+ "Specifies an AssemblyProduct for the .NET Framework global assembly attributes stored in the AssemblyInfo file.";
public static final String PACKAGE_DESCRIPTION = "packageDescription";
- public static final String PACKAGE_DESCRIPTION_DESC = "Specifies a AssemblyDescription for the .NET Framework global assembly attributes stored in the AssemblyInfo file.";
+ public static final String PACKAGE_DESCRIPTION_DESC =
+ "Specifies a AssemblyDescription for the .NET Framework global assembly attributes stored in the AssemblyInfo file.";
public static final String PACKAGE_COMPANY = "packageCompany";
- public static final String PACKAGE_COMPANY_DESC = "Specifies an AssemblyCompany for the .NET Framework global assembly attributes stored in the AssemblyInfo file.";
+ public static final String PACKAGE_COMPANY_DESC =
+ "Specifies an AssemblyCompany for the .NET Framework global assembly attributes stored in the AssemblyInfo file.";
public static final String PACKAGE_COPYRIGHT = "packageCopyright";
- public static final String PACKAGE_COPYRIGHT_DESC = "Specifies an AssemblyCopyright for the .NET Framework global assembly attributes stored in the AssemblyInfo file.";
+ public static final String PACKAGE_COPYRIGHT_DESC =
+ "Specifies an AssemblyCopyright for the .NET Framework global assembly attributes stored in the AssemblyInfo file.";
public static final String POD_VERSION = "podVersion";
public static final String OPTIONAL_METHOD_ARGUMENT = "optionalMethodArgument";
- public static final String OPTIONAL_METHOD_ARGUMENT_DESC = "Optional method argument, e.g. void square(int x=10) (.net 4.0+ only).";
+ public static final String OPTIONAL_METHOD_ARGUMENT_DESC =
+ "Optional method argument, e.g. void square(int x=10) (.net 4.0+ only).";
public static final String OPTIONAL_ASSEMBLY_INFO = "optionalAssemblyInfo";
public static final String OPTIONAL_ASSEMBLY_INFO_DESC = "Generate AssemblyInfo.cs.";
public static final String USE_COLLECTION = "useCollection";
- public static final String USE_COLLECTION_DESC = "Deserialize array types to Collection instead of List.";
+ public static final String USE_COLLECTION_DESC =
+ "Deserialize array types to Collection instead of List.";
public static final String INTERFACE_PREFIX = "interfacePrefix";
- public static final String INTERFACE_PREFIX_DESC = "Prefix interfaces with a community standard or widely accepted prefix.";
+ public static final String INTERFACE_PREFIX_DESC =
+ "Prefix interfaces with a community standard or widely accepted prefix.";
public static final String RETURN_ICOLLECTION = "returnICollection";
- public static final String RETURN_ICOLLECTION_DESC = "Return ICollection instead of the concrete type.";
+ public static final String RETURN_ICOLLECTION_DESC =
+ "Return ICollection instead of the concrete type.";
public static final String OPTIONAL_PROJECT_FILE = "optionalProjectFile";
public static final String OPTIONAL_PROJECT_FILE_DESC = "Generate {PackageName}.csproj.";
public static final String OPTIONAL_PROJECT_GUID = "packageGuid";
- public static final String OPTIONAL_PROJECT_GUID_DESC = "The GUID that will be associated with the C# project";
+ public static final String OPTIONAL_PROJECT_GUID_DESC =
+ "The GUID that will be associated with the C# project";
public static final String MODEL_PROPERTY_NAMING = "modelPropertyNaming";
- public static final String MODEL_PROPERTY_NAMING_DESC = "Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name";
+ public static final String MODEL_PROPERTY_NAMING_DESC =
+ "Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name";
public static final String DOTNET_FRAMEWORK = "targetFramework";
public static final String DOTNET_FRAMEWORK_DESC = "The target .NET framework version.";
- public static enum MODEL_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case, original}
+ public static enum MODEL_PROPERTY_NAMING_TYPE {
+ camelCase, PascalCase, snake_case, original
+ }
public static final String MODEL_NAME_PREFIX = "modelNamePrefix";
- public static final String MODEL_NAME_PREFIX_DESC = "Prefix that will be prepended to all model names. Default is the empty string.";
+ public static final String MODEL_NAME_PREFIX_DESC =
+ "Prefix that will be prepended to all model names. Default is the empty string.";
public static final String MODEL_NAME_SUFFIX = "modelNameSuffix";
- public static final String MODEL_NAME_SUFFIX_DESC = "Suffix that will be appended to all model names. Default is the empty string.";
+ public static final String MODEL_NAME_SUFFIX_DESC =
+ "Suffix that will be appended to all model names. Default is the empty string.";
public static final String OPTIONAL_EMIT_DEFAULT_VALUES = "optionalEmitDefaultValues";
- public static final String OPTIONAL_EMIT_DEFAULT_VALUES_DESC = "Set DataMember's EmitDefaultValue.";
+ public static final String OPTIONAL_EMIT_DEFAULT_VALUES_DESC =
+ "Set DataMember's EmitDefaultValue.";
public static final String GIT_USER_ID = "gitUserId";
public static final String GIT_USER_ID_DESC = "Git user ID, e.g. swagger-api.";
@@ -160,7 +187,8 @@ public static enum MODEL_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case
public static final String RELEASE_NOTE_DESC = "Release note, default to 'Minor update'.";
public static final String HTTP_USER_AGENT = "httpUserAgent";
- public static final String HTTP_USER_AGENT_DESC = "HTTP user agent, e.g. codegen_csharp_api_client, default to 'Swagger-Codegen/{packageVersion}}/{language}'";
+ public static final String HTTP_USER_AGENT_DESC =
+ "HTTP user agent, e.g. codegen_csharp_api_client, default to 'Swagger-Codegen/{packageVersion}}/{language}'";
public static final String SUPPORTS_ES6 = "supportsES6";
public static final String SUPPORTS_ES6_DESC = "Generate code that conforms to ES6.";
@@ -169,21 +197,27 @@ public static enum MODEL_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case
public static final String EXCLUDE_TESTS_DESC = "Specifies that no tests are to be generated.";
public static final String GENERATE_API_TESTS = "generateApiTests";
- public static final String GENERATE_API_TESTS_DESC = "Specifies that api tests are to be generated.";
+ public static final String GENERATE_API_TESTS_DESC =
+ "Specifies that api tests are to be generated.";
public static final String GENERATE_MODEL_TESTS = "generateModelTests";
- public static final String GENERATE_MODEL_TESTS_DESC = "Specifies that model tests are to be generated.";
+ public static final String GENERATE_MODEL_TESTS_DESC =
+ "Specifies that model tests are to be generated.";
public static final String HIDE_GENERATION_TIMESTAMP = "hideGenerationTimestamp";
- public static final String HIDE_GENERATION_TIMESTAMP_DESC = "Hides the generation timestamp when files are generated.";
+ public static final String HIDE_GENERATION_TIMESTAMP_DESC =
+ "Hides the generation timestamp when files are generated.";
public static final String GENERATE_PROPERTY_CHANGED = "generatePropertyChanged";
- public static final String GENERATE_PROPERTY_CHANGED_DESC = "Specifies that models support raising property changed events.";
+ public static final String GENERATE_PROPERTY_CHANGED_DESC =
+ "Specifies that models support raising property changed events.";
public static final String NON_PUBLIC_API = "nonPublicApi";
- public static final String NON_PUBLIC_API_DESC = "Generates code with reduced access modifiers; allows embedding elsewhere without exposing non-public API calls to consumers.";
+ public static final String NON_PUBLIC_API_DESC =
+ "Generates code with reduced access modifiers; allows embedding elsewhere without exposing non-public API calls to consumers.";
public static final String IGNORE_FILE_OVERRIDE = "ignoreFileOverride";
- public static final String IGNORE_FILE_OVERRIDE_DESC = "Specifies an override location for the .swagger-codegen-ignore file. Most useful on initial generation.";
+ public static final String IGNORE_FILE_OVERRIDE_DESC =
+ "Specifies an override location for the .swagger-codegen-ignore file. Most useful on initial generation.";
}
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModel.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModel.java
index 7f89ef738a0..8dff0106d8a 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModel.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModel.java
@@ -14,7 +14,8 @@ public class CodegenModel {
public String parent, parentSchema;
public List interfaces;
- // References to parent and interface CodegenModels. Only set when code generator supports inheritance.
+ // References to parent and interface CodegenModels. Only set when code generator supports
+ // inheritance.
public CodegenModel parentModel;
public List interfaceModels;
public List children;
@@ -26,10 +27,18 @@ public class CodegenModel {
public String defaultValue;
public String arrayModelType;
public List vars = new ArrayList();
- public List requiredVars = new ArrayList(); // a list of required properties
- public List optionalVars = new ArrayList(); // a list of optional properties
- public List readOnlyVars = new ArrayList(); // a list of read-only properties
- public List readWriteVars = new ArrayList(); // a list of properties for read, write
+ public List requiredVars = new ArrayList(); // a list of
+ // required
+ // properties
+ public List optionalVars = new ArrayList(); // a list of
+ // optional
+ // properties
+ public List readOnlyVars = new ArrayList(); // a list of
+ // read-only
+ // properties
+ public List readWriteVars = new ArrayList(); // a list of
+ // properties for
+ // read, write
public List allVars;
public List parentVars = new ArrayList<>();
public Map allowableValues;
@@ -39,17 +48,19 @@ public class CodegenModel {
public Set allMandatory;
public Set imports = new TreeSet();
- public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, hasRequired, isArrayModel, hasChildren;
+ public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, hasRequired, isArrayModel,
+ hasChildren;
public boolean hasOnlyReadOnly = true; // true if all properties are read-only
public ExternalDocs externalDocs;
public Map vendorExtensions;
- //The type of the value from additional properties. Used in map like objects.
+ // The type of the value from additional properties. Used in map like objects.
public String additionalPropertiesType;
{
- // By default these are the same collections. Where the code generator supports inheritance, composed models
+ // By default these are the same collections. Where the code generator supports inheritance,
+ // composed models
// store the complete closure of owned and inherited properties in allVars and allMandatory.
allVars = vars;
allMandatory = mandatory;
@@ -62,20 +73,24 @@ public String toString() {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
CodegenModel that = (CodegenModel) o;
if (parent != null ? !parent.equals(that.parent) : that.parent != null)
return false;
- if (parentSchema != null ? !parentSchema.equals(that.parentSchema) : that.parentSchema != null)
+ if (parentSchema != null ? !parentSchema.equals(that.parentSchema)
+ : that.parentSchema != null)
return false;
if (interfaces != null ? !interfaces.equals(that.interfaces) : that.interfaces != null)
return false;
if (parentModel != null ? !parentModel.equals(that.parentModel) : that.parentModel != null)
return false;
- if (interfaceModels != null ? !interfaceModels.equals(that.interfaceModels) : that.interfaceModels != null)
+ if (interfaceModels != null ? !interfaceModels.equals(that.interfaceModels)
+ : that.interfaceModels != null)
return false;
if (name != null ? !name.equals(that.name) : that.name != null)
return false;
@@ -85,33 +100,42 @@ public boolean equals(Object o) {
return false;
if (description != null ? !description.equals(that.description) : that.description != null)
return false;
- if (classVarName != null ? !classVarName.equals(that.classVarName) : that.classVarName != null)
+ if (classVarName != null ? !classVarName.equals(that.classVarName)
+ : that.classVarName != null)
return false;
if (modelJson != null ? !modelJson.equals(that.modelJson) : that.modelJson != null)
return false;
if (dataType != null ? !dataType.equals(that.dataType) : that.dataType != null)
return false;
- if (classFilename != null ? !classFilename.equals(that.classFilename) : that.classFilename != null)
+ if (classFilename != null ? !classFilename.equals(that.classFilename)
+ : that.classFilename != null)
return false;
- if (unescapedDescription != null ? !unescapedDescription.equals(that.unescapedDescription) : that.unescapedDescription != null)
+ if (unescapedDescription != null ? !unescapedDescription.equals(that.unescapedDescription)
+ : that.unescapedDescription != null)
return false;
- if (discriminator != null ? !discriminator.equals(that.discriminator) : that.discriminator != null)
+ if (discriminator != null ? !discriminator.equals(that.discriminator)
+ : that.discriminator != null)
return false;
- if (defaultValue != null ? !defaultValue.equals(that.defaultValue) : that.defaultValue != null)
+ if (defaultValue != null ? !defaultValue.equals(that.defaultValue)
+ : that.defaultValue != null)
return false;
if (vars != null ? !vars.equals(that.vars) : that.vars != null)
return false;
- if (requiredVars != null ? !requiredVars.equals(that.requiredVars) : that.requiredVars != null)
+ if (requiredVars != null ? !requiredVars.equals(that.requiredVars)
+ : that.requiredVars != null)
return false;
- if (optionalVars != null ? !optionalVars.equals(that.optionalVars) : that.optionalVars != null)
+ if (optionalVars != null ? !optionalVars.equals(that.optionalVars)
+ : that.optionalVars != null)
return false;
if (allVars != null ? !allVars.equals(that.allVars) : that.allVars != null)
return false;
- if (allowableValues != null ? !allowableValues.equals(that.allowableValues) : that.allowableValues != null)
+ if (allowableValues != null ? !allowableValues.equals(that.allowableValues)
+ : that.allowableValues != null)
return false;
if (mandatory != null ? !mandatory.equals(that.mandatory) : that.mandatory != null)
return false;
- if (allMandatory != null ? !allMandatory.equals(that.allMandatory) : that.allMandatory != null)
+ if (allMandatory != null ? !allMandatory.equals(that.allMandatory)
+ : that.allMandatory != null)
return false;
if (imports != null ? !imports.equals(that.imports) : that.imports != null)
return false;
@@ -125,7 +149,8 @@ public boolean equals(Object o) {
return false;
if (isEnum != that.isEnum)
return false;
- if (externalDocs != null ? !externalDocs.equals(that.externalDocs) : that.externalDocs != null)
+ if (externalDocs != null ? !externalDocs.equals(that.externalDocs)
+ : that.externalDocs != null)
return false;
if (!Objects.equals(hasOnlyReadOnly, that.hasOnlyReadOnly))
return false;
@@ -133,7 +158,8 @@ public boolean equals(Object o) {
return false;
if (!Objects.equals(parentVars, that.parentVars))
return false;
- return vendorExtensions != null ? vendorExtensions.equals(that.vendorExtensions) : that.vendorExtensions == null;
+ return vendorExtensions != null ? vendorExtensions.equals(that.vendorExtensions)
+ : that.vendorExtensions == null;
}
@@ -163,11 +189,11 @@ public int hashCode() {
result = 31 * result + (mandatory != null ? mandatory.hashCode() : 0);
result = 31 * result + (allMandatory != null ? allMandatory.hashCode() : 0);
result = 31 * result + (imports != null ? imports.hashCode() : 0);
- result = 31 * result + (hasVars ? 13:31);
- result = 31 * result + (emptyVars ? 13:31);
- result = 31 * result + (hasMoreModels ? 13:31);
- result = 31 * result + (hasEnums ? 13:31);
- result = 31 * result + (isEnum ? 13:31);
+ result = 31 * result + (hasVars ? 13 : 31);
+ result = 31 * result + (emptyVars ? 13 : 31);
+ result = 31 * result + (hasMoreModels ? 13 : 31);
+ result = 31 * result + (hasEnums ? 13 : 31);
+ result = 31 * result + (isEnum ? 13 : 31);
result = 31 * result + (externalDocs != null ? externalDocs.hashCode() : 0);
result = 31 * result + (vendorExtensions != null ? vendorExtensions.hashCode() : 0);
result = 31 * result + Objects.hash(hasOnlyReadOnly);
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModelFactory.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModelFactory.java
index d0a93731a30..f1659f0e232 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModelFactory.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModelFactory.java
@@ -5,17 +5,20 @@
public final class CodegenModelFactory {
- private static final Map> typeMapping = new HashMap>();
+ private static final Map> typeMapping =
+ new HashMap>();
/**
* Configure a different implementation class.
*
- * @param type the type that shall be replaced
- * @param implementation the implementation class must extend the default class and must provide a public no-arg constructor
+ * @param type the type that shall be replaced
+ * @param implementation the implementation class must extend the default class and must provide
+ * a public no-arg constructor
*/
public static void setTypeMapping(CodegenModelType type, Class> implementation) {
if (!type.getDefaultImplementation().isAssignableFrom(implementation)) {
- throw new IllegalArgumentException(implementation.getSimpleName() + " doesn't extend " + type.getDefaultImplementation().getSimpleName());
+ throw new IllegalArgumentException(implementation.getSimpleName() + " doesn't extend "
+ + type.getDefaultImplementation().getSimpleName());
}
try {
implementation.newInstance();
@@ -29,7 +32,8 @@ public static void setTypeMapping(CodegenModelType type, Class> implementation
public static T newInstance(CodegenModelType type) {
Class> classType = typeMapping.get(type);
try {
- return (T) (classType != null ? classType : type.getDefaultImplementation()).newInstance();
+ return (T) (classType != null ? classType : type.getDefaultImplementation())
+ .newInstance();
} catch (IllegalAccessException | InstantiationException e) {
throw new RuntimeException(e);
}
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModelType.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModelType.java
index dce8ab0e2e5..fa511db91a1 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModelType.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModelType.java
@@ -2,12 +2,8 @@
public enum CodegenModelType {
- MODEL(CodegenModel.class),
- OPERATION(CodegenOperation.class),
- PARAMETER(CodegenParameter.class),
- PROPERTY(CodegenProperty.class),
- RESPONSE(CodegenResponse.class),
- SECURITY(CodegenSecurity.class);
+ MODEL(CodegenModel.class), OPERATION(CodegenOperation.class), PARAMETER(CodegenParameter.class), PROPERTY(
+ CodegenProperty.class), RESPONSE(CodegenResponse.class), SECURITY(CodegenSecurity.class);
private final Class> defaultImplementation;
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java
index fc07e0d7174..29f8b4ff8f7 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenOperation.java
@@ -13,12 +13,11 @@ public class CodegenOperation {
public final List responseHeaders = new ArrayList();
public boolean hasAuthMethods, hasConsumes, hasProduces, hasParams, hasOptionalParams,
returnTypeIsPrimitive, returnSimpleType, subresourceOperation, isMapContainer,
- isListContainer, isMultipart, hasMore = true,
- isResponseBinary = false, isResponseFile = false, hasReference = false,
- isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
- isRestful;
- public String path, operationId, returnType, httpMethod, returnBaseType,
- returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse, discriminator;
+ isListContainer, isMultipart, hasMore = true, isResponseBinary = false,
+ isResponseFile = false, hasReference = false, isRestfulIndex, isRestfulShow,
+ isRestfulCreate, isRestfulUpdate, isRestfulDestroy, isRestful;
+ public String path, operationId, returnType, httpMethod, returnBaseType, returnContainer,
+ summary, unescapedNotes, notes, baseName, defaultResponse, discriminator;
public List