diff --git a/modules/swagger-codegen-cli/pom.xml b/modules/swagger-codegen-cli/pom.xml
index 8f57c21653f..ec0d6875358 100644
--- a/modules/swagger-codegen-cli/pom.xml
+++ b/modules/swagger-codegen-cli/pom.xml
@@ -1,4 +1,4 @@
-
io.swagger
@@ -16,12 +16,12 @@
swagger-codegen-cli
-
- src/main/resources
-
- logback.xml
-
-
+
+ src/main/resources
+
+ logback.xml
+
+
@@ -62,7 +62,8 @@
-
+
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 62f0b5cb7e2..fe6d370f3b8 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
@@ -1,17 +1,17 @@
package io.swagger.codegen;
+import io.airlift.airline.Cli;
+import io.airlift.airline.Help;
import io.swagger.codegen.cmd.ConfigHelp;
import io.swagger.codegen.cmd.Generate;
import io.swagger.codegen.cmd.Langs;
import io.swagger.codegen.cmd.Meta;
-import io.airlift.airline.Cli;
-import io.airlift.airline.Help;
/**
* User: lanwen
* Date: 24.03.15
* Time: 17:56
- *
+ *
* Command line interface for swagger codegen
* use `swagger-codegen-cli.jar help` for more info
*
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 54fbfac6e7a..6b34a4bf56d 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
@@ -1,33 +1,24 @@
package io.swagger.codegen.cmd;
-import io.swagger.codegen.CliOption;
-import io.swagger.codegen.CodegenConfig;
import io.airlift.airline.Command;
import io.airlift.airline.Option;
+import io.swagger.codegen.CliOption;
+import io.swagger.codegen.CodegenConfig;
+
import java.util.ServiceLoader;
+
import static java.util.ServiceLoader.load;
@Command(name = "config-help", description = "Config help for chosen lang")
public class ConfigHelp implements Runnable {
-
+
@Option(name = {"-l", "--lang"}, title = "language", required = true,
description = "language to get config help for")
private String lang;
- @Override
- public void run() {
- System.out.println();
- CodegenConfig config = forName(lang);
- System.out.println("CONFIG OPTIONS");
- for (CliOption langCliOption : config.cliOptions()) {
- System.out.println("\t" + langCliOption.getOpt());
- System.out.println("\t " + langCliOption.getDescription());
- System.out.println();
- }
- }
-
/**
* Tries to load config class with SPI first, then with class name directly from classpath
+ *
* @param name name of config, or full qualified class name in classpath
* @return config class
*/
@@ -46,4 +37,16 @@ public class ConfigHelp implements Runnable {
throw new RuntimeException("Can't load config class with name ".concat(name), e);
}
}
+
+ @Override
+ public void run() {
+ System.out.println();
+ CodegenConfig config = forName(lang);
+ System.out.println("CONFIG OPTIONS");
+ for (CliOption langCliOption : config.cliOptions()) {
+ System.out.println("\t" + langCliOption.getOpt());
+ System.out.println("\t " + langCliOption.getDescription());
+ 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 497cba64511..0d7e94e8f28 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
@@ -1,15 +1,15 @@
package io.swagger.codegen.cmd;
+import config.Config;
+import config.ConfigParser;
+import io.airlift.airline.Command;
+import io.airlift.airline.Option;
import io.swagger.codegen.CliOption;
import io.swagger.codegen.ClientOptInput;
import io.swagger.codegen.ClientOpts;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.DefaultGenerator;
import io.swagger.models.Swagger;
-import config.Config;
-import config.ConfigParser;
-import io.airlift.airline.Command;
-import io.airlift.airline.Option;
import io.swagger.parser.SwaggerParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -57,15 +57,37 @@ public class Generate implements Runnable {
"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 " +
+ @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. " +
+
+ @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;
+ /**
+ * Tries to load config class with SPI first, then with class name directly from classpath
+ *
+ * @param name name of config, or full qualified class name in classpath
+ * @return config class
+ */
+ private static CodegenConfig forName(String name) {
+ ServiceLoader loader = load(CodegenConfig.class);
+ for (CodegenConfig config : loader) {
+ if (config.getName().equals(name)) {
+ return config;
+ }
+ }
+
+ // else try to load directly
+ try {
+ return (CodegenConfig) Class.forName(name).newInstance();
+ } catch (Exception e) {
+ throw new RuntimeException("Can't load config class with name ".concat(name), e);
+ }
+ }
+
@Override
public void run() {
verbosed(verbose);
@@ -84,13 +106,13 @@ public class Generate implements Runnable {
if (null != templateDir) {
config.additionalProperties().put(TEMPLATE_DIR_PARAM, new File(templateDir).getAbsolutePath());
}
-
- if(null != configFile){
+
+ if (null != configFile) {
Config genConfig = ConfigParser.read(configFile);
if (null != genConfig) {
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()));
}
}
}
@@ -103,11 +125,11 @@ public class Generate implements Runnable {
}
private void setSystemProperties() {
- if( systemProperties != null && systemProperties.length() > 0 ){
- for( String property : systemProperties.split(",")) {
+ if (systemProperties != null && systemProperties.length() > 0) {
+ for (String property : systemProperties.split(",")) {
int ix = property.indexOf('=');
- if( ix > 0 && ix < property.length()-1 ){
- System.setProperty( property.substring(0, ix), property.substring(ix+1) );
+ if (ix > 0 && ix < property.length() - 1) {
+ System.setProperty(property.substring(0, ix), property.substring(ix + 1));
}
}
}
@@ -115,6 +137,7 @@ public class Generate implements Runnable {
/**
* If true parameter, adds system properties which enables debug mode in generator
+ *
* @param verbose - if true, enables debug mode
*/
private void verbosed(boolean verbose) {
@@ -132,25 +155,4 @@ public class Generate implements Runnable {
System.setProperty("debugOperations", "");
System.setProperty("debugSupportingFiles", "");
}
-
- /**
- * Tries to load config class with SPI first, then with class name directly from classpath
- * @param name name of config, or full qualified class name in classpath
- * @return config class
- */
- private static CodegenConfig forName(String name) {
- ServiceLoader loader = load(CodegenConfig.class);
- for (CodegenConfig config : loader) {
- if (config.getName().equals(name)) {
- return config;
- }
- }
-
- // else try to load directly
- try {
- return (CodegenConfig) Class.forName(name).newInstance();
- } catch (Exception e) {
- throw new RuntimeException("Can't load config class with name ".concat(name), e);
- }
- }
}
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 5627b6c7ac8..c3d7391579e 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
@@ -1,8 +1,8 @@
package io.swagger.codegen.cmd;
import ch.lambdaj.collection.LambdaIterable;
-import io.swagger.codegen.CodegenConfig;
import io.airlift.airline.Command;
+import io.swagger.codegen.CodegenConfig;
import static ch.lambdaj.Lambda.on;
import static ch.lambdaj.collection.LambdaCollections.with;
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 4a875b7199e..c75181c51cd 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
@@ -4,10 +4,10 @@ import ch.lambdaj.function.convert.Converter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.samskivert.mustache.Mustache;
-import io.swagger.codegen.DefaultGenerator;
-import io.swagger.codegen.SupportingFile;
import io.airlift.airline.Command;
import io.airlift.airline.Option;
+import io.swagger.codegen.DefaultGenerator;
+import io.swagger.codegen.SupportingFile;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -81,8 +81,9 @@ public class Meta implements Runnable {
/**
* 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 Converter processFiles(final File targetDir, final Map data) {
@@ -121,6 +122,7 @@ public class Meta implements Runnable {
/**
* Creates mustache loader for template using classpath loader
+ *
* @param generator - class with reader getter
* @return loader for template
*/
@@ -135,6 +137,7 @@ public class Meta implements Runnable {
/**
* Converts package name to path on file system
+ *
* @param packageName - package name to convert
* @return relative path
*/
diff --git a/modules/swagger-codegen-cli/src/main/resources/logback.xml b/modules/swagger-codegen-cli/src/main/resources/logback.xml
index 273b46980db..3bd0c92d369 100644
--- a/modules/swagger-codegen-cli/src/main/resources/logback.xml
+++ b/modules/swagger-codegen-cli/src/main/resources/logback.xml
@@ -1,12 +1,12 @@
-
-
-
- %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
-
-
-
-
-
-
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
diff --git a/modules/swagger-codegen/pom.xml b/modules/swagger-codegen/pom.xml
index 5debeeb2570..1b6712ba32f 100644
--- a/modules/swagger-codegen/pom.xml
+++ b/modules/swagger-codegen/pom.xml
@@ -1,356 +1,357 @@
-
-
- io.swagger
- swagger-codegen-project
- 2.1.1
- ../..
-
- 4.0.0
- swagger-codegen
- jar
- swagger-codegen (core library)
-
- src/main/java
- install
-
-
- src/main/resources
-
- logback.xml
-
-
-
-
-
- org.jvnet.wagon-svn
- wagon-svn
- 1.8
-
-
- org.apache.maven.wagon
- wagon-ssh-external
- 1.0-alpha-6
-
-
- org.apache.maven.wagon
- wagon-webdav
- 1.0-beta-1
-
-
- target
- ${project.artifactId}-${project.version}
-
-
- org.codehaus.mojo
- exec-maven-plugin
- 1.3.2
-
-
-
- java
-
-
-
-
- io.swagger.codegen.Codegen
-
-
-
- maven-dependency-plugin
-
-
- package
-
- copy-dependencies
-
-
- ${project.build.directory}/lib
-
-
-
-
-
- net.alchim31.maven
- scala-maven-plugin
-
-
-
- add-source
- compile
- testCompile
-
-
-
-
-
- incremental
-
-
- -Xmx384m
-
-
- -target:jvm-1.6
- -deprecation
-
-
-
- run-scalatest
- org.scalatest.tools.Runner
-
- -p
- ${project.build.testOutputDirectory}
-
-
- -Xmx512m
-
-
-
-
-
-
- maven-compiler-plugin
- 3.0
-
- 1.6
- 1.6
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- 2.4
-
-
-
- development
- ${project.url}
- ${project.version}
- io.swagger
-
-
-
-
-
- org.apache.maven.plugins
- maven-site-plugin
- 2.1
-
-
- org.apache.maven.plugins
- maven-release-plugin
- 2.1
-
-
-
-
-
- net.alchim31.maven
- scala-maven-plugin
- ${scala-maven-plugin-version}
-
-
- org.apache.maven.plugins
- maven-gpg-plugin
-
- release
- sign
-
-
-
-
-
-
-
- release-profile
-
- true
-
-
+
+
+ io.swagger
+ swagger-codegen-project
+ 2.1.1
+ ../..
+
+ 4.0.0
+ swagger-codegen
+ jar
+ swagger-codegen (core library)
+
+ src/main/java
+ install
+
+
+ src/main/resources
+
+ logback.xml
+
+
+
+
+
+ org.jvnet.wagon-svn
+ wagon-svn
+ 1.8
+
+
+ org.apache.maven.wagon
+ wagon-ssh-external
+ 1.0-alpha-6
+
+
+ org.apache.maven.wagon
+ wagon-webdav
+ 1.0-beta-1
+
+
+ target
+ ${project.artifactId}-${project.version}
-
- net.alchim31.maven
- scala-maven-plugin
-
-
-
- compile
- testCompile
-
-
-
-
- ${scala-version}
-
-
-
- org.codehaus.mojo
- build-helper-maven-plugin
-
-
- add-source
- prepare-package
-
- add-source
-
+
+ org.codehaus.mojo
+ exec-maven-plugin
+ 1.3.2
+
+
+
+ java
+
+
+
-
- src/main/scala
-
+ io.swagger.codegen.Codegen
-
-
-
+
+
+ maven-dependency-plugin
+
+
+ package
+
+ copy-dependencies
+
+
+ ${project.build.directory}/lib
+
+
+
+
+
+ net.alchim31.maven
+ scala-maven-plugin
+
+
+
+ add-source
+ compile
+ testCompile
+
+
+
+
+
+ incremental
+
+
+ -Xmx384m
+
+
+ -target:jvm-1.6
+ -deprecation
+
+
+
+ run-scalatest
+ org.scalatest.tools.Runner
+
+ -p
+ ${project.build.testOutputDirectory}
+
+
+ -Xmx512m
+
+
+
+
+
+
+ maven-compiler-plugin
+ 3.0
+
+ 1.6
+ 1.6
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.4
+
+
+
+ development
+ ${project.url}
+ ${project.version}
+ io.swagger
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-site-plugin
+ 2.1
+
+
+ org.apache.maven.plugins
+ maven-release-plugin
+ 2.1
+
-
-
-
- release-sign-artifacts
-
-
- performRelease
- true
-
-
-
+
+
+
+ net.alchim31.maven
+ scala-maven-plugin
+ ${scala-maven-plugin-version}
+
+
+ org.apache.maven.plugins
+ maven-gpg-plugin
+
+ release
+ sign
+
+
+
+
+
+
+
+ release-profile
+
+ true
+
+
+
+
+ net.alchim31.maven
+ scala-maven-plugin
+
+
+
+ compile
+ testCompile
+
+
+
+
+ ${scala-version}
+
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+
+
+ add-source
+ prepare-package
+
+ add-source
+
+
+
+ src/main/scala
+
+
+
+
+
+
+
+
+
+ release-sign-artifacts
+
+
+ performRelease
+ true
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-gpg-plugin
+
+
+ sign-artifacts
+ verify
+
+ sign
+
+
+
+
+
+
+
+
+
+ target/site
-
- org.apache.maven.plugins
- maven-gpg-plugin
-
-
- sign-artifacts
- verify
-
- sign
-
-
-
-
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 2.9
+
+ true
+ true
+
+ http://java.sun.com/javaee/5/docs/api
+ http://java.sun.com/j2se/1.5.0/docs/api
+
+
+
+
+
+ net.alchim31.maven
+ scala-maven-plugin
+ ${scala-maven-plugin-version}
+
+
+ org.apache.maven.plugins
+ maven-jxr-plugin
+ 2.3
+
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-project-info-reports-plugin
+ 2.6
+
+
+
+ project-team
+
+
+
+
-
-
-
-
- target/site
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 2.9
-
- true
- true
-
- http://java.sun.com/javaee/5/docs/api
- http://java.sun.com/j2se/1.5.0/docs/api
-
-
-
-
-
- net.alchim31.maven
- scala-maven-plugin
- ${scala-maven-plugin-version}
-
-
- org.apache.maven.plugins
- maven-jxr-plugin
- 2.3
-
- true
-
-
-
- org.apache.maven.plugins
- maven-project-info-reports-plugin
- 2.6
-
-
-
- project-team
-
-
-
-
-
-
-
-
- io.swagger
- swagger-parser
- ${swagger-parser-version}
- compile
-
-
- io.swagger
- swagger-compat-spec-parser
- ${swagger-parser-version}
-
-
- ${project.groupId}
- swagger-core
- ${swagger-core-version}
-
-
- com.samskivert
- jmustache
- ${jmustache-version}
-
-
- commons-io
- commons-io
- ${commons-io-version}
-
-
- org.apache.maven
- maven-plugin-tools-api
- 2.0
-
-
- org.apache.felix
- maven-bundle-plugin
- ${felix-version}
-
-
- org.slf4j
- slf4j-ext
- ${slf4j-version}
-
-
- org.slf4j
- slf4j-api
- ${slf4j-version}
-
-
- commons-lang
- commons-lang
- ${commons-lang-version}
-
-
- commons-cli
- commons-cli
- ${commons-cli-version}
-
-
- org.scalatest
- scalatest_2.11
- ${scala-test-version}
- test
-
-
- org.scala-lang
- scala-library
- ${scala-version}
- test
-
-
-
-
- sonatype-snapshots
- https://oss.sonatype.org/content/repositories/snapshots
-
- true
-
-
-
+
+
+
+ io.swagger
+ swagger-parser
+ ${swagger-parser-version}
+ compile
+
+
+ io.swagger
+ swagger-compat-spec-parser
+ ${swagger-parser-version}
+
+
+ ${project.groupId}
+ swagger-core
+ ${swagger-core-version}
+
+
+ com.samskivert
+ jmustache
+ ${jmustache-version}
+
+
+ commons-io
+ commons-io
+ ${commons-io-version}
+
+
+ org.apache.maven
+ maven-plugin-tools-api
+ 2.0
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ ${felix-version}
+
+
+ org.slf4j
+ slf4j-ext
+ ${slf4j-version}
+
+
+ org.slf4j
+ slf4j-api
+ ${slf4j-version}
+
+
+ commons-lang
+ commons-lang
+ ${commons-lang-version}
+
+
+ commons-cli
+ commons-cli
+ ${commons-cli-version}
+
+
+ org.scalatest
+ scalatest_2.11
+ ${scala-test-version}
+ test
+
+
+ org.scala-lang
+ scala-library
+ ${scala-version}
+ test
+
+
+
+
+ sonatype-snapshots
+ https://oss.sonatype.org/content/repositories/snapshots
+
+ true
+
+
+
diff --git a/modules/swagger-codegen/src/main/java/config/Config.java b/modules/swagger-codegen/src/main/java/config/Config.java
index 9bc4bf58624..8b8f1b36a96 100644
--- a/modules/swagger-codegen/src/main/java/config/Config.java
+++ b/modules/swagger-codegen/src/main/java/config/Config.java
@@ -1,33 +1,34 @@
package config;
import com.google.common.collect.ImmutableMap;
+
import java.util.HashMap;
import java.util.Map;
public class Config {
- private Map options;
+ private Map options;
- public Config() {
- this.options = new HashMap();
- }
+ public Config() {
+ this.options = new HashMap();
+ }
- public Config(Map properties) {
- this.options = properties;
- }
+ public Config(Map properties) {
+ this.options = properties;
+ }
- public Map getOptions() {
- return ImmutableMap.copyOf(options);
- }
-
- public boolean hasOption(String opt){
- return options.containsKey(opt);
- }
-
- public String getOption(String opt){
- return options.get(opt);
- }
-
- public void setOption(String opt, String value){
- options.put(opt, value);
- }
+ public Map getOptions() {
+ return ImmutableMap.copyOf(options);
+ }
+
+ public boolean hasOption(String opt) {
+ return options.containsKey(opt);
+ }
+
+ public String getOption(String opt) {
+ return options.get(opt);
+ }
+
+ public void setOption(String opt, String value) {
+ options.put(opt, value);
+ }
}
diff --git a/modules/swagger-codegen/src/main/java/config/ConfigParser.java b/modules/swagger-codegen/src/main/java/config/ConfigParser.java
index cbb1b78f645..101fbb0d256 100644
--- a/modules/swagger-codegen/src/main/java/config/ConfigParser.java
+++ b/modules/swagger-codegen/src/main/java/config/ConfigParser.java
@@ -2,40 +2,39 @@ package config;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+
import java.io.File;
import java.util.Iterator;
import java.util.Map;
public class ConfigParser {
- public static Config read(String location) {
+ public static Config read(String location) {
- System.out.println("reading config from " + location);
+ System.out.println("reading config from " + location);
- ObjectMapper mapper = new ObjectMapper();
-
- Config config = new Config();
-
- try {
- JsonNode rootNode = mapper.readTree(new File(location));
- Iterator> optionNodes = rootNode.fields();
-
- while (optionNodes.hasNext()) {
- Map.Entry optionNode = (Map.Entry) optionNodes.next();
-
- if(optionNode.getValue().isValueNode()){
- config.setOption(optionNode.getKey(), optionNode.getValue().asText());
+ ObjectMapper mapper = new ObjectMapper();
+
+ Config config = new Config();
+
+ try {
+ JsonNode rootNode = mapper.readTree(new File(location));
+ Iterator> optionNodes = rootNode.fields();
+
+ while (optionNodes.hasNext()) {
+ Map.Entry optionNode = (Map.Entry) optionNodes.next();
+
+ if (optionNode.getValue().isValueNode()) {
+ config.setOption(optionNode.getKey(), optionNode.getValue().asText());
+ } else {
+ System.out.println("omitting non-value node " + optionNode.getKey());
+ }
+ }
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ return null;
}
- else{
- System.out.println("omitting non-value node " + optionNode.getKey());
- }
- }
+
+ return config;
}
- catch (Exception e) {
- System.out.println(e.getMessage());
- return null;
- }
-
- return config;
- }
}
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 3fc7dfb8da2..54a2f7efae0 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
@@ -1,60 +1,69 @@
package io.swagger.codegen;
-import com.samskivert.mustache.*;
-
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
import java.util.regex.Pattern;
-import java.io.*;
public abstract class AbstractGenerator {
- public File writeToFile(String filename, String contents) throws IOException {
- System.out.println("writing file " + filename);
- File output = new File(filename);
+ public File writeToFile(String filename, String contents) throws IOException {
+ System.out.println("writing file " + filename);
+ File output = new File(filename);
- if(output.getParent() != null && !new File(output.getParent()).exists()) {
- File parent = new File(output.getParent());
- parent.mkdirs();
- }
- Writer out = new BufferedWriter(new OutputStreamWriter(
- new FileOutputStream(output), "UTF-8"));
+ if (output.getParent() != null && !new File(output.getParent()).exists()) {
+ File parent = new File(output.getParent());
+ parent.mkdirs();
+ }
+ Writer out = new BufferedWriter(new OutputStreamWriter(
+ new FileOutputStream(output), "UTF-8"));
- out.write(contents);
- out.close();
- return output;
- }
+ out.write(contents);
+ out.close();
+ return output;
+ }
- public String readTemplate(String name) {
- try{
- Reader reader = getTemplateReader(name);
- if(reader == null)
- throw new RuntimeException("no file found");
- java.util.Scanner s = new java.util.Scanner(reader).useDelimiter("\\A");
- return s.hasNext() ? s.next() : "";
+ public String readTemplate(String name) {
+ try {
+ Reader reader = getTemplateReader(name);
+ if (reader == null) {
+ throw new RuntimeException("no file found");
+ }
+ java.util.Scanner s = new java.util.Scanner(reader).useDelimiter("\\A");
+ return s.hasNext() ? s.next() : "";
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ throw new RuntimeException("can't load template " + name);
}
- catch(Exception e) {
- e.printStackTrace();
- }
- throw new RuntimeException("can't load template " + name);
- }
- public Reader getTemplateReader(String name) {
- try{
- InputStream is = this.getClass().getClassLoader().getResourceAsStream(getCPResourcePath(name));
- if(is == null)
- is = new FileInputStream(new File(name));
- if(is == null)
- throw new RuntimeException("no file found");
- return new InputStreamReader(is);
+ public Reader getTemplateReader(String name) {
+ try {
+ InputStream is = this.getClass().getClassLoader().getResourceAsStream(getCPResourcePath(name));
+ if (is == null) {
+ is = new FileInputStream(new File(name));
+ }
+ if (is == null) {
+ throw new RuntimeException("no file found");
+ }
+ return new InputStreamReader(is);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ throw new RuntimeException("can't load template " + name);
}
- catch(Exception e) {
- e.printStackTrace();
- }
- throw new RuntimeException("can't load template " + name);
- }
- private String getCPResourcePath(String name) {
- if (!"/".equals(File.separator))
- return name.replaceAll(Pattern.quote(File.separator), "/");
- return name;
- }
+ private String getCPResourcePath(String name) {
+ if (!"/".equals(File.separator)) {
+ return name.replaceAll(Pattern.quote(File.separator), "/");
+ }
+ return name;
+ }
}
\ No newline at end of file
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 3f4334507ae..1aa0937b31b 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
@@ -1,23 +1,23 @@
package io.swagger.codegen;
public class CliOption {
- private final String opt;
- private String description;
+ private final String opt;
+ private String description;
- public CliOption(String opt, String description) {
- this.opt = opt;
- this.description = description;
- }
+ public CliOption(String opt, String description) {
+ this.opt = opt;
+ this.description = description;
+ }
- public String getOpt() {
- return opt;
- }
+ public String getOpt() {
+ return opt;
+ }
- public String getDescription() {
- return description;
- }
+ public String getDescription() {
+ return description;
+ }
- public void setDescription(String description) {
- this.description = description;
- }
+ public void setDescription(String description) {
+ this.description = description;
+ }
}
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 c1d21f48035..da026c7f040 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
@@ -1,88 +1,92 @@
package io.swagger.codegen;
-import io.swagger.codegen.ClientOpts;
-import io.swagger.annotations.*;
+import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.Swagger;
import io.swagger.models.auth.AuthorizationValue;
-import java.util.*;
-import java.net.URLEncoder;
import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.List;
public class ClientOptInput {
- private ClientOpts opts;
- private Swagger swagger;
- private List auths;
- protected CodegenConfig config;
+ protected CodegenConfig config;
+ private ClientOpts opts;
+ private Swagger swagger;
+ private List auths;
- public ClientOptInput swagger(Swagger swagger) {
- this.setSwagger(swagger);
- return this;
- }
- public ClientOptInput opts(ClientOpts opts) {
- this.setOpts(opts);
- return this;
- }
-
- public void setAuth(String urlEncodedAuthString) {
- List auths = new ArrayList();
- if(urlEncodedAuthString != null && !"".equals(urlEncodedAuthString)) {
- String[] parts = urlEncodedAuthString.split(",");
- for(String part : parts) {
- String[] kvPair = part.split(":");
- if(kvPair.length == 2) {
- auths.add(new AuthorizationValue(URLDecoder.decode(kvPair[0]), URLDecoder.decode(kvPair[1]), "header"));
- }
- }
+ public ClientOptInput swagger(Swagger swagger) {
+ this.setSwagger(swagger);
+ return this;
}
- this.auths = auths;
- }
- public String getAuth() {
- if(auths != null) {
- StringBuilder b = new StringBuilder();
- for(AuthorizationValue v : auths) {
- try {
- if(b.toString().length() > 0)
- b.append(",");
- b.append(URLEncoder.encode(v.getKeyName(), "UTF-8"))
- .append(":")
- .append(URLEncoder.encode(v.getValue(), "UTF-8"));
- }
- catch (Exception e) {
- // continue
- e.printStackTrace();
- }
- }
- return b.toString();
+
+ public ClientOptInput opts(ClientOpts opts) {
+ this.setOpts(opts);
+ return this;
}
- else
- return null;
- }
- public List getAuthorizationValues() {
- return auths;
- }
- public CodegenConfig getConfig() {
- return config;
- }
- public void setConfig(CodegenConfig config) {
- this.config = config;
- }
+ public String getAuth() {
+ if (auths != null) {
+ StringBuilder b = new StringBuilder();
+ for (AuthorizationValue v : auths) {
+ try {
+ if (b.toString().length() > 0) {
+ b.append(",");
+ }
+ b.append(URLEncoder.encode(v.getKeyName(), "UTF-8"))
+ .append(":")
+ .append(URLEncoder.encode(v.getValue(), "UTF-8"));
+ } catch (Exception e) {
+ // continue
+ e.printStackTrace();
+ }
+ }
+ return b.toString();
+ } else {
+ return null;
+ }
+ }
- public void setOpts(ClientOpts opts) {
- this.opts = opts;
- }
+ public void setAuth(String urlEncodedAuthString) {
+ List auths = new ArrayList();
+ if (urlEncodedAuthString != null && !"".equals(urlEncodedAuthString)) {
+ String[] parts = urlEncodedAuthString.split(",");
+ for (String part : parts) {
+ String[] kvPair = part.split(":");
+ if (kvPair.length == 2) {
+ auths.add(new AuthorizationValue(URLDecoder.decode(kvPair[0]), URLDecoder.decode(kvPair[1]), "header"));
+ }
+ }
+ }
+ this.auths = auths;
+ }
- public ClientOpts getOpts() {
- return opts;
- }
+ public List getAuthorizationValues() {
+ return auths;
+ }
- public void setSwagger(Swagger swagger) {
- this.swagger = swagger;
- }
+ public CodegenConfig getConfig() {
+ return config;
+ }
- @ApiModelProperty(dataType="Object")
- public Swagger getSwagger() {
- return swagger;
- }
+ public void setConfig(CodegenConfig config) {
+ this.config = config;
+ }
+
+ public ClientOpts getOpts() {
+ return opts;
+ }
+
+ public void setOpts(ClientOpts opts) {
+ this.opts = opts;
+ }
+
+ @ApiModelProperty(dataType = "Object")
+ public Swagger getSwagger() {
+ return swagger;
+ }
+
+ 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 465fed820da..9c4d41f7bfd 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
@@ -1,52 +1,57 @@
package io.swagger.codegen;
-import io.swagger.codegen.auth.*;
+import io.swagger.codegen.auth.AuthMethod;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
public class ClientOpts {
- protected String uri;
- protected String target;
- protected AuthMethod auth;
- protected Map properties = new HashMap();
- protected String outputDirectory;
+ protected String uri;
+ protected String target;
+ protected AuthMethod auth;
+ protected Map properties = new HashMap();
+ protected String outputDirectory;
- public String getUri() {
- return uri;
- }
- public void setUri(String uri) {
- this.uri = uri;
- }
+ public String getUri() {
+ return uri;
+ }
- public String getTarget() {
- return target;
- }
- public void setTarget(String target) {
- this.target = target;
- }
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
- public Map getProperties() {
- return properties;
- }
- public void setProperties(Map properties) {
- this.properties = properties;
- }
+ public String getTarget() {
+ return target;
+ }
- public String getOutputDirectory() {
- return outputDirectory;
- }
- public void setOutputDirectory(String outputDirectory) {
- this.outputDirectory = outputDirectory;
- }
+ public void setTarget(String target) {
+ this.target = target;
+ }
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append("ClientOpts: {\n");
- sb.append(" uri: ").append(uri).append(",");
- sb.append(" auth: ").append(auth).append(",");
- sb.append(properties);
- sb.append("}");
- return sb.toString();
- }
+ public Map getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map properties) {
+ this.properties = properties;
+ }
+
+ public String getOutputDirectory() {
+ return outputDirectory;
+ }
+
+ public void setOutputDirectory(String outputDirectory) {
+ this.outputDirectory = outputDirectory;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("ClientOpts: {\n");
+ sb.append(" uri: ").append(uri).append(",");
+ sb.append(" auth: ").append(auth).append(",");
+ sb.append(properties);
+ sb.append("}");
+ return sb.toString();
+ }
}
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 8772a8b8ced..c99e04e5494 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
@@ -1,16 +1,19 @@
package io.swagger.codegen;
-import io.swagger.codegen.languages.*;
import io.swagger.models.Swagger;
-import io.swagger.models.auth.AuthorizationValue;
-import io.swagger.util.*;
-
import io.swagger.parser.SwaggerParser;
+import org.apache.commons.cli.BasicParser;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
-import org.apache.commons.cli.*;
-
-import java.io.File;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.ServiceLoader;
/**
* @deprecated use instead {@link io.swagger.codegen.DefaultGenerator}
@@ -18,126 +21,128 @@ import java.util.*;
*/
@Deprecated
public class Codegen extends DefaultGenerator {
- static Map configs = new HashMap();
- static String configString;
- static {
- List extensions = getExtensions();
- StringBuilder sb = new StringBuilder();
+ 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";
- for(CodegenConfig config : extensions) {
- if(sb.toString().length() != 0)
- sb.append(", ");
- sb.append(config.getName());
- configs.put(config.getName(), config);
- configString = sb.toString();
- }
- }
+ public static void main(String[] args) {
- 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";
- public static void main(String[] args) {
+ StringBuilder sb = new StringBuilder();
- StringBuilder sb = new StringBuilder();
+ 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("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 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("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");
+ ClientOptInput clientOptInput = new ClientOptInput();
+ ClientOpts clientOpts = new ClientOpts();
+ Swagger swagger = null;
- ClientOptInput clientOptInput = new ClientOptInput();
- ClientOpts clientOpts = new ClientOpts();
- Swagger swagger = null;
+ CommandLine cmd = null;
+ try {
+ CommandLineParser parser = new BasicParser();
+ CodegenConfig config = null;
- CommandLine cmd = null;
- try {
- CommandLineParser parser = new BasicParser();
- CodegenConfig config = null;
-
- cmd = parser.parse(options, args);
- if (cmd.hasOption("d")) {
- usage(options);
- System.out.println(debugInfoOptions);
- return;
- }
- if (cmd.hasOption("a"))
- clientOptInput.setAuth(cmd.getOptionValue("a"));
- if (cmd.hasOption("l"))
- clientOptInput.setConfig(getConfig(cmd.getOptionValue("l")));
- else {
- usage(options);
- return;
- }
- if (cmd.hasOption("o"))
- clientOptInput.getConfig().setOutputDir(cmd.getOptionValue("o"));
- if (cmd.hasOption("h")) {
- if(cmd.hasOption("l")) {
- config = getConfig(String.valueOf(cmd.getOptionValue("l")));
- if(config != null) {
- options.addOption("h", "help", true, config.getHelp());
+ cmd = parser.parse(options, args);
+ if (cmd.hasOption("d")) {
+ usage(options);
+ System.out.println(debugInfoOptions);
+ return;
+ }
+ if (cmd.hasOption("a")) {
+ clientOptInput.setAuth(cmd.getOptionValue("a"));
+ }
+ if (cmd.hasOption("l")) {
+ clientOptInput.setConfig(getConfig(cmd.getOptionValue("l")));
+ } else {
+ usage(options);
+ return;
+ }
+ if (cmd.hasOption("o")) {
+ clientOptInput.getConfig().setOutputDir(cmd.getOptionValue("o"));
+ }
+ if (cmd.hasOption("h")) {
+ if (cmd.hasOption("l")) {
+ config = getConfig(String.valueOf(cmd.getOptionValue("l")));
+ if (config != null) {
+ options.addOption("h", "help", true, config.getHelp());
+ usage(options);
+ return;
+ }
+ }
+ usage(options);
+ return;
+ }
+ if (cmd.hasOption("i")) {
+ swagger = new SwaggerParser().read(cmd.getOptionValue("i"), clientOptInput.getAuthorizationValues(), true);
+ }
+ if (cmd.hasOption("t")) {
+ clientOpts.getProperties().put("templateDir", String.valueOf(cmd.getOptionValue("t")));
+ }
+ } catch (Exception e) {
usage(options);
return;
- }
}
- usage(options);
- return;
- }
- if (cmd.hasOption("i"))
- swagger = new SwaggerParser().read(cmd.getOptionValue("i"), clientOptInput.getAuthorizationValues(), true);
- if (cmd.hasOption("t"))
- clientOpts.getProperties().put("templateDir", String.valueOf(cmd.getOptionValue("t")));
+ try {
+ clientOptInput
+ .opts(clientOpts)
+ .swagger(swagger);
+ new Codegen().opts(clientOptInput).generate();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
- catch (Exception e) {
- usage(options);
- return;
- }
- try{
- clientOptInput
- .opts(clientOpts)
- .swagger(swagger);
- new Codegen().opts(clientOptInput).generate();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static List getExtensions() {
- ServiceLoader loader = ServiceLoader.load(CodegenConfig.class);
- List output = new ArrayList();
- Iterator itr = loader.iterator();
- while(itr.hasNext()) {
- output.add(itr.next());
+ public static List getExtensions() {
+ ServiceLoader loader = ServiceLoader.load(CodegenConfig.class);
+ List output = new ArrayList();
+ Iterator itr = loader.iterator();
+ while (itr.hasNext()) {
+ output.add(itr.next());
+ }
+ return output;
}
- return output;
- }
- static void usage(Options options) {
- HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp( "Codegen", options );
- }
+ static void usage(Options options) {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp("Codegen", options);
+ }
- public static CodegenConfig getConfig(String name) {
- if(configs.containsKey(name)) {
- return configs.get(name);
+ public static CodegenConfig getConfig(String name) {
+ if (configs.containsKey(name)) {
+ return configs.get(name);
+ } else {
+ // see if it's a class
+ try {
+ System.out.println("loading class " + name);
+ Class customClass = Class.forName(name);
+ System.out.println("loaded");
+ return (CodegenConfig) customClass.newInstance();
+ } catch (Exception e) {
+ throw new RuntimeException("can't load class " + name);
+ }
+ }
}
- else {
- // see if it's a class
- try {
- System.out.println("loading class " + name);
- Class customClass = Class.forName(name);
- System.out.println("loaded");
- return (CodegenConfig)customClass.newInstance();
- }
- catch (Exception e) {
- throw new RuntimeException("can't load class " + name);
- }
+
+ static {
+ List extensions = getExtensions();
+ StringBuilder sb = new StringBuilder();
+
+ for (CodegenConfig config : extensions) {
+ if (sb.toString().length() != 0) {
+ sb.append(", ");
+ }
+ sb.append(config.getName());
+ configs.put(config.getName(), config);
+ configString = sb.toString();
+ }
}
- }
}
\ No newline at end of file
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 4ff582dcb11..6f96bd82b5d 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
@@ -1,64 +1,105 @@
package io.swagger.codegen;
-import io.swagger.models.*;
+import io.swagger.models.Model;
+import io.swagger.models.Operation;
+import io.swagger.models.Swagger;
import io.swagger.models.auth.SecuritySchemeDefinition;
-import io.swagger.models.properties.*;
+import io.swagger.models.properties.Property;
-import java.util.*;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
public interface CodegenConfig {
- CodegenType getTag();
- String getName();
- String getHelp();
- Map additionalProperties();
- String apiPackage();
- String apiFileFolder();
- String fileSuffix();
- String outputFolder();
- String templateDir();
- String modelFileFolder();
- String modelPackage();
- String toApiName(String name);
- String toApiVarName(String name);
- String toModelName(String name);
- String toParamName(String name);
- String escapeText(String text);
- String escapeReservedWord(String name);
- String getTypeDeclaration(Property p);
- String getTypeDeclaration(String name);
- void processOpts();
- List cliOptions();
- String generateExamplePath(String path, Operation operation);
+ CodegenType getTag();
- Set reservedWords();
+ String getName();
- List supportingFiles();
+ String getHelp();
- void setOutputDir(String dir);
- String getOutputDir();
+ Map additionalProperties();
- CodegenModel fromModel(String name, Model model);
- CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map definitions);
- List fromSecurity(Map schemes);
+ String apiPackage();
- Set defaultIncludes();
- Map typeMapping();
- Map instantiationTypes();
- Map importMapping();
- Map apiTemplateFiles();
- Map modelTemplateFiles();
- void processSwagger(Swagger swagger);
+ String apiFileFolder();
- String toApiFilename(String name);
- String toModelFilename(String name);
- String toModelImport(String name);
- String toApiImport(String name);
- void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map> operations);
- Map postProcessModels(Map objs);
- Map postProcessOperations(Map objs);
- Map postProcessSupportingFileData(Map objs);
+ String fileSuffix();
- String apiFilename(String templateName, String tag);
+ String outputFolder();
- boolean shouldOverwrite(String filename);
+ String templateDir();
+
+ String modelFileFolder();
+
+ String modelPackage();
+
+ String toApiName(String name);
+
+ String toApiVarName(String name);
+
+ String toModelName(String name);
+
+ String toParamName(String name);
+
+ String escapeText(String text);
+
+ String escapeReservedWord(String name);
+
+ String getTypeDeclaration(Property p);
+
+ String getTypeDeclaration(String name);
+
+ void processOpts();
+
+ List cliOptions();
+
+ String generateExamplePath(String path, Operation operation);
+
+ Set reservedWords();
+
+ List supportingFiles();
+
+ String getOutputDir();
+
+ void setOutputDir(String dir);
+
+ CodegenModel fromModel(String name, Model model);
+
+ CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map definitions);
+
+ List fromSecurity(Map schemes);
+
+ Set defaultIncludes();
+
+ Map typeMapping();
+
+ Map instantiationTypes();
+
+ Map importMapping();
+
+ Map apiTemplateFiles();
+
+ Map modelTemplateFiles();
+
+ void processSwagger(Swagger swagger);
+
+ String toApiFilename(String name);
+
+ String toModelFilename(String name);
+
+ String toModelImport(String name);
+
+ String toApiImport(String name);
+
+ void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map> operations);
+
+ Map postProcessModels(Map objs);
+
+ Map postProcessOperations(Map objs);
+
+ Map postProcessSupportingFileData(Map objs);
+
+ String apiFilename(String templateName, String tag);
+
+ boolean shouldOverwrite(String filename);
}
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 0cacc3a56e3..6a84274774c 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
@@ -1,16 +1,18 @@
package io.swagger.codegen;
-import io.swagger.models.*;
-import io.swagger.models.properties.*;
+import io.swagger.models.ExternalDocs;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
public class CodegenModel {
- public String parent;
- public String name, classname, description, classVarName, modelJson;
- public String defaultValue;
- public List vars = new ArrayList();
- public Set imports = new HashSet();
- public Boolean hasVars, emptyVars, hasMoreModels, hasEnums;
- public ExternalDocs externalDocs;
+ public String parent;
+ public String name, classname, description, classVarName, modelJson;
+ public String defaultValue;
+ public List vars = new ArrayList();
+ public Set imports = new HashSet();
+ public Boolean hasVars, emptyVars, hasMoreModels, hasEnums;
+ public ExternalDocs externalDocs;
}
\ No newline at end of file
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 06dfcfbc86b..4c2b4d4eb87 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,34 +5,35 @@ import java.util.Map;
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
- */
- public static void setTypeMapping(CodegenModelType type, Class> implementation) {
- if (!type.getDefaultImplementation().isAssignableFrom(implementation)) {
- throw new IllegalArgumentException(implementation.getSimpleName() + " doesn't extend " + type.getDefaultImplementation().getSimpleName());
+ /**
+ * 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
+ */
+ public static void setTypeMapping(CodegenModelType type, Class> implementation) {
+ if (!type.getDefaultImplementation().isAssignableFrom(implementation)) {
+ throw new IllegalArgumentException(implementation.getSimpleName() + " doesn't extend " + type.getDefaultImplementation().getSimpleName());
+ }
+ try {
+ implementation.newInstance();
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ typeMapping.put(type, implementation);
}
- try {
- implementation.newInstance();
- } catch (Exception e) {
- throw new IllegalArgumentException(e);
- }
- typeMapping.put(type, implementation);
- }
- @SuppressWarnings("unchecked")
- public static T newInstance(CodegenModelType type) {
- Class> classType = typeMapping.get(type);
- try {
- return (T) (classType != null ? classType : type.getDefaultImplementation()).newInstance();
- } catch (InstantiationException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
+ @SuppressWarnings("unchecked")
+ public static T newInstance(CodegenModelType type) {
+ Class> classType = typeMapping.get(type);
+ try {
+ return (T) (classType != null ? classType : type.getDefaultImplementation()).newInstance();
+ } catch (InstantiationException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException 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 8c082a899cd..dce8ab0e2e5 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,20 +2,20 @@ package io.swagger.codegen;
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;
+ private final Class> defaultImplementation;
- private CodegenModelType(Class> defaultImplementation) {
- this.defaultImplementation = defaultImplementation;
- }
+ private CodegenModelType(Class> defaultImplementation) {
+ this.defaultImplementation = defaultImplementation;
+ }
- public Class> getDefaultImplementation() {
- return defaultImplementation;
- }
+ public Class> getDefaultImplementation() {
+ return 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 f7bd875848c..b795f8e38e2 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
@@ -1,32 +1,35 @@
package io.swagger.codegen;
-import io.swagger.models.*;
+import io.swagger.models.ExternalDocs;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
public class CodegenOperation {
- public Boolean hasConsumes, hasProduces, hasParams, returnTypeIsPrimitive,
- returnSimpleType, subresourceOperation, isMapContainer, isListContainer,
- hasMore = Boolean.TRUE, isMultipart;
- public String path, operationId, returnType, httpMethod, returnBaseType,
- returnContainer, summary, notes, baseName, defaultResponse;
+ public final List responseHeaders = new ArrayList();
+ public Boolean hasConsumes, hasProduces, hasParams, returnTypeIsPrimitive,
+ returnSimpleType, subresourceOperation, isMapContainer, isListContainer,
+ hasMore = Boolean.TRUE, isMultipart;
+ public String path, operationId, returnType, httpMethod, returnBaseType,
+ returnContainer, summary, notes, baseName, defaultResponse;
+ public List