forked from loafle/openapi-generator-original
Merge remote-tracking branch 'upstream/master' into objc-dictionary-fix-dev2_0
This commit is contained in:
commit
e5357df67a
20
README.md
20
README.md
@ -13,12 +13,12 @@ The goal of Swagger™ is to define a standard, language-agnostic interface to R
|
|||||||
Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additional information about the Swagger project, including additional libraries with support for other languages and more.
|
Check out [Swagger-Spec](https://github.com/swagger-api/swagger-spec) for additional information about the Swagger project, including additional libraries with support for other languages and more.
|
||||||
|
|
||||||
|
|
||||||
## Compatability
|
## Compatibility
|
||||||
The Swagger Specification has undergone 3 revisions since initial creation in 2010. The swagger-codegen project has the following compatibilies with the swagger specification:
|
The Swagger Specification has undergone 3 revisions since initial creation in 2010. The swagger-codegen project has the following compatibilities with the swagger specification:
|
||||||
|
|
||||||
Swagger Codegen Version | Release Date | Swagger Spec compatability | Notes
|
Swagger Codegen Version | Release Date | Swagger Spec compatibility | Notes
|
||||||
----------------------- | ------------ | -------------------------- | -----
|
----------------------- | ------------ | -------------------------- | -----
|
||||||
2.1.0-M1 | 2015-02-16 | 1.0, 1.1, 1.2, 2.0 | [tag v2.1.0-M1](https://github.com/swagger-api/swagger-codegen/tree/v2.1.0-M1)
|
2.1.2-M1 (master) | 2015-02-23 | 1.0, 1.1, 1.2, 2.0 | [tag v2.1.0-M1](https://github.com/swagger-api/swagger-codegen)
|
||||||
2.0.17 | 2014-08-22 | 1.1, 1.2 | [tag v2.0.17](https://github.com/swagger-api/swagger-codegen/tree/v2.0.17)
|
2.0.17 | 2014-08-22 | 1.1, 1.2 | [tag v2.0.17](https://github.com/swagger-api/swagger-codegen/tree/v2.0.17)
|
||||||
1.0.4 | 2012-04-12 | 1.0, 1.1 | [tag v1.0.4](https://github.com/swagger-api/swagger-codegen/tree/swagger-codegen_2.9.1-1.1)
|
1.0.4 | 2012-04-12 | 1.0, 1.1 | [tag v1.0.4](https://github.com/swagger-api/swagger-codegen/tree/swagger-codegen_2.9.1-1.1)
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ You can build a client against the swagger sample [petstore](http://petstore.swa
|
|||||||
This will run the generator with this command:
|
This will run the generator with this command:
|
||||||
|
|
||||||
```
|
```
|
||||||
java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.0-M1.jar \
|
java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.2-M1.jar \
|
||||||
-i http://petstore.swagger.io/v2/swagger.json \
|
-i http://petstore.swagger.io/v2/swagger.json \
|
||||||
-l java \
|
-l java \
|
||||||
-o samples/client/petstore/java
|
-o samples/client/petstore/java
|
||||||
@ -91,7 +91,7 @@ It's just as easy--just use the `-i` flag to point to either a server or file.
|
|||||||
### Modifying the client library format
|
### Modifying the client library format
|
||||||
Don't like the default swagger client syntax? Want a different language supported? No problem! Swagger codegen processes mustache templates with the [jmustache](https://github.com/samskivert/jmustache) engine. You can modify our templates or make your own.
|
Don't like the default swagger client syntax? Want a different language supported? No problem! Swagger codegen processes mustache templates with the [jmustache](https://github.com/samskivert/jmustache) engine. You can modify our templates or make your own.
|
||||||
|
|
||||||
You can look at `src/main/resources/${your-language}` for examples. To make your own templates, create your own files and use the `-t` flag to specify your tempalte folder. It actually is that easy.
|
You can look at `modules/swagger-codegen/src/main/resources/${your-language}` for examples. To make your own templates, create your own files and use the `-t` flag to specify your tempalte folder. It actually is that easy.
|
||||||
|
|
||||||
### Where is Javascript???
|
### Where is Javascript???
|
||||||
See our [javascript library](http://github.com/swagger-api/swagger-js)--it's completely dynamic and doesn't require
|
See our [javascript library](http://github.com/swagger-api/swagger-js)--it's completely dynamic and doesn't require
|
||||||
@ -149,7 +149,7 @@ public class MyObjcCodegen extends ObjcClientCodegen {
|
|||||||
and specify the `classname` when running the generator:
|
and specify the `classname` when running the generator:
|
||||||
|
|
||||||
```
|
```
|
||||||
-i com.mycompany.swagger.codegen.MyObjcCodegen
|
-l com.mycompany.swagger.codegen.MyObjcCodegen
|
||||||
```
|
```
|
||||||
|
|
||||||
Your subclass will now be loaded and overrides the `PREFIX` value in the superclass.
|
Your subclass will now be loaded and overrides the `PREFIX` value in the superclass.
|
||||||
@ -189,7 +189,7 @@ You can also use the codegen to generate a server for a couple different framewo
|
|||||||
|
|
||||||
### node.js
|
### node.js
|
||||||
```
|
```
|
||||||
java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.0-M1.jar \
|
java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.2-M1.jar \
|
||||||
-i http://petstore.swagger.io/v2/swagger.json \
|
-i http://petstore.swagger.io/v2/swagger.json \
|
||||||
-l nodejs \
|
-l nodejs \
|
||||||
-o samples/server/petstore/nodejs
|
-o samples/server/petstore/nodejs
|
||||||
@ -201,7 +201,7 @@ java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distributi
|
|||||||
|
|
||||||
### scala scalatra
|
### scala scalatra
|
||||||
```
|
```
|
||||||
java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.0-M1.jar \
|
java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.2-M1.jar \
|
||||||
-i http://petstore.swagger.io/v2/swagger.json \
|
-i http://petstore.swagger.io/v2/swagger.json \
|
||||||
-l scalatra \
|
-l scalatra \
|
||||||
-o samples/server/petstore/scalatra
|
-o samples/server/petstore/scalatra
|
||||||
@ -210,7 +210,7 @@ java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distributi
|
|||||||
### java jax-rs
|
### java jax-rs
|
||||||
|
|
||||||
```
|
```
|
||||||
java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.0-M1.jar \
|
java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.2-M1.jar \
|
||||||
-i http://petstore.swagger.io/v2/swagger.json \
|
-i http://petstore.swagger.io/v2/swagger.json \
|
||||||
-l jaxrs \
|
-l jaxrs \
|
||||||
-o samples/server/petstore/jaxrs
|
-o samples/server/petstore/jaxrs
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
val version = scala.util.Properties.scalaPropOrElse("version.number", "unknown").toString match {
|
|
||||||
case s if s startsWith "2.10" => "2.10"
|
|
||||||
case s if s startsWith "2.11" => "2.11"
|
|
||||||
case e: String => e
|
|
||||||
}
|
|
||||||
println(version)
|
|
36
bin/scala-async-petstore.sh
Executable file
36
bin/scala-async-petstore.sh
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
#!/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
|
||||||
|
|
||||||
|
root=./modules/swagger-codegen-distribution/pom.xml
|
||||||
|
|
||||||
|
# gets version of swagger-codegen
|
||||||
|
version=$(sed '/<project>/,/<\/project>/d;/<version>/!d;s/ *<\/\?version> *//g' $root | sed -n '2p' | sed -e 's,.*<version>\([^<]*\)</version>.*,\1,g')
|
||||||
|
|
||||||
|
executable="./modules/swagger-codegen-distribution/target/swagger-codegen-distribution-$version.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="$@ -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l async-scala -o samples/client/petstore/async-scala"
|
||||||
|
|
||||||
|
java $JAVA_OPTS -jar $executable $ags
|
@ -2,7 +2,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.wordnik</groupId>
|
<groupId>com.wordnik</groupId>
|
||||||
<artifactId>swagger-codegen-project</artifactId>
|
<artifactId>swagger-codegen-project</artifactId>
|
||||||
<version>2.1.1-M1-SNAPSHOT</version>
|
<version>2.1.2-M1</version>
|
||||||
<relativePath>../..</relativePath>
|
<relativePath>../..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@ -10,7 +10,7 @@
|
|||||||
<artifactId>swagger-codegen-distribution</artifactId>
|
<artifactId>swagger-codegen-distribution</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>swagger-codegen (executable)</name>
|
<name>swagger-codegen (executable)</name>
|
||||||
<version>2.1.1-M1-SNAPSHOT</version>
|
<version>2.1.2-M1</version>
|
||||||
<build>
|
<build>
|
||||||
<testSourceDirectory>src/test/scala</testSourceDirectory>
|
<testSourceDirectory>src/test/scala</testSourceDirectory>
|
||||||
<outputDirectory>target/classes</outputDirectory>
|
<outputDirectory>target/classes</outputDirectory>
|
||||||
@ -19,6 +19,17 @@
|
|||||||
<directory>target</directory>
|
<directory>target</directory>
|
||||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>com.wordnik.swagger.codegen.Codegen</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
@ -41,14 +52,21 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<configuration>
|
<version>2.3</version>
|
||||||
<archive>
|
<executions>
|
||||||
<manifest>
|
<execution>
|
||||||
<mainClass>com.wordnik.swagger.codegen.Codegen</mainClass>
|
<phase>package</phase>
|
||||||
</manifest>
|
<goals>
|
||||||
</archive>
|
<goal>shade</goal>
|
||||||
</configuration>
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<transformers>
|
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
|
||||||
|
</transformers>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||||
|
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
<logger name="com.wordnik" level="debug"/>
|
||||||
|
<root level="error">
|
||||||
|
<appender-ref ref="STDOUT" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
@ -2,7 +2,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.wordnik</groupId>
|
<groupId>com.wordnik</groupId>
|
||||||
<artifactId>swagger-codegen-project</artifactId>
|
<artifactId>swagger-codegen-project</artifactId>
|
||||||
<version>2.1.1-M1-SNAPSHOT</version>
|
<version>2.1.2-M1</version>
|
||||||
<relativePath>../..</relativePath>
|
<relativePath>../..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@ -10,7 +10,7 @@
|
|||||||
<artifactId>swagger-codegen</artifactId>
|
<artifactId>swagger-codegen</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>swagger-codegen (core library)</name>
|
<name>swagger-codegen (core library)</name>
|
||||||
<version>2.1.1-M1-SNAPSHOT</version>
|
<version>2.1.2-M1</version>
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src/main/java</sourceDirectory>
|
<sourceDirectory>src/main/java</sourceDirectory>
|
||||||
<defaultGoal>install</defaultGoal>
|
<defaultGoal>install</defaultGoal>
|
||||||
|
@ -44,7 +44,7 @@ public class Codegen extends DefaultGenerator {
|
|||||||
options.addOption("i", "input-spec", true, "location of the swagger spec, as URL or file");
|
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("t", "template-dir", true, "folder containing the template files");
|
||||||
options.addOption("d", "debug-info", false, "prints additional info for debugging");
|
options.addOption("d", "debug-info", false, "prints additional info for debugging");
|
||||||
options.addOption("a", "auth", false, "addes authorization headers when fetching the swagger definitions remotely. Pass in a URL-encoded string of name:header with a comma separating multiple values");
|
options.addOption("a", "auth", true, "adds authorization headers when fetching the swagger definitions remotely. Pass in a URL-encoded string of name:header with a comma separating multiple values");
|
||||||
|
|
||||||
ClientOptInput clientOptInput = new ClientOptInput();
|
ClientOptInput clientOptInput = new ClientOptInput();
|
||||||
ClientOpts clientOpts = new ClientOpts();
|
ClientOpts clientOpts = new ClientOpts();
|
||||||
@ -84,7 +84,7 @@ public class Codegen extends DefaultGenerator {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (cmd.hasOption("i"))
|
if (cmd.hasOption("i"))
|
||||||
swagger = new SwaggerParser().read(cmd.getOptionValue("i"), clientOptInput.getAuthorizationValues());
|
swagger = new SwaggerParser().read(cmd.getOptionValue("i"), clientOptInput.getAuthorizationValues(), true);
|
||||||
if (cmd.hasOption("t"))
|
if (cmd.hasOption("t"))
|
||||||
clientOpts.getProperties().put("templateDir", String.valueOf(cmd.getOptionValue("t")));
|
clientOpts.getProperties().put("templateDir", String.valueOf(cmd.getOptionValue("t")));
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ public interface CodegenConfig {
|
|||||||
String modelFileFolder();
|
String modelFileFolder();
|
||||||
String modelPackage();
|
String modelPackage();
|
||||||
String toApiName(String name);
|
String toApiName(String name);
|
||||||
|
String toApiVarName(String name);
|
||||||
String toModelName(String name);
|
String toModelName(String name);
|
||||||
String toParamName(String name);
|
String toParamName(String name);
|
||||||
String escapeReservedWord(String name);
|
String escapeReservedWord(String name);
|
||||||
|
@ -11,6 +11,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class DefaultCodegen {
|
public class DefaultCodegen {
|
||||||
Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
|
Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
|
||||||
@ -101,11 +102,11 @@ public class DefaultCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String apiFileFolder() {
|
public String apiFileFolder() {
|
||||||
return outputFolder + "/" + apiPackage().replaceAll("\\.", "/");
|
return outputFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modelFileFolder() {
|
public String modelFileFolder() {
|
||||||
return outputFolder + "/" + modelPackage().replaceAll("\\.", "/");
|
return outputFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> additionalProperties() {
|
public Map<String, Object> additionalProperties() {
|
||||||
@ -133,6 +134,10 @@ public class DefaultCodegen {
|
|||||||
return initialCaps(name) + "Api";
|
return initialCaps(name) + "Api";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toApiVarName(String name) {
|
||||||
|
return snakeCase(name);
|
||||||
|
}
|
||||||
|
|
||||||
public String toModelFilename(String name) {
|
public String toModelFilename(String name) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -306,6 +311,10 @@ public class DefaultCodegen {
|
|||||||
return datatype;
|
return datatype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String snakeCase(String name) {
|
||||||
|
return Character.toLowerCase(name.charAt(0)) + name.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
public String initialCaps(String name) {
|
public String initialCaps(String name) {
|
||||||
return Character.toUpperCase(name.charAt(0)) + name.substring(1);
|
return Character.toUpperCase(name.charAt(0)) + name.substring(1);
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,7 @@ public class DefaultGenerator implements Generator {
|
|||||||
operation.put("modelPackage", config.modelPackage());
|
operation.put("modelPackage", config.modelPackage());
|
||||||
operation.putAll(config.additionalProperties());
|
operation.putAll(config.additionalProperties());
|
||||||
operation.put("classname", config.toApiName(tag));
|
operation.put("classname", config.toApiName(tag));
|
||||||
|
operation.put("classVarName", config.toApiVarName(tag));
|
||||||
allOperations.add(operation);
|
allOperations.add(operation);
|
||||||
for(String templateName : config.apiTemplateFiles().keySet()) {
|
for(String templateName : config.apiTemplateFiles().keySet()) {
|
||||||
String suffix = config.apiTemplateFiles().get(templateName);
|
String suffix = config.apiTemplateFiles().get(templateName);
|
||||||
@ -153,7 +154,7 @@ public class DefaultGenerator implements Generator {
|
|||||||
}
|
}
|
||||||
bundle.put("apiInfo", apis);
|
bundle.put("apiInfo", apis);
|
||||||
bundle.put("models", allModels);
|
bundle.put("models", allModels);
|
||||||
bundle.put("apiFolder", config.apiPackage().replaceAll("\\.", "/"));
|
bundle.put("apiFolder", config.apiPackage().replace('.', File.separatorChar));
|
||||||
bundle.put("modelPackage", config.modelPackage());
|
bundle.put("modelPackage", config.modelPackage());
|
||||||
if (swagger.getExternalDocs() != null) {
|
if (swagger.getExternalDocs() != null) {
|
||||||
bundle.put("externalDocs", swagger.getExternalDocs());
|
bundle.put("externalDocs", swagger.getExternalDocs());
|
||||||
|
@ -71,11 +71,11 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiFileFolder() {
|
public String apiFileFolder() {
|
||||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replaceAll("\\.", "/");
|
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modelFileFolder() {
|
public String modelFileFolder() {
|
||||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replaceAll("\\.", "/");
|
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,194 @@
|
|||||||
|
package com.wordnik.swagger.codegen.languages;
|
||||||
|
|
||||||
|
import com.wordnik.swagger.codegen.*;
|
||||||
|
import com.wordnik.swagger.models.properties.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class AsyncScalaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
|
protected String invokerPackage = "io.swagger.client";
|
||||||
|
protected String groupId = "com.wordnik";
|
||||||
|
protected String artifactId = "swagger-client";
|
||||||
|
protected String artifactVersion = "1.0.0";
|
||||||
|
protected String sourceFolder = "src/main/scala";
|
||||||
|
protected String clientName = "SwaggerClient";
|
||||||
|
protected String authScheme = "";
|
||||||
|
protected boolean authPreemptive = false;
|
||||||
|
protected boolean asyncHttpClient = !authScheme.isEmpty();
|
||||||
|
|
||||||
|
public CodegenType getTag() {
|
||||||
|
return CodegenType.CLIENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return "async-scala";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHelp() {
|
||||||
|
return "Generates an Asynchronous Scala client library.";
|
||||||
|
}
|
||||||
|
|
||||||
|
public AsyncScalaClientCodegen() {
|
||||||
|
super();
|
||||||
|
outputFolder = "generated-code/async-scala";
|
||||||
|
modelTemplateFiles.put("model.mustache", ".scala");
|
||||||
|
apiTemplateFiles.put("api.mustache", ".scala");
|
||||||
|
templateDir = "asyncscala";
|
||||||
|
apiPackage = "io.swagger.client.api";
|
||||||
|
modelPackage = "io.swagger.client.model";
|
||||||
|
|
||||||
|
reservedWords = new HashSet<String> (
|
||||||
|
Arrays.asList(
|
||||||
|
"abstract", "case", "catch", "class", "def", "do", "else", "extends",
|
||||||
|
"false", "final", "finally", "for", "forSome", "if", "implicit",
|
||||||
|
"import", "lazy", "match", "new", "null", "object", "override", "package",
|
||||||
|
"private", "protected", "return", "sealed", "super", "this", "throw",
|
||||||
|
"trait", "try", "true", "type", "val", "var", "while", "with", "yield")
|
||||||
|
);
|
||||||
|
|
||||||
|
additionalProperties.put("invokerPackage", invokerPackage);
|
||||||
|
additionalProperties.put("groupId", groupId);
|
||||||
|
additionalProperties.put("artifactId", artifactId);
|
||||||
|
additionalProperties.put("artifactVersion", artifactVersion);
|
||||||
|
additionalProperties.put("asyncHttpClient", asyncHttpClient);
|
||||||
|
additionalProperties.put("authScheme", authScheme);
|
||||||
|
additionalProperties.put("authPreemptive", authPreemptive);
|
||||||
|
additionalProperties.put("clientName", clientName);
|
||||||
|
|
||||||
|
supportingFiles.add(new SupportingFile("sbt.mustache", "", "build.sbt"));
|
||||||
|
supportingFiles.add(new SupportingFile("client.mustache",
|
||||||
|
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), clientName + ".scala"));
|
||||||
|
|
||||||
|
importMapping.remove("List");
|
||||||
|
importMapping.remove("Set");
|
||||||
|
importMapping.remove("Map");
|
||||||
|
|
||||||
|
importMapping.put("DateTime", "org.joda.time.DateTime");
|
||||||
|
importMapping.put("ListBuffer", "scala.collections.mutable.ListBuffer");
|
||||||
|
|
||||||
|
typeMapping = new HashMap<String, String>();
|
||||||
|
typeMapping.put("enum", "NSString");
|
||||||
|
typeMapping.put("array", "List");
|
||||||
|
typeMapping.put("set", "Set");
|
||||||
|
typeMapping.put("boolean", "Boolean");
|
||||||
|
typeMapping.put("string", "String");
|
||||||
|
typeMapping.put("int", "Int");
|
||||||
|
typeMapping.put("long", "Long");
|
||||||
|
typeMapping.put("float", "Float");
|
||||||
|
typeMapping.put("byte", "Byte");
|
||||||
|
typeMapping.put("short", "Short");
|
||||||
|
typeMapping.put("char", "Char");
|
||||||
|
typeMapping.put("long", "Long");
|
||||||
|
typeMapping.put("double", "Double");
|
||||||
|
typeMapping.put("object", "Any");
|
||||||
|
typeMapping.put("file", "File");
|
||||||
|
|
||||||
|
languageSpecificPrimitives = new HashSet<String>(
|
||||||
|
Arrays.asList(
|
||||||
|
"String",
|
||||||
|
"boolean",
|
||||||
|
"Boolean",
|
||||||
|
"Double",
|
||||||
|
"Int",
|
||||||
|
"Long",
|
||||||
|
"Float",
|
||||||
|
"Object",
|
||||||
|
"List",
|
||||||
|
"Map")
|
||||||
|
);
|
||||||
|
instantiationTypes.put("array", "ListBuffer");
|
||||||
|
instantiationTypes.put("map", "HashMap");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String escapeReservedWord(String name) {
|
||||||
|
return "_" + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apiFileFolder() {
|
||||||
|
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String modelFileFolder() {
|
||||||
|
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTypeDeclaration(Property p) {
|
||||||
|
if(p instanceof ArrayProperty) {
|
||||||
|
ArrayProperty ap = (ArrayProperty) p;
|
||||||
|
Property inner = ap.getItems();
|
||||||
|
return getSwaggerType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
|
}
|
||||||
|
else if (p instanceof MapProperty) {
|
||||||
|
MapProperty mp = (MapProperty) p;
|
||||||
|
Property inner = mp.getAdditionalProperties();
|
||||||
|
|
||||||
|
return getSwaggerType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||||
|
}
|
||||||
|
return super.getTypeDeclaration(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSwaggerType(Property p) {
|
||||||
|
String swaggerType = super.getSwaggerType(p);
|
||||||
|
String type = null;
|
||||||
|
if(typeMapping.containsKey(swaggerType)) {
|
||||||
|
type = typeMapping.get(swaggerType);
|
||||||
|
if(languageSpecificPrimitives.contains(type))
|
||||||
|
return toModelName(type);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
type = swaggerType;
|
||||||
|
return toModelName(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toInstantiationType(Property p) {
|
||||||
|
if (p instanceof MapProperty) {
|
||||||
|
MapProperty ap = (MapProperty) p;
|
||||||
|
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||||
|
return instantiationTypes.get("map") + "[String, " + inner + "]";
|
||||||
|
}
|
||||||
|
else if (p instanceof ArrayProperty) {
|
||||||
|
ArrayProperty ap = (ArrayProperty) p;
|
||||||
|
String inner = getSwaggerType(ap.getItems());
|
||||||
|
return instantiationTypes.get("array") + "[" + inner + "]";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toDefaultValue(Property p) {
|
||||||
|
if(p instanceof StringProperty)
|
||||||
|
return "null";
|
||||||
|
else if (p instanceof BooleanProperty)
|
||||||
|
return "null";
|
||||||
|
else if(p instanceof DateProperty)
|
||||||
|
return "null";
|
||||||
|
else if(p instanceof DateTimeProperty)
|
||||||
|
return "null";
|
||||||
|
else if (p instanceof DoubleProperty)
|
||||||
|
return "null";
|
||||||
|
else if (p instanceof FloatProperty)
|
||||||
|
return "null";
|
||||||
|
else if (p instanceof IntegerProperty)
|
||||||
|
return "null";
|
||||||
|
else if (p instanceof LongProperty)
|
||||||
|
return "null";
|
||||||
|
else if (p instanceof MapProperty) {
|
||||||
|
MapProperty ap = (MapProperty) p;
|
||||||
|
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||||
|
return "new HashMap[String, " + inner + "]() ";
|
||||||
|
}
|
||||||
|
else if (p instanceof ArrayProperty) {
|
||||||
|
ArrayProperty ap = (ArrayProperty) p;
|
||||||
|
String inner = getSwaggerType(ap.getItems());
|
||||||
|
return "new ListBuffer[" + inner + "]() ";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
|
}
|
@ -80,11 +80,11 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiFileFolder() {
|
public String apiFileFolder() {
|
||||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replaceAll("\\.", "/");
|
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modelFileFolder() {
|
public String modelFileFolder() {
|
||||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replaceAll("\\.", "/");
|
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -89,11 +89,11 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiFileFolder() {
|
public String apiFileFolder() {
|
||||||
return outputFolder + File.separator + apiPackage().replaceAll("\\.", File.separator);
|
return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modelFileFolder() {
|
public String modelFileFolder() {
|
||||||
return outputFolder + File.separator + modelPackage().replaceAll("\\.", File.separator);
|
return outputFolder + File.separator + modelPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,11 +69,11 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiFileFolder() {
|
public String apiFileFolder() {
|
||||||
return outputFolder + "/" + apiPackage().replaceAll("\\.", "/");
|
return outputFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modelFileFolder() {
|
public String modelFileFolder() {
|
||||||
return outputFolder + "/" + modelPackage().replaceAll("\\.", "/");
|
return outputFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,7 +54,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||||
supportingFiles.add(new SupportingFile("swagger.mustache", module, "swagger.py"));
|
supportingFiles.add(new SupportingFile("swagger.mustache", module, "swagger.py"));
|
||||||
supportingFiles.add(new SupportingFile("__init__.mustache", module, "__init__.py"));
|
supportingFiles.add(new SupportingFile("__init__.mustache", module, "__init__.py"));
|
||||||
supportingFiles.add(new SupportingFile("__init__.mustache", modelPackage.replaceAll("\\.", File.separator), "__init__.py"));
|
supportingFiles.add(new SupportingFile("__init__.mustache", modelPackage.replace('.', File.separatorChar), "__init__.py"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -64,11 +64,11 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiFileFolder() {
|
public String apiFileFolder() {
|
||||||
return outputFolder + "/" + apiPackage().replaceAll("\\.", "/");
|
return outputFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modelFileFolder() {
|
public String modelFileFolder() {
|
||||||
return outputFolder + "/" + modelPackage().replaceAll("\\.", "/");
|
return outputFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -106,11 +106,11 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiFileFolder() {
|
public String apiFileFolder() {
|
||||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replaceAll("\\.", "/");
|
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modelFileFolder() {
|
public String modelFileFolder() {
|
||||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replaceAll("\\.", "/");
|
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -128,11 +128,11 @@ public class ScalatraServerCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiFileFolder() {
|
public String apiFileFolder() {
|
||||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replaceAll("\\.", "/");
|
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String modelFileFolder() {
|
public String modelFileFolder() {
|
||||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replaceAll("\\.", "/");
|
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,8 +51,11 @@ public class ApiInvoker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
||||||
|
if(null != containerType) {
|
||||||
|
containerType = containerType.toLowerCase();
|
||||||
|
}
|
||||||
try{
|
try{
|
||||||
if("List".equals(containerType)) {
|
if("list".equals(containerType) || "array".equals(containerType)) {
|
||||||
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
|
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
|
||||||
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
|
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
|
||||||
return response;
|
return response;
|
||||||
@ -103,12 +106,12 @@ public class ApiInvoker {
|
|||||||
|
|
||||||
Builder builder = client.resource(host + path + querystring).accept("application/json");
|
Builder builder = client.resource(host + path + querystring).accept("application/json");
|
||||||
for(String key : headerParams.keySet()) {
|
for(String key : headerParams.keySet()) {
|
||||||
builder.header(key, headerParams.get(key));
|
builder = builder.header(key, headerParams.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(String key : defaultHeaderMap.keySet()) {
|
for(String key : defaultHeaderMap.keySet()) {
|
||||||
if(!headerParams.containsKey(key)) {
|
if(!headerParams.containsKey(key)) {
|
||||||
builder.header(key, defaultHeaderMap.get(key));
|
builder = builder.header(key, defaultHeaderMap.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ClientResponse response = null;
|
ClientResponse response = null;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
com.wordnik.swagger.codegen.languages.AndroidClientCodegen
|
com.wordnik.swagger.codegen.languages.AndroidClientCodegen
|
||||||
|
com.wordnik.swagger.codegen.languages.AsyncScalaClientCodegen
|
||||||
com.wordnik.swagger.codegen.languages.JavaClientCodegen
|
com.wordnik.swagger.codegen.languages.JavaClientCodegen
|
||||||
com.wordnik.swagger.codegen.languages.JaxRSServerCodegen
|
com.wordnik.swagger.codegen.languages.JaxRSServerCodegen
|
||||||
com.wordnik.swagger.codegen.languages.NodeJSServerCodegen
|
com.wordnik.swagger.codegen.languages.NodeJSServerCodegen
|
||||||
@ -10,4 +11,4 @@ com.wordnik.swagger.codegen.languages.StaticHtmlGenerator
|
|||||||
com.wordnik.swagger.codegen.languages.SwaggerGenerator
|
com.wordnik.swagger.codegen.languages.SwaggerGenerator
|
||||||
com.wordnik.swagger.codegen.languages.TizenClientCodegen
|
com.wordnik.swagger.codegen.languages.TizenClientCodegen
|
||||||
com.wordnik.swagger.codegen.languages.PhpClientCodegen
|
com.wordnik.swagger.codegen.languages.PhpClientCodegen
|
||||||
com.wordnik.swagger.codegen.languages.PythonClientCodegen
|
com.wordnik.swagger.codegen.languages.PythonClientCodegen
|
||||||
|
@ -8,46 +8,31 @@ import scala.concurrent.duration._
|
|||||||
import collection.mutable
|
import collection.mutable
|
||||||
|
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
class {{className}}(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
|
class {{classname}}(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
|
||||||
|
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
|
def {{nickname}}({{#allParams}}{{#optional}}{{paramName}}: Option[{{dataType}}] = {{#defaultValue}}Some({{defaultValue}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{#hasMore}},
|
||||||
def {{nickname}}({{#allParams}}
|
{{/hasMore}}
|
||||||
{{#optional}}
|
{{/optional}}{{^optional}}{{paramName}}: {{dataType}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#hasMore}},
|
||||||
{{paramName}}: Option[{{dataType}}] = {{#defaultValue}}Some({{defaultValue}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{#hasMore}}, {{/hasMore}}
|
{{/hasMore}}{{/optional}}{{/allParams}})(implicit reader: ClientResponseReader[{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}]{{#bodyParams}}, writer: RequestWriter[{{dataType}}]{{/bodyParams}}){{#returnType}}: Future[{{returnType}}]{{/returnType}}{{^returnType}}: Future[Unit]{{/returnType}} = {
|
||||||
{{/optional}}
|
|
||||||
{{^optional}}
|
|
||||||
{{paramName}}: {{dataType}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#hasMore}}, {{/hasMore}}
|
|
||||||
{{/optional}}{{/allParams}})(implicit reader: ClientResponseReader[{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}]{{#bodyParams}}, writer: RequestWriter[{{dataType}}]{{/bodyParams}}){{#returnType}}: Future[{{returnType}}]{{/returnType}}{{^returnType}}: Future[Unit]{{/returnType}} = {
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
val path =
|
val path = (addFmt("{{path}}"){{#pathParams}}
|
||||||
(addFmt("{{path}}"){{#pathParams}}
|
replaceAll ("\\{" + "{{baseName}}" + "\\}",{{paramName}}.toString){{/pathParams}})
|
||||||
replaceAll ("\\{" + "{{baseName}}" + "\\}",{{paramName}}.toString)
|
|
||||||
{{/pathParams}})
|
|
||||||
|
|
||||||
// query params
|
// query params
|
||||||
val queryParams = new mutable.HashMap[String, String]
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
val headerParams = new mutable.HashMap[String, String]
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
{{#requiredParamCount}}
|
{{#requiredParamCount}}// verify required params are set
|
||||||
// verify required params are set
|
|
||||||
val paramCount = (Set[Any]({{/requiredParamCount}}{{#requiredParams}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) - null).size
|
val paramCount = (Set[Any]({{/requiredParamCount}}{{#requiredParams}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) - null).size
|
||||||
if (paramCount != {{requiredParamCount}}) sys.error("missing required params")
|
if (paramCount != {{requiredParamCount}}) sys.error("missing required params"){{/requiredParamCount}}
|
||||||
{{/requiredParamCount}}
|
|
||||||
|
|
||||||
{{#queryParams}}
|
{{#queryParams}}{{#optional}}if({{paramName}} != null) {{paramName}}.foreach { v => queryParams += "{{baseName}}" -> v.toString }{{/optional}}{{^optional}}
|
||||||
{{#optional}}
|
if({{paramName}} != null) queryParams += "{{baseName}}" -> {{paramName}}.toString{{/optional}}{{/queryParams}}
|
||||||
if({{paramName}} != null) {{paramName}}.foreach { v => queryParams += "{{baseName}}" -> v.toString }
|
|
||||||
{{/optional}}
|
|
||||||
{{^optional}}
|
|
||||||
if({{paramName}} != null) queryParams += "{{baseName}}" -> {{paramName}}.toString
|
|
||||||
{{/optional}}
|
|
||||||
{{/queryParams}}
|
|
||||||
|
|
||||||
{{#headerParams}}headerParams += "{{baseName}}" -> {{paramName}}.toString
|
{{#headerParams}}headerParams += "{{baseName}}" -> {{paramName}}.toString{{/headerParams}}
|
||||||
{{/headerParams}}
|
|
||||||
|
|
||||||
val resFuture = client.submit("{{httpMethod}}", path, queryParams.toMap, headerParams.toMap, {{#bodyParam}}writer.write({{bodyParam}}){{/bodyParam}}{{^bodyParam}}"{{emptyBodyParam}}"{{/bodyParam}})
|
val resFuture = client.submit("{{httpMethod}}", path, queryParams.toMap, headerParams.toMap, {{#bodyParam}}writer.write({{paramName}}){{/bodyParam}}{{^bodyParam}}"{{emptyBodyParam}}"{{/bodyParam}})
|
||||||
resFuture flatMap { resp =>
|
resFuture flatMap { resp =>
|
||||||
process(reader.read(resp))
|
process(reader.read(resp))
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package {{package}}
|
package {{invokerPackage}}
|
||||||
|
|
||||||
{{#imports}}import {{import}}
|
{{#imports}}import {{import}}
|
||||||
{{/imports}}
|
{{/imports}}
|
||||||
|
import {{apiPackage}}._
|
||||||
|
|
||||||
import com.wordnik.swagger.client._
|
import com.wordnik.swagger.client._
|
||||||
import apis._
|
|
||||||
import java.io.Closeable
|
import java.io.Closeable
|
||||||
|
|
||||||
class {{clientName}}(config: SwaggerConfig) extends Closeable {
|
class {{clientName}}(config: SwaggerConfig) extends Closeable {
|
||||||
@ -13,12 +15,9 @@ class {{clientName}}(config: SwaggerConfig) extends Closeable {
|
|||||||
private[this] val client = transportClient
|
private[this] val client = transportClient
|
||||||
|
|
||||||
protected def transportClient: TransportClient = new RestClient(config)
|
protected def transportClient: TransportClient = new RestClient(config)
|
||||||
|
{{#apiInfo}}{{#apis}}
|
||||||
{{#apiInfo}}
|
val {{classVarName}} = new {{classname}}(client, config)
|
||||||
{{#apis}}
|
{{/apis}}{{/apiInfo}}
|
||||||
val {{name}} = new {{className}}(client, config)
|
|
||||||
{{/apis}}
|
|
||||||
{{/apiInfo}}
|
|
||||||
|
|
||||||
def close() {
|
def close() {
|
||||||
client.close()
|
client.close()
|
||||||
|
@ -6,9 +6,7 @@ import org.joda.time.DateTime
|
|||||||
|
|
||||||
{{#model}}
|
{{#model}}
|
||||||
case class {{classname}} (
|
case class {{classname}} (
|
||||||
{{#vars}}
|
{{#vars}}{{name}}: {{#isNotRequired}}Option[{{/isNotRequired}}{{datatype}}{{#isNotRequired}}]{{/isNotRequired}}{{#hasMore}},{{/hasMore}}{{#description}} // {{description}}{{/description}}
|
||||||
|
|
||||||
{{name}}: {{#isNotRequired}}Option[{{/isNotRequired}}{{datatype}}{{#isNotRequired}}]{{/isNotRequired}} {{#hasMore}},{{/hasMore}}{{#description}} // {{description}}{{/description}}{{newline}}
|
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
)
|
)
|
||||||
{{/model}}
|
{{/model}}
|
||||||
|
@ -2,7 +2,7 @@ organization := "{{package}}"
|
|||||||
|
|
||||||
name := "{{projectName}}-client"
|
name := "{{projectName}}-client"
|
||||||
|
|
||||||
libraryDependencies += "com.wordnik.swagger" %% "swagger-async-httpclient" % "0.3.0-WN5"
|
libraryDependencies += "com.wordnik.swagger" %% "swagger-async-httpclient" % "0.3.5"
|
||||||
|
|
||||||
libraryDependencies += "joda-time" % "joda-time" % "2.3"
|
libraryDependencies += "joda-time" % "joda-time" % "2.3"
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ class ApiClient:
|
|||||||
subValues.append(self.deserialize(subValue, subClass))
|
subValues.append(self.deserialize(subValue, subClass))
|
||||||
setattr(instance, attr, subValues)
|
setattr(instance, attr, subValues)
|
||||||
else:
|
else:
|
||||||
setattr(instance, attr, self.deserialize(value, objClass))
|
setattr(instance, attr, self.deserialize(value, attrType))
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"swagger": "2.0",
|
"swagger": "2.0",
|
||||||
"info": {
|
"info": {
|
||||||
"description": "This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.wordnik.com\">http://swagger.wordnik.com</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters",
|
"description": "This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"title": "Swagger Petstore",
|
"title": "Swagger Petstore",
|
||||||
"termsOfService": "http://helloreverb.com/terms/",
|
"termsOfService": "http://helloreverb.com/terms/",
|
||||||
@ -13,7 +13,7 @@
|
|||||||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"host": "petstore.swagger.wordnik.com",
|
"host": "petstore.swagger.io",
|
||||||
"basePath": "/v2",
|
"basePath": "/v2",
|
||||||
"schemes": [
|
"schemes": [
|
||||||
"http"
|
"http"
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.wordnik</groupId>
|
<groupId>com.wordnik</groupId>
|
||||||
<artifactId>swagger-codegen-project</artifactId>
|
<artifactId>swagger-codegen-project</artifactId>
|
||||||
<version>2.1.1-M1-SNAPSHOT</version>
|
<version>2.1.2-M1</version>
|
||||||
<relativePath>../..</relativePath>
|
<relativePath>../..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.wordnik</groupId>
|
<groupId>com.wordnik</groupId>
|
||||||
@ -200,10 +200,18 @@
|
|||||||
<artifactId>jetty-deploy</artifactId>
|
<artifactId>jetty-deploy</artifactId>
|
||||||
<version>${jetty-version}</version>
|
<version>${jetty-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.scalatest</groupId>
|
||||||
|
<artifactId>scalatest_2.11</artifactId>
|
||||||
|
<version>${scala-test-version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.scala-lang</groupId>
|
<groupId>org.scala-lang</groupId>
|
||||||
<artifactId>scala-library</artifactId>
|
<artifactId>scala-library</artifactId>
|
||||||
<version>${scala-version}</version>
|
<version>${scala-version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.scala-lang</groupId>
|
<groupId>org.scala-lang</groupId>
|
||||||
@ -228,6 +236,5 @@
|
|||||||
|
|
||||||
<scala-maven-plugin-version>3.1.5</scala-maven-plugin-version>
|
<scala-maven-plugin-version>3.1.5</scala-maven-plugin-version>
|
||||||
<scala-version>2.10.0</scala-version>
|
<scala-version>2.10.0</scala-version>
|
||||||
<scala-test-version>1.9</scala-test-version>
|
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
"url": "http://github.com/gruntjs/grunt/blob/master/LICENSE-MIT"
|
"url": "http://github.com/gruntjs/grunt/blob/master/LICENSE-MIT"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"host": "petstore.swagger.wordnik.com",
|
"host": "petstore.swagger.io",
|
||||||
"basePath": "/api",
|
"basePath": "/api",
|
||||||
"paths": {
|
"paths": {
|
||||||
"/pet": {
|
"/pet": {
|
||||||
|
@ -31,11 +31,13 @@ public class Bootstrap extends HttpServlet {
|
|||||||
bc.setBasePath("/api");
|
bc.setBasePath("/api");
|
||||||
bc.setTitle("Swagger Generator");
|
bc.setTitle("Swagger Generator");
|
||||||
bc.setDescription("This is an online swagger codegen server. You can find out more " +
|
bc.setDescription("This is an online swagger codegen server. You can find out more " +
|
||||||
"at <a href=\"https://github.com/wordnik/swagger-generator\">https://github.com/wordnik/swagger-generator</a> or on irc.freenode.net, #swagger." +
|
"at <a href=\"https://github.com/wordnik/swagger-generator\">https://github.com/swagger-api/swagger-codegen</a> or on irc.freenode.net, #swagger." +
|
||||||
"http://helloreverb.com/terms/");
|
"http://helloreverb.com/terms/");
|
||||||
bc.setTermsOfServiceUrl("http://helloreverb.com/terms/");
|
bc.setTermsOfServiceUrl("http://helloreverb.com/terms/");
|
||||||
bc.setContact("apiteam@swagger.io");
|
bc.setContact("apiteam@swagger.io");
|
||||||
bc.setLicense("Apache 2.0");
|
bc.setLicense("Apache 2.0");
|
||||||
|
bc.setVersion("1.0.0");
|
||||||
|
bc.setHost("generator.swagger.io");
|
||||||
bc.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html");
|
bc.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html");
|
||||||
bc.setResourcePackage("com.wordnik.swagger.generator.resource");
|
bc.setResourcePackage("com.wordnik.swagger.generator.resource");
|
||||||
bc.setScan(true);
|
bc.setScan(true);
|
||||||
|
@ -2,18 +2,25 @@ package com.wordnik.swagger.generator.model;
|
|||||||
|
|
||||||
public class ResponseCode {
|
public class ResponseCode {
|
||||||
private String code;
|
private String code;
|
||||||
|
private String link;
|
||||||
|
public ResponseCode() {}
|
||||||
|
|
||||||
|
public ResponseCode(String code, String link) {
|
||||||
|
setCode(code);
|
||||||
|
setLink(link);
|
||||||
|
}
|
||||||
|
|
||||||
public String getCode() {
|
public String getCode() {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCode(String code) {
|
public void setCode(String code) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResponseCode() {}
|
public String getLink() {
|
||||||
|
return link;
|
||||||
public ResponseCode(String code) {
|
}
|
||||||
setCode(code);
|
public void setLink(String link) {
|
||||||
|
this.link = link;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,20 +11,33 @@ import com.wordnik.swagger.generator.util.ZipUtil;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Generator {
|
public class Generator {
|
||||||
|
static Logger LOGGER = LoggerFactory.getLogger(Generator.class);
|
||||||
|
|
||||||
public static String generateClient(String language, GeneratorInput opts) throws ApiException {
|
public static String generateClient(String language, GeneratorInput opts) throws ApiException {
|
||||||
|
Swagger swagger;
|
||||||
|
LOGGER.debug("generate client for " + language);
|
||||||
if(opts == null) {
|
if(opts == null) {
|
||||||
throw new BadRequestException(400, "No options were supplied");
|
throw new BadRequestException(400, "No options were supplied");
|
||||||
}
|
}
|
||||||
JsonNode node = opts.getSpec();
|
JsonNode node = opts.getSpec();
|
||||||
if(node == null) {
|
if(node == null) {
|
||||||
throw new BadRequestException(400, "No swagger specification was supplied");
|
if(opts.getSwaggerUrl() != null) {
|
||||||
|
swagger = new SwaggerParser().read(opts.getSwaggerUrl());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new BadRequestException(400, "No swagger specification was supplied");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
swagger = new SwaggerParser().read(node);
|
||||||
}
|
}
|
||||||
Swagger swagger = new SwaggerParser().read(node);
|
|
||||||
if(swagger == null) {
|
if(swagger == null) {
|
||||||
throw new BadRequestException(400, "The swagger specification supplied was not valid");
|
throw new BadRequestException(400, "The swagger specification supplied was not valid");
|
||||||
}
|
}
|
||||||
@ -67,8 +80,66 @@ public class Generator {
|
|||||||
return outputFilename;
|
return outputFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String generateServer(String language, GeneratorInput opts) {
|
public static String generateServer(String language, GeneratorInput opts) throws ApiException {
|
||||||
return "";
|
LOGGER.debug("generate server for " + language);
|
||||||
|
Swagger swagger;
|
||||||
|
if(opts == null) {
|
||||||
|
throw new BadRequestException(400, "No options were supplied");
|
||||||
|
}
|
||||||
|
if(opts == null) {
|
||||||
|
throw new BadRequestException(400, "No options were supplied");
|
||||||
|
}
|
||||||
|
JsonNode node = opts.getSpec();
|
||||||
|
if(node == null) {
|
||||||
|
if(opts.getSwaggerUrl() != null) {
|
||||||
|
swagger = new SwaggerParser().read(opts.getSwaggerUrl());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new BadRequestException(400, "No swagger specification was supplied");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
swagger = new SwaggerParser().read(node);
|
||||||
|
}
|
||||||
|
if(swagger == null) {
|
||||||
|
throw new BadRequestException(400, "The swagger specification supplied was not valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientOptInput clientOptInput = new ClientOptInput();
|
||||||
|
ClientOpts clientOpts = new ClientOpts();
|
||||||
|
String outputFolder = getTmpFolder().getAbsolutePath() + File.separator + language + "-server";
|
||||||
|
String outputFilename = outputFolder + "-bundle.zip";
|
||||||
|
|
||||||
|
clientOptInput
|
||||||
|
.opts(clientOpts)
|
||||||
|
.swagger(swagger);
|
||||||
|
|
||||||
|
CodegenConfig codegenConfig = Codegen.getConfig(language);
|
||||||
|
if(codegenConfig == null) {
|
||||||
|
throw new BadRequestException(400, "Unsupported target " + language + " supplied");
|
||||||
|
}
|
||||||
|
|
||||||
|
codegenConfig.setOutputDir(outputFolder);
|
||||||
|
|
||||||
|
Json.prettyPrint(clientOpts);
|
||||||
|
|
||||||
|
clientOptInput.setConfig(codegenConfig);
|
||||||
|
|
||||||
|
try{
|
||||||
|
List<File> files = new Codegen().opts(clientOptInput).generate();
|
||||||
|
if(files.size() > 0) {
|
||||||
|
List<File> filesToAdd = new ArrayList<File>();
|
||||||
|
filesToAdd.add(new File(outputFolder));
|
||||||
|
ZipUtil zip = new ZipUtil();
|
||||||
|
zip.compressFiles(filesToAdd, outputFilename);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new BadRequestException(400, "A target generation was attempted, but no files were created!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new BadRequestException(500, "Unable to build target: " + e.getMessage());
|
||||||
|
}
|
||||||
|
return outputFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InputOption clientOptions(String language) {
|
public static InputOption clientOptions(String language) {
|
||||||
|
@ -18,10 +18,25 @@ import javax.ws.rs.core.*;
|
|||||||
public class SwaggerResource {
|
public class SwaggerResource {
|
||||||
private static Map<String, Generated> fileMap = new HashMap<String, Generated>();
|
private static Map<String, Generated> fileMap = new HashMap<String, Generated>();
|
||||||
|
|
||||||
|
static List<String> clients = new ArrayList<String>();
|
||||||
|
static List<String> servers = new ArrayList<String>();
|
||||||
|
static {
|
||||||
|
List<CodegenConfig> extensions = Codegen.getExtensions();
|
||||||
|
for(CodegenConfig config : extensions) {
|
||||||
|
if(config.getTag().equals(CodegenType.CLIENT) || config.getTag().equals(CodegenType.DOCUMENTATION)) {
|
||||||
|
clients.add(config.getName());
|
||||||
|
}
|
||||||
|
else if(config.getTag().equals(CodegenType.SERVER)) {
|
||||||
|
servers.add(config.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/download/{fileId}")
|
@Path("/download/{fileId}")
|
||||||
@Produces({"application/zip", "application/json"})
|
@Produces({"application/zip"})
|
||||||
@ApiOperation(value = "Downloads a pre-generated file", response = File.class)
|
@ApiOperation(value = "Downloads a pre-generated file",
|
||||||
|
response = String.class)
|
||||||
public Response downloadFile(@PathParam("fileId") String fileId) throws Exception {
|
public Response downloadFile(@PathParam("fileId") String fileId) throws Exception {
|
||||||
Generated g = fileMap.get(fileId);
|
Generated g = fileMap.get(fileId);
|
||||||
System.out.println("looking for fileId " + fileId);
|
System.out.println("looking for fileId " + fileId);
|
||||||
@ -43,7 +58,8 @@ public class SwaggerResource {
|
|||||||
@POST
|
@POST
|
||||||
@Path("/clients/{language}")
|
@Path("/clients/{language}")
|
||||||
@Produces({"application/zip", "application/json"})
|
@Produces({"application/zip", "application/json"})
|
||||||
@ApiOperation(value = "Generates a client library based on the config")
|
@ApiOperation(
|
||||||
|
value = "Generates a client library based on the config")
|
||||||
public Response generateClient(
|
public Response generateClient(
|
||||||
@ApiParam(value = "The target language for the client library", allowableValues = "android,java,php,objc,docs", required = true) @PathParam("language") String language,
|
@ApiParam(value = "The target language for the client library", allowableValues = "android,java,php,objc,docs", required = true) @PathParam("language") String language,
|
||||||
@ApiParam(value = "Configuration for building the client library", required = true) GeneratorInput opts) throws Exception {
|
@ApiParam(value = "Configuration for building the client library", required = true) GeneratorInput opts) throws Exception {
|
||||||
@ -57,7 +73,8 @@ public class SwaggerResource {
|
|||||||
g.setFriendlyName(language + "-client");
|
g.setFriendlyName(language + "-client");
|
||||||
fileMap.put(code, g);
|
fileMap.put(code, g);
|
||||||
System.out.println(code + ", " + filename);
|
System.out.println(code + ", " + filename);
|
||||||
return Response.ok().entity(new ResponseCode(code)).build();
|
String link = "http://generator.swagger.io/api/gen/download/" + code;
|
||||||
|
return Response.ok().entity(new ResponseCode(code, link)).build();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return Response.status(500).build();
|
return Response.status(500).build();
|
||||||
@ -70,46 +87,22 @@ public class SwaggerResource {
|
|||||||
response = String.class,
|
response = String.class,
|
||||||
responseContainer = "List")
|
responseContainer = "List")
|
||||||
public Response clientOptions() {
|
public Response clientOptions() {
|
||||||
String[] languages = {"android", "java", "php", "objc", "docs"};
|
String[] languages = new String[clients.size()];
|
||||||
|
languages = clients.toArray(languages);
|
||||||
return Response.ok().entity(languages).build();
|
return Response.ok().entity(languages).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/clients/{language}")
|
|
||||||
@ApiOperation(value = "Gets options for a client generation",
|
|
||||||
notes = "Values which are not required will use the provided default values",
|
|
||||||
response = InputOption.class,
|
|
||||||
responseContainer = "List")
|
|
||||||
@ApiResponses(value = {
|
|
||||||
@com.wordnik.swagger.annotations.ApiResponse(code = 400, message = "Invalid model supplied", response = ValidationMessage.class),
|
|
||||||
})
|
|
||||||
|
|
||||||
public Response clientLibraryOptions(
|
|
||||||
@ApiParam(value = "The target language for the client library", allowableValues = "android,java,php,objc,docs", required = true) @PathParam("language") String language) {
|
|
||||||
return Response.ok().entity(Generator.clientOptions(language)).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/servers")
|
@Path("/servers")
|
||||||
@ApiOperation(value = "Gets languages supported by the server generator",
|
@ApiOperation(value = "Gets languages supported by the server generator",
|
||||||
response = String.class,
|
response = String.class,
|
||||||
responseContainer = "List")
|
responseContainer = "List")
|
||||||
public Response serverOptions() {
|
public Response serverOptions() {
|
||||||
String[] languages = {"jaxrs","nodejs"};
|
String[] languages = new String[servers.size()];
|
||||||
|
languages = servers.toArray(languages);
|
||||||
return Response.ok().entity(languages).build();
|
return Response.ok().entity(languages).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
|
||||||
@Path("/servers/{language}")
|
|
||||||
@ApiOperation(value = "Gets options for a server generation",
|
|
||||||
notes = "Values which are not required will use the provided default values",
|
|
||||||
response = InputOption.class,
|
|
||||||
responseContainer = "List")
|
|
||||||
public Response serverFrameworkOptions(
|
|
||||||
@ApiParam(value = "The target framework for the client library", allowableValues = "jaxrs,nodejs", required = true) @PathParam("language") String framework) {
|
|
||||||
return Response.ok().entity(Generator.serverOptions(framework)).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/servers/{framework}")
|
@Path("/servers/{framework}")
|
||||||
@ApiOperation(value = "Generates a server library for the supplied server framework",
|
@ApiOperation(value = "Generates a server library for the supplied server framework",
|
||||||
@ -130,7 +123,8 @@ public class SwaggerResource {
|
|||||||
g.setFriendlyName(framework + "-server");
|
g.setFriendlyName(framework + "-server");
|
||||||
fileMap.put(code, g);
|
fileMap.put(code, g);
|
||||||
System.out.println(code + ", " + filename);
|
System.out.println(code + ", " + filename);
|
||||||
return Response.ok().entity(new ResponseCode(code)).build();
|
String link = "http://generator.swagger.io/api/gen/download/" + code;
|
||||||
|
return Response.ok().entity(new ResponseCode(code, link)).build();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return Response.status(500).build();
|
return Response.status(500).build();
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
import com.wordnik.swagger.online._
|
||||||
|
import com.wordnik.swagger.generator.model._
|
||||||
|
import com.wordnik.swagger.util.Json
|
||||||
|
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.scalatest.junit.JUnitRunner
|
||||||
|
import org.scalatest.FlatSpec
|
||||||
|
import org.scalatest.Matchers
|
||||||
|
|
||||||
|
import scala.collection.JavaConverters._
|
||||||
|
|
||||||
|
@RunWith(classOf[JUnitRunner])
|
||||||
|
class GeneratorInputTest extends FlatSpec with Matchers {
|
||||||
|
it should "write an object" in {
|
||||||
|
val obj = new GeneratorInput()
|
||||||
|
obj.setSwaggerUrl("http://petstore.swagger.io/v2/swagger.json")
|
||||||
|
Json.prettyPrint(obj)
|
||||||
|
}
|
||||||
|
}
|
6
pom.xml
6
pom.xml
@ -9,7 +9,7 @@
|
|||||||
<artifactId>swagger-codegen-project</artifactId>
|
<artifactId>swagger-codegen-project</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>swagger-codegen-project</name>
|
<name>swagger-codegen-project</name>
|
||||||
<version>2.1.1-M1-SNAPSHOT</version>
|
<version>2.1.2-M1</version>
|
||||||
<url>https://github.com/swagger-api/swagger-codegen</url>
|
<url>https://github.com/swagger-api/swagger-codegen</url>
|
||||||
<scm>
|
<scm>
|
||||||
<connection>scm:git:git@github.com:swagger-api/swagger-codegen.git</connection>
|
<connection>scm:git:git@github.com:swagger-api/swagger-codegen.git</connection>
|
||||||
@ -347,10 +347,10 @@
|
|||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
<properties>
|
<properties>
|
||||||
<swagger-parser-version>1.0.0</swagger-parser-version>
|
<swagger-parser-version>1.0.1</swagger-parser-version>
|
||||||
<scala-version>2.11.1</scala-version>
|
<scala-version>2.11.1</scala-version>
|
||||||
<felix-version>2.3.4</felix-version>
|
<felix-version>2.3.4</felix-version>
|
||||||
<swagger-core-version>1.5.1-M1</swagger-core-version>
|
<swagger-core-version>1.5.2-M1</swagger-core-version>
|
||||||
<scala-test-version>2.1.4</scala-test-version>
|
<scala-test-version>2.1.4</scala-test-version>
|
||||||
<commons-io-version>2.3</commons-io-version>
|
<commons-io-version>2.3</commons-io-version>
|
||||||
<commons-cli-version>1.2</commons-cli-version>
|
<commons-cli-version>1.2</commons-cli-version>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package io.swagger.client.model;
|
package io.swagger.client.model;
|
||||||
|
|
||||||
import io.swagger.client.model.Category;
|
import io.swagger.client.model.Category;
|
||||||
import java.util.*;
|
|
||||||
import io.swagger.client.model.Tag;
|
import io.swagger.client.model.Tag;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import com.wordnik.swagger.annotations.*;
|
import com.wordnik.swagger.annotations.*;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
11
samples/client/petstore/async-scala/build.sbt
Normal file
11
samples/client/petstore/async-scala/build.sbt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
organization := ""
|
||||||
|
|
||||||
|
name := "-client"
|
||||||
|
|
||||||
|
libraryDependencies += "com.wordnik.swagger" %% "swagger-async-httpclient" % "0.3.5"
|
||||||
|
|
||||||
|
libraryDependencies += "joda-time" % "joda-time" % "2.3"
|
||||||
|
|
||||||
|
libraryDependencies += "org.joda" % "joda-convert" % "1.3.1"
|
||||||
|
|
||||||
|
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.0.13" % "provided"
|
@ -0,0 +1,27 @@
|
|||||||
|
package io.swagger.client
|
||||||
|
|
||||||
|
import io.swagger.client.api._
|
||||||
|
|
||||||
|
import com.wordnik.swagger.client._
|
||||||
|
|
||||||
|
import java.io.Closeable
|
||||||
|
|
||||||
|
class SwaggerClient(config: SwaggerConfig) extends Closeable {
|
||||||
|
val locator = config.locator
|
||||||
|
val name = config.name
|
||||||
|
|
||||||
|
private[this] val client = transportClient
|
||||||
|
|
||||||
|
protected def transportClient: TransportClient = new RestClient(config)
|
||||||
|
|
||||||
|
val user = new UserApi(client, config)
|
||||||
|
|
||||||
|
val pet = new PetApi(client, config)
|
||||||
|
|
||||||
|
val store = new StoreApi(client, config)
|
||||||
|
|
||||||
|
|
||||||
|
def close() {
|
||||||
|
client.close()
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,193 @@
|
|||||||
|
package io.swagger.client.api
|
||||||
|
|
||||||
|
import io.swagger.client.model.Pet
|
||||||
|
import java.io.File
|
||||||
|
import com.wordnik.swagger.client._
|
||||||
|
import scala.concurrent.{ Future, Await }
|
||||||
|
import scala.concurrent.duration._
|
||||||
|
import collection.mutable
|
||||||
|
|
||||||
|
class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
|
||||||
|
|
||||||
|
|
||||||
|
def updatePet(body: Pet)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/pet"))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def addPet(body: Pet)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/pet"))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def findPetsByStatus(status: List[String])(implicit reader: ClientResponseReader[List[Pet]]): Future[List[Pet]] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/pet/findByStatus"))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(status != null) queryParams += "status" -> status.toString
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def findPetsByTags(tags: List[String])(implicit reader: ClientResponseReader[List[Pet]]): Future[List[Pet]] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/pet/findByTags"))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(tags != null) queryParams += "tags" -> tags.toString
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def getPetById(petId: Long)(implicit reader: ClientResponseReader[Pet]): Future[Pet] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/pet/{petId}")
|
||||||
|
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def updatePetWithForm(petId: String,
|
||||||
|
name: String,
|
||||||
|
status: String)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/pet/{petId}")
|
||||||
|
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, "")
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def deletePet(api_key: String,
|
||||||
|
petId: Long)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/pet/{petId}")
|
||||||
|
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
headerParams += "api_key" -> api_key.toString
|
||||||
|
|
||||||
|
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def uploadFile(petId: Long,
|
||||||
|
additionalMetadata: String,
|
||||||
|
file: File)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/pet/{petId}/uploadImage")
|
||||||
|
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, "")
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,99 @@
|
|||||||
|
package io.swagger.client.api
|
||||||
|
|
||||||
|
import io.swagger.client.model.Order
|
||||||
|
import com.wordnik.swagger.client._
|
||||||
|
import scala.concurrent.{ Future, Await }
|
||||||
|
import scala.concurrent.duration._
|
||||||
|
import collection.mutable
|
||||||
|
|
||||||
|
class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
|
||||||
|
|
||||||
|
|
||||||
|
def getInventory()(implicit reader: ClientResponseReader[Map[String, Integer]]): Future[Map[String, Integer]] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/store/inventory"))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def placeOrder(body: Order)(implicit reader: ClientResponseReader[Order], writer: RequestWriter[Order]): Future[Order] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/store/order"))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def getOrderById(orderId: String)(implicit reader: ClientResponseReader[Order]): Future[Order] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/store/order/{orderId}")
|
||||||
|
replaceAll ("\\{" + "orderId" + "\\}",orderId.toString))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def deleteOrder(orderId: String)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/store/order/{orderId}")
|
||||||
|
replaceAll ("\\{" + "orderId" + "\\}",orderId.toString))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,188 @@
|
|||||||
|
package io.swagger.client.api
|
||||||
|
|
||||||
|
import io.swagger.client.model.User
|
||||||
|
import com.wordnik.swagger.client._
|
||||||
|
import scala.concurrent.{ Future, Await }
|
||||||
|
import scala.concurrent.duration._
|
||||||
|
import collection.mutable
|
||||||
|
|
||||||
|
class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
|
||||||
|
|
||||||
|
|
||||||
|
def createUser(body: User)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/user"))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def createUsersWithArrayInput(body: List[User])(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/user/createWithArray"))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def createUsersWithListInput(body: List[User])(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/user/createWithList"))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def loginUser(username: String,
|
||||||
|
password: String)(implicit reader: ClientResponseReader[String]): Future[String] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/user/login"))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(username != null) queryParams += "username" -> username.toString
|
||||||
|
if(password != null) queryParams += "password" -> password.toString
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def logoutUser()(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/user/logout"))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def getUserByName(username: String)(implicit reader: ClientResponseReader[User]): Future[User] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/user/{username}")
|
||||||
|
replaceAll ("\\{" + "username" + "\\}",username.toString))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def updateUser(username: String,
|
||||||
|
body: User)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/user/{username}")
|
||||||
|
replaceAll ("\\{" + "username" + "\\}",username.toString))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def deleteUser(username: String)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
|
||||||
|
// create path and map variables
|
||||||
|
val path = (addFmt("/user/{username}")
|
||||||
|
replaceAll ("\\{" + "username" + "\\}",username.toString))
|
||||||
|
|
||||||
|
// query params
|
||||||
|
val queryParams = new mutable.HashMap[String, String]
|
||||||
|
val headerParams = new mutable.HashMap[String, String]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
|
||||||
|
resFuture flatMap { resp =>
|
||||||
|
process(reader.read(resp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package io.swagger.client.model
|
||||||
|
|
||||||
|
import org.joda.time.DateTime
|
||||||
|
|
||||||
|
|
||||||
|
case class Category (
|
||||||
|
id: Long,
|
||||||
|
name: String
|
||||||
|
|
||||||
|
)
|
@ -0,0 +1,14 @@
|
|||||||
|
package io.swagger.client.model
|
||||||
|
|
||||||
|
import org.joda.time.DateTime
|
||||||
|
|
||||||
|
|
||||||
|
case class Order (
|
||||||
|
id: Long,
|
||||||
|
petId: Long,
|
||||||
|
quantity: Integer,
|
||||||
|
shipDate: DateTime,
|
||||||
|
status: String, // Order Status
|
||||||
|
complete: Boolean
|
||||||
|
|
||||||
|
)
|
@ -0,0 +1,14 @@
|
|||||||
|
package io.swagger.client.model
|
||||||
|
|
||||||
|
import org.joda.time.DateTime
|
||||||
|
|
||||||
|
|
||||||
|
case class Pet (
|
||||||
|
id: Long,
|
||||||
|
category: Category,
|
||||||
|
name: String,
|
||||||
|
photoUrls: List[String],
|
||||||
|
tags: List[Tag],
|
||||||
|
status: String // pet status in the store
|
||||||
|
|
||||||
|
)
|
@ -0,0 +1,10 @@
|
|||||||
|
package io.swagger.client.model
|
||||||
|
|
||||||
|
import org.joda.time.DateTime
|
||||||
|
|
||||||
|
|
||||||
|
case class Tag (
|
||||||
|
id: Long,
|
||||||
|
name: String
|
||||||
|
|
||||||
|
)
|
@ -0,0 +1,16 @@
|
|||||||
|
package io.swagger.client.model
|
||||||
|
|
||||||
|
import org.joda.time.DateTime
|
||||||
|
|
||||||
|
|
||||||
|
case class User (
|
||||||
|
id: Long,
|
||||||
|
username: String,
|
||||||
|
firstName: String,
|
||||||
|
lastName: String,
|
||||||
|
email: String,
|
||||||
|
password: String,
|
||||||
|
phone: String,
|
||||||
|
userStatus: Integer // User Status
|
||||||
|
|
||||||
|
)
|
@ -51,8 +51,11 @@ public class ApiInvoker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
||||||
|
if(null != containerType) {
|
||||||
|
containerType = containerType.toLowerCase();
|
||||||
|
}
|
||||||
try{
|
try{
|
||||||
if("List".equals(containerType)) {
|
if("list".equals(containerType) || "array".equals(containerType)) {
|
||||||
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
|
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
|
||||||
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
|
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
|
||||||
return response;
|
return response;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package io.swagger.client.model;
|
package io.swagger.client.model;
|
||||||
|
|
||||||
import io.swagger.client.model.Category;
|
import io.swagger.client.model.Category;
|
||||||
import java.util.*;
|
|
||||||
import io.swagger.client.model.Tag;
|
import io.swagger.client.model.Tag;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import com.wordnik.swagger.annotations.*;
|
import com.wordnik.swagger.annotations.*;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "SWGObject.h"
|
#import "SWGObject.h"
|
||||||
#import "SWGCategory.h"
|
|
||||||
#import "SWGTag.h"
|
#import "SWGTag.h"
|
||||||
|
#import "SWGCategory.h"
|
||||||
|
|
||||||
|
|
||||||
@interface SWGPet : SWGObject
|
@interface SWGPet : SWGObject
|
||||||
|
@ -17,11 +17,11 @@
|
|||||||
using namespace Tizen::Web::Json;
|
using namespace Tizen::Web::Json;
|
||||||
|
|
||||||
|
|
||||||
using Tizen::Base::Integer;
|
|
||||||
using Tizen::Base::Long;
|
using Tizen::Base::Long;
|
||||||
|
using Tizen::Base::DateTime;
|
||||||
using Tizen::Base::String;
|
using Tizen::Base::String;
|
||||||
using Tizen::Base::Boolean;
|
using Tizen::Base::Boolean;
|
||||||
using Tizen::Base::DateTime;
|
using Tizen::Base::Integer;
|
||||||
|
|
||||||
|
|
||||||
namespace Swagger {
|
namespace Swagger {
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
using namespace Tizen::Web::Json;
|
using namespace Tizen::Web::Json;
|
||||||
|
|
||||||
|
|
||||||
|
#include "SamiCategory.h"
|
||||||
using Tizen::Base::Long;
|
using Tizen::Base::Long;
|
||||||
using Tizen::Base::String;
|
using Tizen::Base::String;
|
||||||
#include "SamiCategory.h"
|
|
||||||
#include "SamiTag.h"
|
#include "SamiTag.h"
|
||||||
using Tizen::Base::Collection::IList;
|
using Tizen::Base::Collection::IList;
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
using namespace Tizen::Web::Json;
|
using namespace Tizen::Web::Json;
|
||||||
|
|
||||||
|
|
||||||
using Tizen::Base::Integer;
|
|
||||||
using Tizen::Base::Long;
|
using Tizen::Base::Long;
|
||||||
using Tizen::Base::String;
|
using Tizen::Base::String;
|
||||||
|
using Tizen::Base::Integer;
|
||||||
|
|
||||||
|
|
||||||
namespace Swagger {
|
namespace Swagger {
|
||||||
|
Binary file not shown.
@ -58,25 +58,6 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="section-box">
|
|
||||||
<div class="section-header">
|
|
||||||
<a href="#!/StoreApi">StoreApi</a>
|
|
||||||
</div>
|
|
||||||
<ul>
|
|
||||||
|
|
||||||
|
|
||||||
<li><a href="#!/StoreApi#getInventory">getInventory</a></li>
|
|
||||||
|
|
||||||
<li><a href="#!/StoreApi#placeOrder">placeOrder</a></li>
|
|
||||||
|
|
||||||
<li><a href="#!/StoreApi#getOrderById">getOrderById</a></li>
|
|
||||||
|
|
||||||
<li><a href="#!/StoreApi#deleteOrder">deleteOrder</a></li>
|
|
||||||
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="section-box">
|
<div class="section-box">
|
||||||
<div class="section-header">
|
<div class="section-header">
|
||||||
<a href="#!/PetApi">PetApi</a>
|
<a href="#!/PetApi">PetApi</a>
|
||||||
@ -104,6 +85,25 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="section-box">
|
||||||
|
<div class="section-header">
|
||||||
|
<a href="#!/StoreApi">StoreApi</a>
|
||||||
|
</div>
|
||||||
|
<ul>
|
||||||
|
|
||||||
|
|
||||||
|
<li><a href="#!/StoreApi#getInventory">getInventory</a></li>
|
||||||
|
|
||||||
|
<li><a href="#!/StoreApi#placeOrder">placeOrder</a></li>
|
||||||
|
|
||||||
|
<li><a href="#!/StoreApi#getOrderById">getOrderById</a></li>
|
||||||
|
|
||||||
|
<li><a href="#!/StoreApi#deleteOrder">deleteOrder</a></li>
|
||||||
|
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="non-sidebar">
|
<div class="non-sidebar">
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package io.swagger.model;
|
package io.swagger.model;
|
||||||
|
|
||||||
import io.swagger.model.Category;
|
import io.swagger.model.Category;
|
||||||
import java.util.*;
|
|
||||||
import io.swagger.model.Tag;
|
import io.swagger.model.Tag;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import com.wordnik.swagger.annotations.*;
|
import com.wordnik.swagger.annotations.*;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user