diff --git a/.gitignore b/.gitignore
index 24bb9709fc3..a0e39ffd165 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,7 @@ version.properties
lib/*
build/*
generated-files/*
+generated-sources/*
generated-code/*
*.swp
*.swo
diff --git a/bin/all-petstore.sh b/bin/all-petstore.sh
index ea5aad656b5..d44a7b1cb7c 100755
--- a/bin/all-petstore.sh
+++ b/bin/all-petstore.sh
@@ -35,3 +35,5 @@ cd $APP_DIR
./bin/silex-petstore-server.sh
./bin/spring-mvc-petstore-server.sh
./bin/tizen-petstore.sh
+./bin/typescript-angular-petstore.sh
+./bin/typescript-node-petstore.sh
diff --git a/bin/csharp-petstore.sh b/bin/csharp-petstore.sh
index a72a6cf84f0..c3fe78f0f36 100755
--- a/bin/csharp-petstore.sh
+++ b/bin/csharp-petstore.sh
@@ -26,6 +26,6 @@ fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
-ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l csharp -o samples/client/petstore/csharp"
+ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l csharp -o samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient"
java $JAVA_OPTS -jar $executable $ags
diff --git a/bin/silex-petstore-server.sh b/bin/silex-petstore-server.sh
index 5ead9db0002..ffa030b88c3 100755
--- a/bin/silex-petstore-server.sh
+++ b/bin/silex-petstore-server.sh
@@ -26,6 +26,6 @@ fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
-ags="$@ generate -t modules/swagger-codegen/src/main/resources/silex -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l silex -o samples/client/petstore/silex"
+ags="$@ generate -t modules/swagger-codegen/src/main/resources/silex -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l silex -o samples/server/petstore/silex"
java $JAVA_OPTS -jar $executable $ags
diff --git a/bin/sinatra-petstore-server.sh b/bin/sinatra-petstore-server.sh
new file mode 100755
index 00000000000..4f7e19cee39
--- /dev/null
+++ b/bin/sinatra-petstore-server.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+SCRIPT="$0"
+
+while [ -h "$SCRIPT" ] ; do
+ ls=`ls -ld "$SCRIPT"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ SCRIPT="$link"
+ else
+ SCRIPT=`dirname "$SCRIPT"`/"$link"
+ fi
+done
+
+if [ ! -d "${APP_DIR}" ]; then
+ APP_DIR=`dirname "$SCRIPT"`/..
+ APP_DIR=`cd "${APP_DIR}"; pwd`
+fi
+
+executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
+
+if [ ! -f "$executable" ]
+then
+ mvn clean package
+fi
+
+# if you've executed sbt assembly previously it will use that instead.
+export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
+ags="$@ generate -t modules/swagger-codegen/src/main/resources/sinatra -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l sinatra -o samples/server/petstore/sinatra"
+
+java $JAVA_OPTS -jar $executable $ags
diff --git a/bin/typescript-angular-petstore.sh b/bin/typescript-angular-petstore.sh
new file mode 100755
index 00000000000..60c10790c90
--- /dev/null
+++ b/bin/typescript-angular-petstore.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+SCRIPT="$0"
+
+while [ -h "$SCRIPT" ] ; do
+ ls=`ls -ld "$SCRIPT"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ SCRIPT="$link"
+ else
+ SCRIPT=`dirname "$SCRIPT"`/"$link"
+ fi
+done
+
+if [ ! -d "${APP_DIR}" ]; then
+ APP_DIR=`dirname "$SCRIPT"`/..
+ APP_DIR=`cd "${APP_DIR}"; pwd`
+fi
+
+executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
+
+if [ ! -f "$executable" ]
+then
+ mvn clean package
+fi
+
+# if you've executed sbt assembly previously it will use that instead.
+export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
+ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-angular -o samples/client/petstore/typescript-angular"
+
+java $JAVA_OPTS -jar $executable $ags
diff --git a/bin/typescript-node-petstore.sh b/bin/typescript-node-petstore.sh
new file mode 100755
index 00000000000..53c5a6f8d82
--- /dev/null
+++ b/bin/typescript-node-petstore.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+SCRIPT="$0"
+
+while [ -h "$SCRIPT" ] ; do
+ ls=`ls -ld "$SCRIPT"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ SCRIPT="$link"
+ else
+ SCRIPT=`dirname "$SCRIPT"`/"$link"
+ fi
+done
+
+if [ ! -d "${APP_DIR}" ]; then
+ APP_DIR=`dirname "$SCRIPT"`/..
+ APP_DIR=`cd "${APP_DIR}"; pwd`
+fi
+
+executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
+
+if [ ! -f "$executable" ]
+then
+ mvn clean package
+fi
+
+# if you've executed sbt assembly previously it will use that instead.
+export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
+ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-node -o samples/client/petstore/typescript-node"
+
+java $JAVA_OPTS -jar $executable $ags
diff --git a/modules/swagger-codegen-maven-plugin/README.md b/modules/swagger-codegen-maven-plugin/README.md
new file mode 100644
index 00000000000..a7eaf852a22
--- /dev/null
+++ b/modules/swagger-codegen-maven-plugin/README.md
@@ -0,0 +1,41 @@
+swagger-codegen-maven-plugin
+============================
+
+A Maven plugin to support the [swagger](http://swagger.io) code generation project
+
+Usage
+============================
+
+Add to your `build->plugins` section (default phase is `generate-sources` phase)
+```xml
+
+ io.swagger
+ swagger-codegen-maven-plugin
+ ${project.version}
+
+
+
+ generate
+
+
+ src/main/resources/api.yaml
+ java
+
+
+
+
+```
+
+Followed by:
+
+```
+mvn clean compile
+```
+
+### Configuration parameters
+
+- `inputSpec` - swagger spec file path
+- `language` - target generation language
+- `output` - target output path (default is `${project.build.directory}/generated-sources/swagger`)
+- `templateDirectory` - directory with mustache templates
+- `addCompileSourceRoot` - add the output directory to the project as a source root (`true` by default)
diff --git a/modules/swagger-codegen-maven-plugin/pom.xml b/modules/swagger-codegen-maven-plugin/pom.xml
new file mode 100644
index 00000000000..7ad4496872c
--- /dev/null
+++ b/modules/swagger-codegen-maven-plugin/pom.xml
@@ -0,0 +1,87 @@
+
+
+ 4.0.0
+
+
+ io.swagger
+ swagger-codegen-project
+ 2.1.3-SNAPSHOT
+ ../..
+
+ swagger-codegen-maven-plugin
+ swagger-codegen (maven-plugin)
+ maven-plugin
+ maven plugin to build modules from swagger codegen
+
+ UTF-8
+
+
+
+ org.apache.maven
+ maven-core
+ 3.2.5
+
+
+ org.apache.maven
+ maven-artifact
+ 3.2.5
+ provided
+
+
+ org.apache.maven
+ maven-compat
+ 3.2.5
+
+
+ org.apache.maven
+ maven-plugin-api
+ 3.2.5
+
+
+ org.apache.maven.plugin-tools
+ maven-plugin-annotations
+ 3.4
+
+
+ io.swagger
+ swagger-codegen
+ ${project.version}
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-plugin-plugin
+ 3.4
+
+ true
+
+
+
+ mojo-descriptor
+ process-classes
+
+ descriptor
+
+
+
+ help-goal
+
+ helpmojo
+
+
+
+
+
+
+
+
diff --git a/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/AdditionalParams.java b/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/AdditionalParams.java
new file mode 100644
index 00000000000..aa137cbf6c3
--- /dev/null
+++ b/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/AdditionalParams.java
@@ -0,0 +1,16 @@
+package io.swagger.codegen.plugin;
+
+/**
+ * User: lanwen
+ * Date: 24.03.15
+ * Time: 14:47
+ */
+public final class AdditionalParams {
+ public static final String TEMPLATE_DIR_PARAM = "templateDir";
+
+ private AdditionalParams() {
+
+ }
+
+
+}
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
new file mode 100644
index 00000000000..26b6fef1135
--- /dev/null
+++ b/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java
@@ -0,0 +1,118 @@
+package io.swagger.codegen.plugin;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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 io.swagger.parser.SwaggerParser;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+
+import java.io.File;
+import java.util.ServiceLoader;
+
+import static io.swagger.codegen.plugin.AdditionalParams.TEMPLATE_DIR_PARAM;
+
+/**
+ * Goal which generates client/server code from a swagger json/yaml definition.
+ */
+@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
+public class CodeGenMojo extends AbstractMojo {
+
+ /**
+ * Location of the output directory.
+ */
+ @Parameter(name = "output",
+ property = "swagger.codegen.maven.plugin.output",
+ defaultValue = "${project.build.directory}/generated-sources/swagger")
+ private File output;
+
+ /**
+ * Location of the swagger spec, as URL or file.
+ */
+ @Parameter(name = "inputSpec", required = true)
+ private String inputSpec;
+
+ /**
+ * Folder containing the template files.
+ */
+ @Parameter(name = "templateDirectory")
+ private File templateDirectory;
+
+ /**
+ * Client language to generate.
+ */
+ @Parameter(name = "language", required = true)
+ private String language;
+
+
+ /**
+ * 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;
+
+ /**
+ * The project being built.
+ */
+ @Parameter(readonly = true, required = true, defaultValue = "${project}")
+ private MavenProject project;
+
+ @Override
+ public void execute() throws MojoExecutionException {
+ Swagger swagger = new SwaggerParser().read(inputSpec);
+
+ CodegenConfig config = forName(language);
+ config.setOutputDir(output.getAbsolutePath());
+
+ if (null != templateDirectory) {
+ config.additionalProperties().put(TEMPLATE_DIR_PARAM, templateDirectory.getAbsolutePath());
+ }
+
+ ClientOptInput input = new ClientOptInput().opts(new ClientOpts()).swagger(swagger);
+ input.setConfig(config);
+ new DefaultGenerator().opts(input).generate();
+
+ if (addCompileSourceRoot) {
+ project.addCompileSourceRoot(output.toString());
+ }
+ }
+
+ private CodegenConfig forName(String name) {
+ ServiceLoader loader = ServiceLoader.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/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java
index a564ec5f883..33ea13b5e31 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java
@@ -7,6 +7,7 @@ import io.swagger.codegen.SupportingFile;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.MapProperty;
import io.swagger.models.properties.Property;
+import io.swagger.codegen.CliOption;
import java.io.File;
import java.util.Arrays;
@@ -14,15 +15,14 @@ import java.util.HashMap;
import java.util.HashSet;
public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig {
- protected String invokerPackage = "IO.Swagger.Client";
- protected String groupId = "io.swagger";
- protected String artifactId = "swagger-csharp-client";
- protected String artifactVersion = "1.0.0";
- protected String sourceFolder = "src/main/csharp";
+ protected String packageName = "IO.Swagger";
+ protected String packageVersion = "1.0.0";
+ protected String clientPackage = "IO.Swagger.Client";
+ protected String sourceFolder = "src" + File.separator + "main" + File.separator + "csharp";
public CSharpClientCodegen() {
super();
- outputFolder = "generated-code/csharp";
+ outputFolder = "generated-code" + File.separator + "csharp";
modelTemplateFiles.put("model.mustache", ".cs");
apiTemplateFiles.put("api.mustache", ".cs");
templateDir = "csharp";
@@ -34,17 +34,6 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while")
);
- additionalProperties.put("invokerPackage", invokerPackage);
-
- supportingFiles.add(new SupportingFile("Configuration.mustache",
- (sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "Configuration.cs"));
- supportingFiles.add(new SupportingFile("ApiClient.mustache",
- (sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiClient.cs"));
- supportingFiles.add(new SupportingFile("ApiException.mustache",
- (sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ApiException.cs"));
- supportingFiles.add(new SupportingFile("Newtonsoft.Json.dll", "bin", "Newtonsoft.Json.dll"));
- supportingFiles.add(new SupportingFile("RestSharp.dll", "bin", "RestSharp.dll"));
- supportingFiles.add(new SupportingFile("compile.mustache", "", "compile.bat"));
languageSpecificPrimitives = new HashSet(
Arrays.asList(
@@ -85,6 +74,43 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
typeMapping.put("map", "Dictionary");
typeMapping.put("object", "Object");
+ cliOptions.clear();
+ cliOptions.add(new CliOption("packageName", "C# package name (convention: Camel.Case), default: IO.Swagger"));
+ cliOptions.add(new CliOption("packageVersion", "C# package version, default: 1.0.0"));
+
+ }
+
+ @Override
+ public void processOpts() {
+ super.processOpts();
+
+ if (additionalProperties.containsKey("packageVersion")) {
+ packageVersion = (String) additionalProperties.get("packageVersion");
+ } else {
+ additionalProperties.put("packageVersion", packageVersion);
+ }
+
+ if (additionalProperties.containsKey("packageName")) {
+ packageName = (String) additionalProperties.get("packageName");
+ apiPackage = packageName + ".Api";
+ modelPackage = packageName + ".Model";
+ clientPackage = packageName + ".Client";
+ } else {
+ additionalProperties.put("packageName", packageName);
+ }
+
+ additionalProperties.put("clientPackage", clientPackage);
+
+ supportingFiles.add(new SupportingFile("Configuration.mustache",
+ (sourceFolder + File.separator + clientPackage).replace(".", java.io.File.separator), "Configuration.cs"));
+ supportingFiles.add(new SupportingFile("ApiClient.mustache",
+ (sourceFolder + File.separator + clientPackage).replace(".", java.io.File.separator), "ApiClient.cs"));
+ supportingFiles.add(new SupportingFile("ApiException.mustache",
+ (sourceFolder + File.separator + clientPackage).replace(".", java.io.File.separator), "ApiException.cs"));
+ supportingFiles.add(new SupportingFile("Newtonsoft.Json.dll", "bin", "Newtonsoft.Json.dll"));
+ supportingFiles.add(new SupportingFile("RestSharp.dll", "bin", "RestSharp.dll"));
+ supportingFiles.add(new SupportingFile("compile.mustache", "", "compile.bat"));
+
}
public CodegenType getTag() {
@@ -106,11 +132,11 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
@Override
public String apiFileFolder() {
- return (outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', '/')).replace('.', File.separatorChar);
+ return (outputFolder + File.separator + sourceFolder + File.separator + apiPackage()).replace('.', File.separatorChar);
}
public String modelFileFolder() {
- return (outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', '/')).replace('.', File.separatorChar);
+ return (outputFolder + File.separator + sourceFolder + File.separator + modelPackage()).replace('.', File.separatorChar);
}
@Override
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java
index 0690163f137..e2ddba4bf34 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java
@@ -1,5 +1,6 @@
package io.swagger.codegen.languages;
+import io.swagger.codegen.CliOption;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.CodegenType;
import io.swagger.codegen.DefaultCodegen;
@@ -18,12 +19,14 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
protected String invokerPackage = "Swagger\\Client";
protected String groupId = "swagger";
protected String artifactId = "swagger-client";
+ protected String packagePath = "SwaggerClient-php";
protected String artifactVersion = null;
+ protected String srcBasePath = "lib";
public PhpClientCodegen() {
super();
- outputFolder = "generated-code/php";
+ outputFolder = "generated-code" + File.separator + "php";
modelTemplateFiles.put("model.mustache", ".php");
apiTemplateFiles.put("api.mustache", ".php");
templateDir = "php";
@@ -38,6 +41,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
additionalProperties.put("invokerPackage", invokerPackage);
additionalProperties.put("modelPackage", modelPackage);
additionalProperties.put("apiPackage", apiPackage);
+ additionalProperties.put("srcBasePath", srcBasePath);
additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\"));
additionalProperties.put("groupId", groupId);
additionalProperties.put("artifactId", artifactId);
@@ -81,16 +85,13 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("list", "array");
typeMapping.put("object", "object");
typeMapping.put("DateTime", "\\DateTime");
-
- supportingFiles.add(new SupportingFile("composer.mustache", getPackagePath(), "composer.json"));
- supportingFiles.add(new SupportingFile("configuration.mustache", toPackagePath(invokerPackage, "lib"), "Configuration.php"));
- supportingFiles.add(new SupportingFile("ApiClient.mustache", toPackagePath(invokerPackage, "lib"), "ApiClient.php"));
- supportingFiles.add(new SupportingFile("ApiException.mustache", toPackagePath(invokerPackage, "lib"), "ApiException.php"));
- supportingFiles.add(new SupportingFile("autoload.mustache", getPackagePath(), "autoload.php"));
+
+ cliOptions.add(new CliOption("packagePath", "main package name for classes"));
+ cliOptions.add(new CliOption("srcBasePath", "directory directory under packagePath to serve as source root"));
}
public String getPackagePath() {
- return "SwaggerClient-php";
+ return packagePath;
}
public String toPackagePath(String packageName, String basePath) {
@@ -99,13 +100,27 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separatorChar;
}
+ String regFirstPathSeparator;
+ if ("/".equals(File.separator)) { // for mac, linux
+ regFirstPathSeparator = "^/";
+ } else { // for windows
+ regFirstPathSeparator = "^\\\\";
+ }
+
+ String regLastPathSeparator;
+ if ("/".equals(File.separator)) { // for mac, linux
+ regLastPathSeparator = "/$";
+ } else { // for windows
+ regLastPathSeparator = "\\\\$";
+ }
+
return (getPackagePath() + File.separatorChar + basePath
// Replace period, backslash, forward slash with file separator in package name
+ packageName.replaceAll("[\\.\\\\/]", File.separator)
// Trim prefix file separators from package path
- .replaceAll("^" + File.separator, ""))
- // Trim trailing file separators from the overall path
- .replaceAll(File.separator + "$", "");
+ .replaceAll(regFirstPathSeparator, ""))
+ // Trim trailing file separators from the overall path
+ .replaceAll(regLastPathSeparator+ "$", "");
}
public CodegenType getTag() {
@@ -120,6 +135,39 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
return "Generates a PHP client library.";
}
+ @Override
+ public void processOpts() {
+ super.processOpts();
+
+ if (additionalProperties.containsKey("packagePath")) {
+ this.setPackagePath((String) additionalProperties.get("packagePath"));
+ }
+
+ if (additionalProperties.containsKey("srcBasePath")) {
+ this.setSrcBasePath((String) additionalProperties.get("srcBasePath"));
+ }
+
+ if (additionalProperties.containsKey("modelPackage")) {
+ this.setModelPackage((String) additionalProperties.get("modelPackage"));
+ }
+
+ if (additionalProperties.containsKey("apiPackage")) {
+ this.setApiPackage((String) additionalProperties.get("apiPackage"));
+ }
+
+ additionalProperties.put("srcBasePath", srcBasePath);
+ additionalProperties.put("modelPackage", modelPackage);
+ additionalProperties.put("apiPackage", apiPackage);
+ additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\"));
+
+ supportingFiles.add(new SupportingFile("configuration.mustache", toPackagePath(invokerPackage, srcBasePath), "Configuration.php"));
+ supportingFiles.add(new SupportingFile("ApiClient.mustache", toPackagePath(invokerPackage, srcBasePath), "ApiClient.php"));
+ supportingFiles.add(new SupportingFile("ApiException.mustache", toPackagePath(invokerPackage, srcBasePath), "ApiException.php"));
+ supportingFiles.add(new SupportingFile("ObjectSerializer.mustache", toPackagePath(invokerPackage, srcBasePath), "ObjectSerializer.php"));
+ supportingFiles.add(new SupportingFile("composer.mustache", getPackagePath(), "composer.json"));
+ supportingFiles.add(new SupportingFile("autoload.mustache", getPackagePath(), "autoload.php"));
+ }
+
@Override
public String escapeReservedWord(String name) {
return "_" + name;
@@ -127,11 +175,11 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override
public String apiFileFolder() {
- return (outputFolder + "/" + toPackagePath(apiPackage(), "lib"));
+ return (outputFolder + "/" + toPackagePath(apiPackage(), srcBasePath));
}
public String modelFileFolder() {
- return (outputFolder + "/" + toPackagePath(modelPackage(), "lib"));
+ return (outputFolder + "/" + toPackagePath(modelPackage(), srcBasePath));
}
@Override
@@ -184,6 +232,17 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
return "null";
}
+ public void setInvokerPackage(String invokerPackage) {
+ this.invokerPackage = invokerPackage;
+ }
+
+ public void setPackagePath(String packagePath) {
+ this.packagePath = packagePath;
+ }
+
+ public void setSrcBasePath(String srcBasePath) {
+ this.srcBasePath = srcBasePath;
+ }
@Override
public String toVarName(String name) {
@@ -221,5 +280,4 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
// should be the same as the model name
return toModelName(name);
}
-
}
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java
index a14fa71f425..475a816aa5c 100755
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java
@@ -1,5 +1,6 @@
package io.swagger.codegen.languages;
+import io.swagger.codegen.CliOption;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.CodegenType;
import io.swagger.codegen.DefaultCodegen;
@@ -13,25 +14,19 @@ import java.util.Arrays;
import java.util.HashSet;
public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig {
- protected String module = "SwaggerPetstore";
- protected String invokerPackage;
- protected String eggPackage;
+ protected String packageName = null;
+ protected String packageVersion = null;
public PythonClientCodegen() {
super();
- eggPackage = module + "-python";
-
- invokerPackage = eggPackage + File.separatorChar + module;
-
+ modelPackage = "models";
+ apiPackage = "api";
outputFolder = "generated-code" + File.separatorChar + "python";
modelTemplateFiles.put("model.mustache", ".py");
apiTemplateFiles.put("api.mustache", ".py");
templateDir = "python";
- apiPackage = invokerPackage + File.separatorChar + "apis";
- modelPackage = invokerPackage + File.separatorChar + "models";
-
languageSpecificPrimitives.clear();
languageSpecificPrimitives.add("int");
languageSpecificPrimitives.add("float");
@@ -60,14 +55,43 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
"print", "class", "exec", "in", "raise", "continue", "finally", "is",
"return", "def", "for", "lambda", "try"));
- additionalProperties.put("module", module);
+ cliOptions.clear();
+ cliOptions.add(new CliOption("packageName", "python package name (convension: under_score), default: swagger_client"));
+ cliOptions.add(new CliOption("packageVersion", "python package version, default: 1.0.0"));
+ }
- supportingFiles.add(new SupportingFile("README.mustache", eggPackage, "README.md"));
- supportingFiles.add(new SupportingFile("setup.mustache", eggPackage, "setup.py"));
- supportingFiles.add(new SupportingFile("api_client.mustache", invokerPackage, "api_client.py"));
- supportingFiles.add(new SupportingFile("rest.mustache", invokerPackage, "rest.py"));
- supportingFiles.add(new SupportingFile("configuration.mustache", invokerPackage, "configuration.py"));
- supportingFiles.add(new SupportingFile("__init__package.mustache", invokerPackage, "__init__.py"));
+ @Override
+ public void processOpts() {
+ super.processOpts();
+
+ if (additionalProperties.containsKey("packageName")) {
+ setPackageName((String) additionalProperties.get("packageName"));
+ }
+ else {
+ setPackageName("swagger_client");
+ }
+
+ if (additionalProperties.containsKey("packageVersion")) {
+ setPackageVersion((String) additionalProperties.get("packageVersion"));
+ }
+ else {
+ setPackageVersion("1.0.0");
+ }
+
+ additionalProperties.put("packageName", packageName);
+ additionalProperties.put("packageVersion", packageVersion);
+
+ String swaggerFolder = packageName;
+
+ modelPackage = swaggerFolder + File.separatorChar + "models";
+ apiPackage = swaggerFolder + File.separatorChar + "apis";
+
+ supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
+ supportingFiles.add(new SupportingFile("setup.mustache", "", "setup.py"));
+ supportingFiles.add(new SupportingFile("api_client.mustache", swaggerFolder, "api_client.py"));
+ supportingFiles.add(new SupportingFile("rest.mustache", swaggerFolder, "rest.py"));
+ supportingFiles.add(new SupportingFile("configuration.mustache", swaggerFolder, "configuration.py"));
+ supportingFiles.add(new SupportingFile("__init__package.mustache", swaggerFolder, "__init__.py"));
supportingFiles.add(new SupportingFile("__init__model.mustache", modelPackage, "__init__.py"));
supportingFiles.add(new SupportingFile("__init__api.mustache", apiPackage, "__init__.py"));
}
@@ -225,4 +249,23 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
return underscore(operationId);
}
+ public void setPackageName(String packageName) {
+ this.packageName = packageName;
+ }
+
+ public void setPackageVersion(String packageVersion) {
+ this.packageVersion = packageVersion;
+ }
+
+ /**
+ * Generate Python package name from String `packageName`
+ *
+ * (PEP 0008) Python packages should also have short, all-lowercase names,
+ * although the use of underscores is discouraged.
+ */
+ public String generatePackageName(String packageName) {
+ return underscore(packageName.replaceAll("[^\\w]+", ""));
+ }
}
+
+
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ScalaClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ScalaClientCodegen.java
index d8c143aad1d..6ad296a0210 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ScalaClientCodegen.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/ScalaClientCodegen.java
@@ -20,6 +20,9 @@ import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig {
protected String invokerPackage = "io.swagger.client";
@@ -214,4 +217,17 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig
return camelize(operationId, true);
}
+ @Override
+ public Map postProcessModels(Map objs) {
+ // remove model imports to avoid warnings for importing class in the same package in Scala
+ List