mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 11:23:58 +00:00
Merge pull request #451 from swagger-api/develop_2.0
Merged from develop_2.0
This commit is contained in:
commit
4fd4c17036
@ -18,7 +18,7 @@ The Swagger Specification has undergone 3 revisions since initial creation in 20
|
||||
|
||||
Swagger Codegen Version | Release Date | Swagger Spec compatability | Notes
|
||||
----------------------- | ------------ | -------------------------- | -----
|
||||
2.1.1-M1 | 2015-02-17 | 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 | 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)
|
||||
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,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>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>swagger-codegen-project</artifactId>
|
||||
<version>2.1.1-M1</version>
|
||||
<version>2.1.2-M1</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -10,7 +10,7 @@
|
||||
<artifactId>swagger-codegen-distribution</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>swagger-codegen (executable)</name>
|
||||
<version>2.1.1-M1</version>
|
||||
<version>2.1.2-M1</version>
|
||||
<build>
|
||||
<testSourceDirectory>src/test/scala</testSourceDirectory>
|
||||
<outputDirectory>target/classes</outputDirectory>
|
||||
|
@ -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>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>swagger-codegen-project</artifactId>
|
||||
<version>2.1.1-M1</version>
|
||||
<version>2.1.2-M1</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -10,7 +10,7 @@
|
||||
<artifactId>swagger-codegen</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>swagger-codegen (core library)</name>
|
||||
<version>2.1.1-M1</version>
|
||||
<version>2.1.2-M1</version>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
|
@ -84,7 +84,7 @@ public class Codegen extends DefaultGenerator {
|
||||
return;
|
||||
}
|
||||
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"))
|
||||
clientOpts.getProperties().put("templateDir", String.valueOf(cmd.getOptionValue("t")));
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public interface CodegenConfig {
|
||||
String modelFileFolder();
|
||||
String modelPackage();
|
||||
String toApiName(String name);
|
||||
String toApiVarName(String name);
|
||||
String toModelName(String name);
|
||||
String toParamName(String name);
|
||||
String escapeReservedWord(String name);
|
||||
|
@ -11,6 +11,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class DefaultCodegen {
|
||||
Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
|
||||
@ -101,11 +102,11 @@ public class DefaultCodegen {
|
||||
}
|
||||
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + apiPackage().replaceAll("\\.", "/");
|
||||
return outputFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + modelPackage().replaceAll("\\.", "/");
|
||||
return outputFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public Map<String, Object> additionalProperties() {
|
||||
@ -133,6 +134,10 @@ public class DefaultCodegen {
|
||||
return initialCaps(name) + "Api";
|
||||
}
|
||||
|
||||
public String toApiVarName(String name) {
|
||||
return snakeCase(name);
|
||||
}
|
||||
|
||||
public String toModelFilename(String name) {
|
||||
return name;
|
||||
}
|
||||
@ -306,6 +311,10 @@ public class DefaultCodegen {
|
||||
return datatype;
|
||||
}
|
||||
|
||||
public String snakeCase(String name) {
|
||||
return Character.toLowerCase(name.charAt(0)) + name.substring(1);
|
||||
}
|
||||
|
||||
public String initialCaps(String name) {
|
||||
return Character.toUpperCase(name.charAt(0)) + name.substring(1);
|
||||
}
|
||||
|
@ -114,6 +114,7 @@ public class DefaultGenerator implements Generator {
|
||||
operation.put("modelPackage", config.modelPackage());
|
||||
operation.putAll(config.additionalProperties());
|
||||
operation.put("classname", config.toApiName(tag));
|
||||
operation.put("classVarName", config.toApiVarName(tag));
|
||||
allOperations.add(operation);
|
||||
for(String templateName : config.apiTemplateFiles().keySet()) {
|
||||
String suffix = config.apiTemplateFiles().get(templateName);
|
||||
@ -153,7 +154,7 @@ public class DefaultGenerator implements Generator {
|
||||
}
|
||||
bundle.put("apiInfo", apis);
|
||||
bundle.put("models", allModels);
|
||||
bundle.put("apiFolder", config.apiPackage().replaceAll("\\.", "/"));
|
||||
bundle.put("apiFolder", config.apiPackage().replace('.', File.separatorChar));
|
||||
bundle.put("modelPackage", config.modelPackage());
|
||||
if (swagger.getExternalDocs() != null) {
|
||||
bundle.put("externalDocs", swagger.getExternalDocs());
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
@ -89,11 +89,11 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + apiPackage().replaceAll("\\.", File.separator);
|
||||
return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + modelPackage().replaceAll("\\.", File.separator);
|
||||
return outputFolder + File.separator + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,11 +64,11 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + apiPackage().replaceAll("\\.", "/");
|
||||
return outputFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + modelPackage().replaceAll("\\.", "/");
|
||||
return outputFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,4 +1,5 @@
|
||||
com.wordnik.swagger.codegen.languages.AndroidClientCodegen
|
||||
com.wordnik.swagger.codegen.languages.AsyncScalaClientCodegen
|
||||
com.wordnik.swagger.codegen.languages.JavaClientCodegen
|
||||
com.wordnik.swagger.codegen.languages.JaxRSServerCodegen
|
||||
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.TizenClientCodegen
|
||||
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
|
||||
|
||||
{{#operations}}
|
||||
class {{className}}(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
|
||||
class {{classname}}(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
|
||||
|
||||
{{#operation}}
|
||||
|
||||
def {{nickname}}({{#allParams}}
|
||||
{{#optional}}
|
||||
{{paramName}}: Option[{{dataType}}] = {{#defaultValue}}Some({{defaultValue}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{#hasMore}}, {{/hasMore}}
|
||||
{{/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}} = {
|
||||
def {{nickname}}({{#allParams}}{{#optional}}{{paramName}}: Option[{{dataType}}] = {{#defaultValue}}Some({{defaultValue}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{#hasMore}},
|
||||
{{/hasMore}}
|
||||
{{/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
|
||||
val path =
|
||||
(addFmt("{{path}}"){{#pathParams}}
|
||||
replaceAll ("\\{" + "{{baseName}}" + "\\}",{{paramName}}.toString)
|
||||
{{/pathParams}})
|
||||
val path = (addFmt("{{path}}"){{#pathParams}}
|
||||
replaceAll ("\\{" + "{{baseName}}" + "\\}",{{paramName}}.toString){{/pathParams}})
|
||||
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
{{#requiredParamCount}}
|
||||
// verify required params are set
|
||||
{{#requiredParamCount}}// verify required params are set
|
||||
val paramCount = (Set[Any]({{/requiredParamCount}}{{#requiredParams}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) - null).size
|
||||
if (paramCount != {{requiredParamCount}}) sys.error("missing required params")
|
||||
{{/requiredParamCount}}
|
||||
if (paramCount != {{requiredParamCount}}) sys.error("missing required params"){{/requiredParamCount}}
|
||||
|
||||
{{#queryParams}}
|
||||
{{#optional}}
|
||||
if({{paramName}} != null) {{paramName}}.foreach { v => queryParams += "{{baseName}}" -> v.toString }
|
||||
{{/optional}}
|
||||
{{^optional}}
|
||||
if({{paramName}} != null) queryParams += "{{baseName}}" -> {{paramName}}.toString
|
||||
{{/optional}}
|
||||
{{/queryParams}}
|
||||
{{#queryParams}}{{#optional}}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}}headerParams += "{{baseName}}" -> {{paramName}}.toString{{/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 =>
|
||||
process(reader.read(resp))
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package {{package}}
|
||||
package {{invokerPackage}}
|
||||
|
||||
{{#imports}}import {{import}}
|
||||
{{/imports}}
|
||||
import {{apiPackage}}._
|
||||
|
||||
import com.wordnik.swagger.client._
|
||||
import apis._
|
||||
|
||||
import java.io.Closeable
|
||||
|
||||
class {{clientName}}(config: SwaggerConfig) extends Closeable {
|
||||
@ -13,12 +15,9 @@ class {{clientName}}(config: SwaggerConfig) extends Closeable {
|
||||
private[this] val client = transportClient
|
||||
|
||||
protected def transportClient: TransportClient = new RestClient(config)
|
||||
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
val {{name}} = new {{className}}(client, config)
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
||||
{{#apiInfo}}{{#apis}}
|
||||
val {{classVarName}} = new {{classname}}(client, config)
|
||||
{{/apis}}{{/apiInfo}}
|
||||
|
||||
def close() {
|
||||
client.close()
|
||||
|
@ -6,9 +6,7 @@ import org.joda.time.DateTime
|
||||
|
||||
{{#model}}
|
||||
case class {{classname}} (
|
||||
{{#vars}}
|
||||
|
||||
{{name}}: {{#isNotRequired}}Option[{{/isNotRequired}}{{datatype}}{{#isNotRequired}}]{{/isNotRequired}} {{#hasMore}},{{/hasMore}}{{#description}} // {{description}}{{/description}}{{newline}}
|
||||
{{#vars}}{{name}}: {{#isNotRequired}}Option[{{/isNotRequired}}{{datatype}}{{#isNotRequired}}]{{/isNotRequired}}{{#hasMore}},{{/hasMore}}{{#description}} // {{description}}{{/description}}
|
||||
{{/vars}}
|
||||
)
|
||||
{{/model}}
|
||||
|
@ -2,7 +2,7 @@ organization := "{{package}}"
|
||||
|
||||
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"
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"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",
|
||||
"title": "Swagger Petstore",
|
||||
"termsOfService": "http://helloreverb.com/terms/",
|
||||
@ -13,7 +13,7 @@
|
||||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
}
|
||||
},
|
||||
"host": "petstore.swagger.wordnik.com",
|
||||
"host": "petstore.swagger.io",
|
||||
"basePath": "/v2",
|
||||
"schemes": [
|
||||
"http"
|
||||
|
@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.wordnik</groupId>
|
||||
<artifactId>swagger-codegen-project</artifactId>
|
||||
<version>2.1.1-M1</version>
|
||||
<version>2.1.2-M1</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<groupId>com.wordnik</groupId>
|
||||
|
@ -14,7 +14,7 @@
|
||||
"url": "http://github.com/gruntjs/grunt/blob/master/LICENSE-MIT"
|
||||
}
|
||||
},
|
||||
"host": "petstore.swagger.wordnik.com",
|
||||
"host": "petstore.swagger.io",
|
||||
"basePath": "/api",
|
||||
"paths": {
|
||||
"/pet": {
|
||||
|
@ -82,14 +82,24 @@ public class Generator {
|
||||
|
||||
public static String generateServer(String language, GeneratorInput opts) throws ApiException {
|
||||
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) {
|
||||
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) {
|
||||
throw new BadRequestException(400, "The swagger specification supplied was not valid");
|
||||
}
|
||||
|
@ -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>
|
||||
<packaging>pom</packaging>
|
||||
<name>swagger-codegen-project</name>
|
||||
<version>2.1.1-M1</version>
|
||||
<version>2.1.2-M1</version>
|
||||
<url>https://github.com/swagger-api/swagger-codegen</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:swagger-api/swagger-codegen.git</connection>
|
||||
@ -347,10 +347,10 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<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>
|
||||
<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>
|
||||
<commons-io-version>2.3</commons-io-version>
|
||||
<commons-cli-version>1.2</commons-cli-version>
|
||||
|
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
|
||||
|
||||
)
|
Loading…
Reference in New Issue
Block a user