diff --git a/modules/swagger-codegen-distribution/pom.xml b/modules/swagger-codegen-distribution/pom.xml
new file mode 100644
index 00000000000..a70a79c27e1
--- /dev/null
+++ b/modules/swagger-codegen-distribution/pom.xml
@@ -0,0 +1,63 @@
+
+
+ com.wordnik
+ swagger-codegen-project
+ 2.1.0-SNAPSHOT
+ ../..
+
+ 4.0.0
+ com.wordnik
+ swagger-codegen-distribution
+ jar
+ swagger-codegen-distribution
+ 2.1.0-SNAPSHOT
+
+ src/test/scala
+ target/classes
+ target/test-classes
+ install
+ target
+ ${project.artifactId}-${project.version}
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 2.3
+
+
+ package
+
+ shade
+
+
+ false
+ true
+
+ ${java.io.tmpdir}/dependency-reduced-pom.xml
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+
+ com.wordnik.swagger.codegen.Codegen
+
+
+
+
+
+
+
+
+ com.wordnik
+ swagger-codegen
+ ${project.parent.version}
+
+
+
\ No newline at end of file
diff --git a/modules/swagger-codegen/pom.xml b/modules/swagger-codegen/pom.xml
new file mode 100644
index 00000000000..8f0de9f7ddb
--- /dev/null
+++ b/modules/swagger-codegen/pom.xml
@@ -0,0 +1,391 @@
+
+
+ com.wordnik
+ swagger-codegen-project
+ 2.1.0-SNAPSHOT
+ ../..
+
+ 4.0.0
+ com.wordnik
+ swagger-codegen
+ jar
+ swagger-codegen
+ 2.1.0-SNAPSHOT
+
+ src/main/java
+ install
+
+
+ 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
+
+
+
+
+ com.wordnik.swagger.codegen.Codegen
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+
+ true
+ com.wordnik.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
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 2.1.2
+
+
+ attach-sources
+ verify
+
+ jar-no-fork
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 2.7
+
+ true
+ 1.6
+ UTF-8
+ 1g
+
+ http://java.sun.com/javase/6/docs/api/
+
+ ${javadoc.package.exclude}
+
+
+
+ attach-javadocs
+ verify
+
+ jar
+
+
+
+
+
+ maven-compiler-plugin
+ 3.0
+
+ 1.6
+ 1.6
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.4
+
+
+
+ development
+ ${project.url}
+ ${project.version}
+ com.wordnik
+
+
+
+
+
+ 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
+
+
+
+
+ net.alchim31.maven
+ scala-maven-plugin
+
+
+
+ compile
+ testCompile
+
+
+
+
+
+
+ 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-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}
+
+
+ io.swagger
+ swagger-legacy-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
+
+
+
+
+ sonatype-snapshots
+ https://oss.sonatype.org/content/repositories/snapshots
+
+ true
+
+
+
+
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/ClientOptInput.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/ClientOptInput.java
new file mode 100644
index 00000000000..cdfb1191b2f
--- /dev/null
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/ClientOptInput.java
@@ -0,0 +1,59 @@
+/**
+ * Copyright 2014 Reverb, Inc.
+ *
+ * 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.
+ */
+
+package com.wordnik.swagger.codegen;
+
+import com.wordnik.swagger.codegen.ClientOpts;
+
+import com.wordnik.swagger.models.Swagger;
+
+public class ClientOptInput {
+ private ClientOpts opts;
+ private Swagger swagger;
+ protected CodegenConfig config;
+
+ public ClientOptInput swagger(Swagger swagger) {
+ this.setSwagger(swagger);
+ return this;
+ }
+ public ClientOptInput opts(ClientOpts opts) {
+ this.setOpts(opts);
+ return this;
+ }
+
+ public CodegenConfig getConfig() {
+ return config;
+ }
+ public void setConfig(CodegenConfig config) {
+ this.config = config;
+ }
+
+ public void setOpts(ClientOpts opts) {
+ this.opts = opts;
+ }
+
+ public ClientOpts getOpts() {
+ return opts;
+ }
+
+ public void setSwagger(Swagger swagger) {
+ this.swagger = swagger;
+ }
+
+ public Swagger getSwagger() {
+ return swagger;
+ }
+}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/ClientOpts.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/ClientOpts.java
new file mode 100644
index 00000000000..b8d681cc307
--- /dev/null
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/ClientOpts.java
@@ -0,0 +1,52 @@
+package com.wordnik.swagger.codegen;
+
+import com.wordnik.swagger.codegen.auth.*;
+
+import java.util.*;
+
+public class ClientOpts {
+ 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 getTarget() {
+ return target;
+ }
+ public void setTarget(String target) {
+ this.target = target;
+ }
+
+ 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/com/wordnik/swagger/codegen/Codegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/Codegen.java
new file mode 100644
index 00000000000..c9e39c7f2f3
--- /dev/null
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/Codegen.java
@@ -0,0 +1,123 @@
+package com.wordnik.swagger.codegen;
+
+import com.wordnik.swagger.codegen.languages.*;
+import com.wordnik.swagger.models.Swagger;
+import com.wordnik.swagger.util.*;
+
+import io.swagger.parser.SwaggerParser;
+
+import org.apache.commons.cli.*;
+
+import java.io.File;
+import java.util.*;
+
+public class Codegen extends DefaultGenerator {
+ 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) {
+ List extensions = getExtensions();
+ Map configs = new HashMap();
+
+ StringBuilder sb = new StringBuilder();
+ for(CodegenConfig config : extensions) {
+ if(sb.toString().length() != 0)
+ sb.append(", ");
+ sb.append(config.getName());
+ configs.put(config.getName(), config);
+ }
+
+ 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[" + sb.toString() + "]");
+ 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");
+
+ ClientOptInput clientOptInput = new ClientOptInput();
+ ClientOpts clientOpts = new ClientOpts();
+ Swagger swagger = 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("l"))
+ clientOptInput.setConfig(getConfig(cmd.getOptionValue("l"), configs));
+ 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")), configs);
+ 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"));
+ if (cmd.hasOption("t"))
+ clientOpts.getProperties().put("templateDir", String.valueOf(cmd.getOptionValue("t")));
+ }
+ 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());
+ }
+ return output;
+ }
+
+ static void usage(Options options) {
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp( "Codegen", options );
+ }
+
+ static CodegenConfig getConfig(String name, Map configs) {
+ 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);
+ }
+ }
+ }
+}
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenConfig.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenConfig.java
new file mode 100644
index 00000000000..73abe291c1d
--- /dev/null
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenConfig.java
@@ -0,0 +1,51 @@
+package com.wordnik.swagger.codegen;
+
+import com.wordnik.swagger.models.*;
+import com.wordnik.swagger.models.properties.*;
+
+import java.util.*;
+
+public interface CodegenConfig {
+ 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 toModelName(String name);
+ String toParamName(String name);
+ String escapeReservedWord(String name);
+ String getTypeDeclaration(Property p);
+ String getTypeDeclaration(String name);
+ void processOpts();
+
+ Set reservedWords();
+
+ List supportingFiles();
+
+ void setOutputDir(String dir);
+ String getOutputDir();
+
+ CodegenModel fromModel(String name, Model model);
+ CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation);
+ 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);
+}
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenModel.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenModel.java
new file mode 100644
index 00000000000..169886da22e
--- /dev/null
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenModel.java
@@ -0,0 +1,16 @@
+package com.wordnik.swagger.codegen;
+
+import com.wordnik.swagger.models.*;
+import com.wordnik.swagger.models.properties.*;
+
+import java.util.*;
+
+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;
+ public ExternalDocs externalDocs;
+}
\ No newline at end of file
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenModelFactory.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenModelFactory.java
new file mode 100644
index 00000000000..b369623f37c
--- /dev/null
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenModelFactory.java
@@ -0,0 +1,38 @@
+package com.wordnik.swagger.codegen;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public final class CodegenModelFactory {
+
+ 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());
+ }
+ 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);
+ }
+ }
+}
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenModelType.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenModelType.java
new file mode 100644
index 00000000000..41c877532f0
--- /dev/null
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenModelType.java
@@ -0,0 +1,20 @@
+package com.wordnik.swagger.codegen;
+
+public enum CodegenModelType {
+
+ MODEL(CodegenModel.class),
+ OPERATION(CodegenOperation.class),
+ PARAMETER(CodegenParameter.class),
+ PROPERTY(CodegenProperty.class),
+ RESPONSE(CodegenResponse.class);
+
+ private final Class> defaultImplementation;
+
+ private CodegenModelType(Class> defaultImplementation) {
+ this.defaultImplementation = defaultImplementation;
+ }
+
+ public Class> getDefaultImplementation() {
+ return defaultImplementation;
+ }
+}
diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenOperation.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenOperation.java
new file mode 100644
index 00000000000..3609e53d9ee
--- /dev/null
+++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenOperation.java
@@ -0,0 +1,29 @@
+package com.wordnik.swagger.codegen;
+
+import com.wordnik.swagger.models.*;
+
+import java.util.*;
+
+public class CodegenOperation {
+ public Boolean hasConsumes, hasProduces, hasParams, returnTypeIsPrimitive, returnSimpleType, subresourceOperation;
+ public String path, operationId, returnType, httpMethod, returnBaseType,
+ returnContainer, summary, notes, baseName, defaultResponse;
+
+ public List