forked from loafle/openapi-generator-original
20
README.md
20
README.md
@@ -5,20 +5,15 @@
|
||||
## Overview
|
||||
This is the swagger codegen project, which allows generation of client libraries automatically from a Swagger-compliant server.
|
||||
|
||||
## What's Swagger?
|
||||
|
||||
The goal of Swagger™ is to define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via Swagger, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interfaces have done for lower-level programming, Swagger removes the guesswork in calling the service.
|
||||
|
||||
|
||||
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:
|
||||
|
||||
Swagger Codegen Version | Release Date | Swagger Spec compatibility | Notes
|
||||
----------------------- | ------------ | -------------------------- | -----
|
||||
2.1.0 | 2015-06-09 | 1.0, 1.1, 1.2, 2.0 | [master](https://github.com/swagger-api/swagger-codegen)
|
||||
2.1.0 | 2015-06-09 | 1.0, 1.1, 1.2, 2.0 | [master](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)
|
||||
|
||||
@@ -29,6 +24,17 @@ You need the following installed and available in your $PATH:
|
||||
* [Java 7](http://java.oracle.com)
|
||||
|
||||
* [Apache maven 3.0.3 or greater](http://maven.apache.org/)
|
||||
|
||||
#### OS X Users
|
||||
Don't forget to install Java 7. You probably have 1.6 or 1.8.
|
||||
|
||||
Export JAVA_HOME in order to user proper Java version:
|
||||
```
|
||||
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
|
||||
export PATH=${JAVA_HOME}/bin:$PATH
|
||||
```
|
||||
|
||||
#### Building
|
||||
|
||||
After cloning the project, you can build it from source with this command:
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ cd $APP_DIR
|
||||
./bin/jaxrs-petstore-server.sh
|
||||
./bin/java-petstore.sh
|
||||
./bin/qt5-petstore.sh
|
||||
./bin/perl-petstore.sh
|
||||
./bin/php-petstore.sh
|
||||
./bin/python-petstore.sh
|
||||
./bin/retrofit-petstore.sh
|
||||
|
||||
@@ -8,43 +8,43 @@ import static java.net.URI.create;
|
||||
|
||||
class ApiUtils {
|
||||
|
||||
def invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, method, container, type) {
|
||||
def (url, uriPath) = buildUrlAndUriPath(basePath, versionPath, resourcePath)
|
||||
println "url=$url uriPath=$uriPath"
|
||||
def http = new HTTPBuilder(url)
|
||||
http.request( Method.valueOf(method), JSON ) {
|
||||
uri.path = uriPath
|
||||
uri.query = queryParams
|
||||
response.success = { resp, json ->
|
||||
if (type != null) {
|
||||
onSuccess(parse(json, container, type))
|
||||
}
|
||||
}
|
||||
response.failure = { resp ->
|
||||
onFailure(resp.status, resp.statusLine.reasonPhrase)
|
||||
}
|
||||
}
|
||||
}
|
||||
def invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams, method, container, type) {
|
||||
def (url, uriPath) = buildUrlAndUriPath(basePath, versionPath, resourcePath)
|
||||
println "url=$url uriPath=$uriPath"
|
||||
def http = new HTTPBuilder(url)
|
||||
http.request( Method.valueOf(method), JSON ) {
|
||||
uri.path = uriPath
|
||||
uri.query = queryParams
|
||||
response.success = { resp, json ->
|
||||
if (type != null) {
|
||||
onSuccess(parse(json, container, type))
|
||||
}
|
||||
}
|
||||
response.failure = { resp ->
|
||||
onFailure(resp.status, resp.statusLine.reasonPhrase)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def buildUrlAndUriPath(basePath, versionPath, resourcePath) {
|
||||
// HTTPBuilder expects to get as its constructor parameter an URL,
|
||||
// without any other additions like path, therefore we need to cut the path
|
||||
// from the basePath as it is represented by swagger APIs
|
||||
// we use java.net.URI to manipulate the basePath
|
||||
// then the uriPath will hold the rest of the path
|
||||
URI baseUri = create(basePath)
|
||||
def pathOnly = baseUri.getPath()
|
||||
[basePath-pathOnly, pathOnly+versionPath+resourcePath]
|
||||
}
|
||||
def buildUrlAndUriPath(basePath, versionPath, resourcePath) {
|
||||
// HTTPBuilder expects to get as its constructor parameter an URL,
|
||||
// without any other additions like path, therefore we need to cut the path
|
||||
// from the basePath as it is represented by swagger APIs
|
||||
// we use java.net.URI to manipulate the basePath
|
||||
// then the uriPath will hold the rest of the path
|
||||
URI baseUri = create(basePath)
|
||||
def pathOnly = baseUri.getPath()
|
||||
[basePath-pathOnly, pathOnly+versionPath+resourcePath]
|
||||
}
|
||||
|
||||
|
||||
def parse(object, container, clazz) {
|
||||
if (container == "List") {
|
||||
return object.collect {parse(it, "", clazz)}
|
||||
} else {
|
||||
return clazz.newInstance(object)
|
||||
}
|
||||
}
|
||||
def parse(object, container, clazz) {
|
||||
if (container == "List") {
|
||||
return object.collect {parse(it, "", clazz)}
|
||||
} else {
|
||||
return clazz.newInstance(object)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package {{package}};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import groovyx.net.http.*
|
||||
import static groovyx.net.http.ContentType.*
|
||||
import static groovyx.net.http.Method.*
|
||||
@@ -14,40 +17,40 @@ import java.util.*;
|
||||
|
||||
@Mixin(ApiUtils)
|
||||
{{#operations}}
|
||||
class {{classname}} {
|
||||
class {{classname}} {
|
||||
String basePath = "{{basePath}}"
|
||||
String versionPath = "/api/v1"
|
||||
|
||||
|
||||
{{#operation}}
|
||||
def {{nickname}} ({{#allParams}} {{{dataType}}} {{paramName}},{{/allParams}} Closure onSuccess, Closure onFailure) {
|
||||
// create path and map variables
|
||||
String resourcePath = "{{path}}"
|
||||
{{#operation}}
|
||||
def {{nickname}} ({{#allParams}} {{{dataType}}} {{paramName}},{{/allParams}} Closure onSuccess, Closure onFailure) {
|
||||
// create path and map variables
|
||||
String resourcePath = "{{path}}"
|
||||
|
||||
|
||||
// query params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
// query params
|
||||
def queryParams = [:]
|
||||
def headerParams = [:]
|
||||
|
||||
{{#requiredParamCount}}
|
||||
// verify required params are set
|
||||
if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) {
|
||||
throw new RuntimeException("missing required params")
|
||||
}
|
||||
{{/requiredParamCount}}
|
||||
|
||||
{{#queryParams}}if(!"null".equals(String.valueOf({{paramName}})))
|
||||
queryParams.put("{{paramName}}", String.valueOf({{paramName}}))
|
||||
{{/queryParams}}
|
||||
|
||||
{{#headerParams}}headerParams.put("{{paramName}}", {{paramName}})
|
||||
{{/headerParams}}
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
"{{httpMethod}}", "{{returnContainer}}",
|
||||
{{#returnBaseType}}{{{returnBaseType}}}.class {{/returnBaseType}}{{^returnBaseType}}null {{/returnBaseType}})
|
||||
|
||||
}
|
||||
{{/operation}}
|
||||
{{#requiredParamCount}}
|
||||
// verify required params are set
|
||||
if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) {
|
||||
throw new RuntimeException("missing required params")
|
||||
}
|
||||
{{/requiredParamCount}}
|
||||
|
||||
{{#queryParams}}if(!"null".equals(String.valueOf({{paramName}})))
|
||||
queryParams.put("{{paramName}}", String.valueOf({{paramName}}))
|
||||
{{/queryParams}}
|
||||
|
||||
{{#headerParams}}headerParams.put("{{paramName}}", {{paramName}})
|
||||
{{/headerParams}}
|
||||
|
||||
invokeApi(onSuccess, onFailure, basePath, versionPath, resourcePath, queryParams, headerParams,
|
||||
"{{httpMethod}}", "{{returnContainer}}",
|
||||
{{#returnBaseType}}{{{returnBaseType}}}.class {{/returnBaseType}}{{^returnBaseType}}null {{/returnBaseType}})
|
||||
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
@@ -6,24 +6,24 @@ archivesBaseName = 'swagger-gen-groovy'
|
||||
version = '0.1'
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
maven { url 'http://repo.jfrog.org/artifactory/gradle-plugins' }
|
||||
}
|
||||
dependencies {
|
||||
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.16')
|
||||
}
|
||||
repositories {
|
||||
maven { url 'http://repo.jfrog.org/artifactory/gradle-plugins' }
|
||||
}
|
||||
dependencies {
|
||||
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.16')
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
mavenCentral(artifactUrls: ['http://maven.springframework.org/milestone'])
|
||||
maven { url "http://$artifactory:8080/artifactory/repo" }
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
mavenCentral(artifactUrls: ['http://maven.springframework.org/milestone'])
|
||||
maven { url "http://$artifactory:8080/artifactory/repo" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
groovy "org.codehaus.groovy:groovy-all:2.0.5"
|
||||
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.6'
|
||||
groovy "org.codehaus.groovy:groovy-all:2.0.5"
|
||||
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.6'
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,18 +4,18 @@ import groovy.transform.Canonical
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
@Canonical
|
||||
class {{classname}} {
|
||||
{{#vars}}
|
||||
{{#model}}
|
||||
@Canonical
|
||||
class {{classname}} {
|
||||
{{#vars}}
|
||||
|
||||
{{#description}}/* {{{description}}} */
|
||||
{{/description}}
|
||||
{{{datatype}}} {{name}} = {{{defaultValue}}}
|
||||
{{/vars}}
|
||||
{{#description}}/* {{{description}}} */
|
||||
{{/description}}
|
||||
{{{datatype}}} {{name}} = {{{defaultValue}}}
|
||||
{{/vars}}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
{{/model}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
@@ -40,482 +40,468 @@ import {{invokerPackage}}.auth.ApiKeyAuth;
|
||||
import {{invokerPackage}}.auth.OAuth;
|
||||
|
||||
public class ApiClient {
|
||||
private Map
|
||||
<String, Client> hostMap = new HashMap
|
||||
<String, Client>();
|
||||
private Map
|
||||
<String, String> defaultHeaderMap = new HashMap
|
||||
<String, String>();
|
||||
private boolean debugging = false;
|
||||
private String basePath = "{{basePath}}";
|
||||
private Map<String, Client> hostMap = new HashMap<String, Client>();
|
||||
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
private boolean debugging = false;
|
||||
private String basePath = "{{basePath}}";
|
||||
|
||||
private Map
|
||||
<String, Authentication> authentications;
|
||||
private Map<String, Authentication> authentications;
|
||||
|
||||
private DateFormat dateFormat;
|
||||
private DateFormat dateFormat;
|
||||
|
||||
public ApiClient() {
|
||||
// Use ISO 8601 format for date and datetime.
|
||||
// See https://en.wikipedia.org/wiki/ISO_8601
|
||||
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
public ApiClient() {
|
||||
// Use ISO 8601 format for date and datetime.
|
||||
// See https://en.wikipedia.org/wiki/ISO_8601
|
||||
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
|
||||
// Use UTC as the default time zone.
|
||||
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
// Use UTC as the default time zone.
|
||||
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
// Set default User-Agent.
|
||||
setUserAgent("Java-Swagger");
|
||||
// Set default User-Agent.
|
||||
setUserAgent("Java-Swagger");
|
||||
|
||||
// Setup authentications (key: authentication name, value: authentication).
|
||||
authentications = new HashMap
|
||||
<String, Authentication>();{{#authMethods}}{{#isBasic}}
|
||||
// Setup authentications (key: authentication name, value: authentication).
|
||||
authentications = new HashMap<String, Authentication>();{{#authMethods}}{{#isBasic}}
|
||||
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasic}}{{#isApiKey}}
|
||||
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
|
||||
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
||||
// Prevent the authentications from being modified.
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
}
|
||||
// Prevent the authentications from being modified.
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
}
|
||||
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public ApiClient setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
return this;
|
||||
}
|
||||
public ApiClient setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get authentications (key: authentication name, value: authentication).
|
||||
*/
|
||||
public Map
|
||||
<String, Authentication> getAuthentications() {
|
||||
return authentications;
|
||||
}
|
||||
/**
|
||||
* Get authentications (key: authentication name, value: authentication).
|
||||
*/
|
||||
public Map<String, Authentication> getAuthentications() {
|
||||
return authentications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get authentication for the given name.
|
||||
*
|
||||
* @param authName The authentication name
|
||||
* @return The authentication, null if not found
|
||||
*/
|
||||
public Authentication getAuthentication(String authName) {
|
||||
return authentications.get(authName);
|
||||
}
|
||||
/**
|
||||
* Get authentication for the given name.
|
||||
*
|
||||
* @param authName The authentication name
|
||||
* @return The authentication, null if not found
|
||||
*/
|
||||
public Authentication getAuthentication(String authName) {
|
||||
return authentications.get(authName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set username for the first HTTP basic authentication.
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
((HttpBasicAuth) auth).setUsername(username);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No HTTP basic authentication configured!");
|
||||
}
|
||||
/**
|
||||
* Helper method to set username for the first HTTP basic authentication.
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
((HttpBasicAuth) auth).setUsername(username);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No HTTP basic authentication configured!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set password for the first HTTP basic authentication.
|
||||
*/
|
||||
public void setPassword(String password) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
((HttpBasicAuth) auth).setPassword(password);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No HTTP basic authentication configured!");
|
||||
}
|
||||
/**
|
||||
* Helper method to set password for the first HTTP basic authentication.
|
||||
*/
|
||||
public void setPassword(String password) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
((HttpBasicAuth) auth).setPassword(password);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No HTTP basic authentication configured!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set API key value for the first API key authentication.
|
||||
*/
|
||||
public void setApiKey(String apiKey) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
((ApiKeyAuth) auth).setApiKey(apiKey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No API key authentication configured!");
|
||||
}
|
||||
/**
|
||||
* Helper method to set API key value for the first API key authentication.
|
||||
*/
|
||||
public void setApiKey(String apiKey) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
((ApiKeyAuth) auth).setApiKey(apiKey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No API key authentication configured!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set API key prefix for the first API key authentication.
|
||||
*/
|
||||
public void setApiKeyPrefix(String apiKeyPrefix) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No API key authentication configured!");
|
||||
}
|
||||
/**
|
||||
* Helper method to set API key prefix for the first API key authentication.
|
||||
*/
|
||||
public void setApiKeyPrefix(String apiKeyPrefix) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No API key authentication configured!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the User-Agent header's value (by adding to the default header map).
|
||||
*/
|
||||
public ApiClient setUserAgent(String userAgent) {
|
||||
addDefaultHeader("User-Agent", userAgent);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the User-Agent header's value (by adding to the default header map).
|
||||
*/
|
||||
public ApiClient setUserAgent(String userAgent) {
|
||||
addDefaultHeader("User-Agent", userAgent);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a default header.
|
||||
*
|
||||
* @param key The header's key
|
||||
* @param value The header's value
|
||||
*/
|
||||
public ApiClient addDefaultHeader(String key, String value) {
|
||||
defaultHeaderMap.put(key, value);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Add a default header.
|
||||
*
|
||||
* @param key The header's key
|
||||
* @param value The header's value
|
||||
*/
|
||||
public ApiClient addDefaultHeader(String key, String value) {
|
||||
defaultHeaderMap.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that whether debugging is enabled for this API client.
|
||||
*/
|
||||
public boolean isDebugging() {
|
||||
return debugging;
|
||||
}
|
||||
/**
|
||||
* Check that whether debugging is enabled for this API client.
|
||||
*/
|
||||
public boolean isDebugging() {
|
||||
return debugging;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable debugging for this API client.
|
||||
*
|
||||
* @param debugging To enable (true) or disable (false) debugging
|
||||
*/
|
||||
public ApiClient setDebugging(boolean debugging) {
|
||||
this.debugging = debugging;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Enable/disable debugging for this API client.
|
||||
*
|
||||
* @param debugging To enable (true) or disable (false) debugging
|
||||
*/
|
||||
public ApiClient setDebugging(boolean debugging) {
|
||||
this.debugging = debugging;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date format used to parse/format date parameters.
|
||||
*/
|
||||
public DateFormat getDateFormat() {
|
||||
return dateFormat;
|
||||
}
|
||||
/**
|
||||
* Get the date format used to parse/format date parameters.
|
||||
*/
|
||||
public DateFormat getDateFormat() {
|
||||
return dateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the date format used to parse/format date parameters.
|
||||
*/
|
||||
public ApiClient getDateFormat(DateFormat dateFormat) {
|
||||
this.dateFormat = dateFormat;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the date format used to parse/format date parameters.
|
||||
*/
|
||||
public ApiClient getDateFormat(DateFormat dateFormat) {
|
||||
this.dateFormat = dateFormat;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given string into Date object.
|
||||
*/
|
||||
public Date parseDate(String str) {
|
||||
try {
|
||||
return dateFormat.parse(str);
|
||||
} catch (java.text.ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Parse the given string into Date object.
|
||||
*/
|
||||
public Date parseDate(String str) {
|
||||
try {
|
||||
return dateFormat.parse(str);
|
||||
} catch (java.text.ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given Date object into string.
|
||||
*/
|
||||
public String formatDate(Date date) {
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
/**
|
||||
* Format the given Date object into string.
|
||||
*/
|
||||
public String formatDate(Date date) {
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given parameter object into string.
|
||||
*/
|
||||
public String parameterToString(Object param) {
|
||||
if (param == null) {
|
||||
return "";
|
||||
} else if (param instanceof Date) {
|
||||
return formatDate((Date) param);
|
||||
} else if (param instanceof Collection) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(Object o : (Collection)param) {
|
||||
if(b.length() > 0) {
|
||||
b.append(",");
|
||||
}
|
||||
b.append(String.valueOf(o));
|
||||
}
|
||||
return b.toString();
|
||||
} else {
|
||||
return String.valueOf(param);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Format the given parameter object into string.
|
||||
*/
|
||||
public String parameterToString(Object param) {
|
||||
if (param == null) {
|
||||
return "";
|
||||
} else if (param instanceof Date) {
|
||||
return formatDate((Date) param);
|
||||
} else if (param instanceof Collection) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(Object o : (Collection)param) {
|
||||
if(b.length() > 0) {
|
||||
b.append(",");
|
||||
}
|
||||
b.append(String.valueOf(o));
|
||||
}
|
||||
return b.toString();
|
||||
} else {
|
||||
return String.valueOf(param);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the Accept header's value from the given accepts array:
|
||||
* if JSON exists in the given array, use it;
|
||||
* otherwise use all of them (joining into a string)
|
||||
*
|
||||
* @param accepts The accepts array to select from
|
||||
* @return The Accept header to use. If the given array is empty,
|
||||
* null will be returned (not to set the Accept header explicitly).
|
||||
*/
|
||||
public String selectHeaderAccept(String[] accepts) {
|
||||
if (accepts.length == 0) return null;
|
||||
if (StringUtil.containsIgnoreCase(accepts, "application/json")) return "application/json";
|
||||
return StringUtil.join(accepts, ",");
|
||||
}
|
||||
/**
|
||||
* Select the Accept header's value from the given accepts array:
|
||||
* if JSON exists in the given array, use it;
|
||||
* otherwise use all of them (joining into a string)
|
||||
*
|
||||
* @param accepts The accepts array to select from
|
||||
* @return The Accept header to use. If the given array is empty,
|
||||
* null will be returned (not to set the Accept header explicitly).
|
||||
*/
|
||||
public String selectHeaderAccept(String[] accepts) {
|
||||
if (accepts.length == 0) return null;
|
||||
if (StringUtil.containsIgnoreCase(accepts, "application/json")) return "application/json";
|
||||
return StringUtil.join(accepts, ",");
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the Content-Type header's value from the given array:
|
||||
* if JSON exists in the given array, use it;
|
||||
* otherwise use the first one of the array.
|
||||
*
|
||||
* @param contentTypes The Content-Type array to select from
|
||||
* @return The Content-Type header to use. If the given array is empty,
|
||||
* JSON will be used.
|
||||
*/
|
||||
public String selectHeaderContentType(String[] contentTypes) {
|
||||
if (contentTypes.length == 0) return "application/json";
|
||||
if (StringUtil.containsIgnoreCase(contentTypes, "application/json")) return "application/json";
|
||||
return contentTypes[0];
|
||||
}
|
||||
/**
|
||||
* Select the Content-Type header's value from the given array:
|
||||
* if JSON exists in the given array, use it;
|
||||
* otherwise use the first one of the array.
|
||||
*
|
||||
* @param contentTypes The Content-Type array to select from
|
||||
* @return The Content-Type header to use. If the given array is empty,
|
||||
* JSON will be used.
|
||||
*/
|
||||
public String selectHeaderContentType(String[] contentTypes) {
|
||||
if (contentTypes.length == 0) return "application/json";
|
||||
if (StringUtil.containsIgnoreCase(contentTypes, "application/json")) return "application/json";
|
||||
return contentTypes[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape the given string to be used as URL query value.
|
||||
*/
|
||||
public String escapeString(String str) {
|
||||
try {
|
||||
return URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Escape the given string to be used as URL query value.
|
||||
*/
|
||||
public String escapeString(String str) {
|
||||
try {
|
||||
return URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize the given JSON string to Java object.
|
||||
*
|
||||
* @param json The JSON string
|
||||
* @param containerType The container type, one of "list", "array" or ""
|
||||
* @param cls The type of the Java object
|
||||
* @return The deserialized Java object
|
||||
*/
|
||||
public Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
||||
if(null != containerType) {
|
||||
containerType = containerType.toLowerCase();
|
||||
}
|
||||
try{
|
||||
if("list".equals(containerType) || "array".equals(containerType)) {
|
||||
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
|
||||
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
|
||||
return response;
|
||||
}
|
||||
else if(String.class.equals(cls)) {
|
||||
if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
|
||||
return json.substring(1, json.length() - 2);
|
||||
else
|
||||
return json;
|
||||
}
|
||||
else {
|
||||
return JsonUtil.getJsonMapper().readValue(json, cls);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new ApiException(500, e.getMessage(), null, json);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Deserialize the given JSON string to Java object.
|
||||
*
|
||||
* @param json The JSON string
|
||||
* @param containerType The container type, one of "list", "array" or ""
|
||||
* @param cls The type of the Java object
|
||||
* @return The deserialized Java object
|
||||
*/
|
||||
public Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
||||
if(null != containerType) {
|
||||
containerType = containerType.toLowerCase();
|
||||
}
|
||||
try{
|
||||
if("list".equals(containerType) || "array".equals(containerType)) {
|
||||
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
|
||||
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
|
||||
return response;
|
||||
}
|
||||
else if(String.class.equals(cls)) {
|
||||
if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
|
||||
return json.substring(1, json.length() - 2);
|
||||
else
|
||||
return json;
|
||||
}
|
||||
else {
|
||||
return JsonUtil.getJsonMapper().readValue(json, cls);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new ApiException(500, e.getMessage(), null, json);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the given Java object into JSON string.
|
||||
*/
|
||||
public String serialize(Object obj) throws ApiException {
|
||||
try {
|
||||
if (obj != null)
|
||||
return JsonUtil.getJsonMapper().writeValueAsString(obj);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ApiException(500, e.getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Serialize the given Java object into JSON string.
|
||||
*/
|
||||
public String serialize(Object obj) throws ApiException {
|
||||
try {
|
||||
if (obj != null)
|
||||
return JsonUtil.getJsonMapper().writeValueAsString(obj);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ApiException(500, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke API by sending HTTP request with the given options.
|
||||
*
|
||||
* @param path The sub-path of the HTTP URL
|
||||
* @param method The request method, one of "GET", "POST", "PUT", and "DELETE"
|
||||
* @param queryParams The query parameters
|
||||
* @param body The request body object
|
||||
* @param headerParams The header parameters
|
||||
* @param formParams The form parameters
|
||||
* @param accept The request's Accept header
|
||||
* @param contentType The request's Content-Type header
|
||||
* @param authNames The authentications to apply
|
||||
* @return The response body in type of string
|
||||
*/
|
||||
public String invokeAPI(String path, String method, Map
|
||||
<String, String> queryParams, Object body, Map
|
||||
<String, String> headerParams, Map
|
||||
<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
|
||||
updateParamsForAuth(authNames, queryParams, headerParams);
|
||||
/**
|
||||
* Invoke API by sending HTTP request with the given options.
|
||||
*
|
||||
* @param path The sub-path of the HTTP URL
|
||||
* @param method The request method, one of "GET", "POST", "PUT", and "DELETE"
|
||||
* @param queryParams The query parameters
|
||||
* @param body The request body object
|
||||
* @param headerParams The header parameters
|
||||
* @param formParams The form parameters
|
||||
* @param accept The request's Accept header
|
||||
* @param contentType The request's Content-Type header
|
||||
* @param authNames The authentications to apply
|
||||
* @return The response body in type of string
|
||||
*/
|
||||
public String invokeAPI(String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
|
||||
updateParamsForAuth(authNames, queryParams, headerParams);
|
||||
|
||||
Client client = getClient();
|
||||
Client client = getClient();
|
||||
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(String key : queryParams.keySet()) {
|
||||
String value = queryParams.get(key);
|
||||
if (value != null){
|
||||
if(b.toString().length() == 0)
|
||||
b.append("?");
|
||||
else
|
||||
b.append("&");
|
||||
b.append(escapeString(key)).append("=").append(escapeString(value));
|
||||
}
|
||||
}
|
||||
String querystring = b.toString();
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(String key : queryParams.keySet()) {
|
||||
String value = queryParams.get(key);
|
||||
if (value != null){
|
||||
if(b.toString().length() == 0)
|
||||
b.append("?");
|
||||
else
|
||||
b.append("&");
|
||||
b.append(escapeString(key)).append("=").append(escapeString(value));
|
||||
}
|
||||
}
|
||||
String querystring = b.toString();
|
||||
|
||||
Builder builder;
|
||||
if (accept == null)
|
||||
builder = client.resource(basePath + path + querystring).getRequestBuilder();
|
||||
else
|
||||
builder = client.resource(basePath + path + querystring).accept(accept);
|
||||
Builder builder;
|
||||
if (accept == null)
|
||||
builder = client.resource(basePath + path + querystring).getRequestBuilder();
|
||||
else
|
||||
builder = client.resource(basePath + path + querystring).accept(accept);
|
||||
|
||||
for(String key : headerParams.keySet()) {
|
||||
builder = builder.header(key, headerParams.get(key));
|
||||
}
|
||||
for(String key : defaultHeaderMap.keySet()) {
|
||||
if(!headerParams.containsKey(key)) {
|
||||
builder = builder.header(key, defaultHeaderMap.get(key));
|
||||
}
|
||||
}
|
||||
for(String key : headerParams.keySet()) {
|
||||
builder = builder.header(key, headerParams.get(key));
|
||||
}
|
||||
for(String key : defaultHeaderMap.keySet()) {
|
||||
if(!headerParams.containsKey(key)) {
|
||||
builder = builder.header(key, defaultHeaderMap.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
ClientResponse response = null;
|
||||
ClientResponse response = null;
|
||||
|
||||
if("GET".equals(method)) {
|
||||
response = (ClientResponse) builder.get(ClientResponse.class);
|
||||
}
|
||||
else if ("POST".equals(method)) {
|
||||
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
||||
String encodedFormParams = this
|
||||
.getXWWWFormUrlencodedParams(formParams);
|
||||
response = builder.type(contentType).post(ClientResponse.class,
|
||||
encodedFormParams);
|
||||
} else if (body == null) {
|
||||
response = builder.post(ClientResponse.class, null);
|
||||
} else if(body instanceof FormDataMultiPart) {
|
||||
response = builder.type(contentType).post(ClientResponse.class, body);
|
||||
}
|
||||
else
|
||||
response = builder.type(contentType).post(ClientResponse.class, serialize(body));
|
||||
}
|
||||
else if ("PUT".equals(method)) {
|
||||
if ("application/x-www-form-urlencoded".equals(contentType)) {
|
||||
String encodedFormParams = this
|
||||
.getXWWWFormUrlencodedParams(formParams);
|
||||
response = builder.type(contentType).put(ClientResponse.class,
|
||||
encodedFormParams);
|
||||
} else if(body == null) {
|
||||
response = builder.put(ClientResponse.class, serialize(body));
|
||||
} else {
|
||||
response = builder.type(contentType).put(ClientResponse.class, serialize(body));
|
||||
}
|
||||
}
|
||||
else if ("DELETE".equals(method)) {
|
||||
if ("application/x-www-form-urlencoded".equals(contentType)) {
|
||||
String encodedFormParams = this
|
||||
.getXWWWFormUrlencodedParams(formParams);
|
||||
response = builder.type(contentType).delete(ClientResponse.class,
|
||||
encodedFormParams);
|
||||
} else if(body == null) {
|
||||
response = builder.delete(ClientResponse.class);
|
||||
} else {
|
||||
response = builder.type(contentType).delete(ClientResponse.class, serialize(body));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new ApiException(500, "unknown method type " + method);
|
||||
}
|
||||
if("GET".equals(method)) {
|
||||
response = (ClientResponse) builder.get(ClientResponse.class);
|
||||
}
|
||||
else if ("POST".equals(method)) {
|
||||
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
||||
String encodedFormParams = this
|
||||
.getXWWWFormUrlencodedParams(formParams);
|
||||
response = builder.type(contentType).post(ClientResponse.class,
|
||||
encodedFormParams);
|
||||
} else if (body == null) {
|
||||
response = builder.post(ClientResponse.class, null);
|
||||
} else if(body instanceof FormDataMultiPart) {
|
||||
response = builder.type(contentType).post(ClientResponse.class, body);
|
||||
}
|
||||
else
|
||||
response = builder.type(contentType).post(ClientResponse.class, serialize(body));
|
||||
}
|
||||
else if ("PUT".equals(method)) {
|
||||
if ("application/x-www-form-urlencoded".equals(contentType)) {
|
||||
String encodedFormParams = this
|
||||
.getXWWWFormUrlencodedParams(formParams);
|
||||
response = builder.type(contentType).put(ClientResponse.class,
|
||||
encodedFormParams);
|
||||
} else if(body == null) {
|
||||
response = builder.put(ClientResponse.class, serialize(body));
|
||||
} else {
|
||||
response = builder.type(contentType).put(ClientResponse.class, serialize(body));
|
||||
}
|
||||
}
|
||||
else if ("DELETE".equals(method)) {
|
||||
if ("application/x-www-form-urlencoded".equals(contentType)) {
|
||||
String encodedFormParams = this
|
||||
.getXWWWFormUrlencodedParams(formParams);
|
||||
response = builder.type(contentType).delete(ClientResponse.class,
|
||||
encodedFormParams);
|
||||
} else if(body == null) {
|
||||
response = builder.delete(ClientResponse.class);
|
||||
} else {
|
||||
response = builder.type(contentType).delete(ClientResponse.class, serialize(body));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new ApiException(500, "unknown method type " + method);
|
||||
}
|
||||
|
||||
if(response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) {
|
||||
return null;
|
||||
}
|
||||
else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
|
||||
if(response.hasEntity()) {
|
||||
return (String) response.getEntity(String.class);
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
else {
|
||||
String message = "error";
|
||||
String respBody = null;
|
||||
if(response.hasEntity()) {
|
||||
try{
|
||||
respBody = String.valueOf(response.getEntity(String.class));
|
||||
message = respBody;
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
throw new ApiException(
|
||||
response.getClientResponseStatus().getStatusCode(),
|
||||
message,
|
||||
response.getHeaders(),
|
||||
respBody);
|
||||
}
|
||||
}
|
||||
if(response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) {
|
||||
return null;
|
||||
}
|
||||
else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
|
||||
if(response.hasEntity()) {
|
||||
return (String) response.getEntity(String.class);
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
else {
|
||||
String message = "error";
|
||||
String respBody = null;
|
||||
if(response.hasEntity()) {
|
||||
try{
|
||||
respBody = String.valueOf(response.getEntity(String.class));
|
||||
message = respBody;
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
throw new ApiException(
|
||||
response.getClientResponseStatus().getStatusCode(),
|
||||
message,
|
||||
response.getHeaders(),
|
||||
respBody);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update query and header parameters based on authentication settings.
|
||||
*
|
||||
* @param authNames The authentications to apply
|
||||
*/
|
||||
private void updateParamsForAuth(String[] authNames, Map
|
||||
<String, String> queryParams, Map
|
||||
<String, String> headerParams) {
|
||||
for (String authName : authNames) {
|
||||
Authentication auth = authentications.get(authName);
|
||||
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
|
||||
auth.applyToParams(queryParams, headerParams);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Update query and header parameters based on authentication settings.
|
||||
*
|
||||
* @param authNames The authentications to apply
|
||||
*/
|
||||
private void updateParamsForAuth(String[] authNames, Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
for (String authName : authNames) {
|
||||
Authentication auth = authentications.get(authName);
|
||||
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
|
||||
auth.applyToParams(queryParams, headerParams);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the given form parameters as request body.
|
||||
*/
|
||||
private String getXWWWFormUrlencodedParams(Map
|
||||
<String, String> formParams) {
|
||||
StringBuilder formParamBuilder = new StringBuilder();
|
||||
/**
|
||||
* Encode the given form parameters as request body.
|
||||
*/
|
||||
private String getXWWWFormUrlencodedParams(Map<String, String> formParams) {
|
||||
StringBuilder formParamBuilder = new StringBuilder();
|
||||
|
||||
for (Entry
|
||||
<String, String> param : formParams.entrySet()) {
|
||||
String keyStr = parameterToString(param.getKey());
|
||||
String valueStr = parameterToString(param.getValue());
|
||||
for (Entry<String, String> param : formParams.entrySet()) {
|
||||
String keyStr = parameterToString(param.getKey());
|
||||
String valueStr = parameterToString(param.getValue());
|
||||
|
||||
try {
|
||||
formParamBuilder.append(URLEncoder.encode(keyStr, "utf8"))
|
||||
.append("=")
|
||||
.append(URLEncoder.encode(valueStr, "utf8"));
|
||||
formParamBuilder.append("&");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// move on to next
|
||||
}
|
||||
}
|
||||
String encodedFormParams = formParamBuilder.toString();
|
||||
if (encodedFormParams.endsWith("&")) {
|
||||
encodedFormParams = encodedFormParams.substring(0,
|
||||
encodedFormParams.length() - 1);
|
||||
}
|
||||
return encodedFormParams;
|
||||
}
|
||||
try {
|
||||
formParamBuilder.append(URLEncoder.encode(keyStr, "utf8"))
|
||||
.append("=")
|
||||
.append(URLEncoder.encode(valueStr, "utf8"));
|
||||
formParamBuilder.append("&");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// move on to next
|
||||
}
|
||||
}
|
||||
String encodedFormParams = formParamBuilder.toString();
|
||||
if (encodedFormParams.endsWith("&")) {
|
||||
encodedFormParams = encodedFormParams.substring(0,
|
||||
encodedFormParams.length() - 1);
|
||||
}
|
||||
return encodedFormParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an existing client or create a new client to handle HTTP request.
|
||||
*/
|
||||
private Client getClient() {
|
||||
if(!hostMap.containsKey(basePath)) {
|
||||
Client client = Client.create();
|
||||
if (debugging)
|
||||
client.addFilter(new LoggingFilter());
|
||||
hostMap.put(basePath, client);
|
||||
}
|
||||
return hostMap.get(basePath);
|
||||
}
|
||||
/**
|
||||
* Get an existing client or create a new client to handle HTTP request.
|
||||
*/
|
||||
private Client getClient() {
|
||||
if(!hostMap.containsKey(basePath)) {
|
||||
Client client = Client.create();
|
||||
if (debugging)
|
||||
client.addFilter(new LoggingFilter());
|
||||
hostMap.put(basePath, client);
|
||||
}
|
||||
return hostMap.get(basePath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package {{invokerPackage}};
|
||||
|
||||
public class Configuration {
|
||||
private static ApiClient defaultApiClient = new ApiClient();
|
||||
private static ApiClient defaultApiClient = new ApiClient();
|
||||
|
||||
/**
|
||||
* Get the default API client, which would be used when creating API
|
||||
* instances without providing an API client.
|
||||
*/
|
||||
public static ApiClient getDefaultApiClient() {
|
||||
return defaultApiClient;
|
||||
}
|
||||
/**
|
||||
* Get the default API client, which would be used when creating API
|
||||
* instances without providing an API client.
|
||||
*/
|
||||
public static ApiClient getDefaultApiClient() {
|
||||
return defaultApiClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default API client, which would be used when creating API
|
||||
* instances without providing an API client.
|
||||
*/
|
||||
public static void setDefaultApiClient(ApiClient apiClient) {
|
||||
defaultApiClient = apiClient;
|
||||
}
|
||||
/**
|
||||
* Set the default API client, which would be used when creating API
|
||||
* instances without providing an API client.
|
||||
*/
|
||||
public static void setDefaultApiClient(ApiClient apiClient) {
|
||||
defaultApiClient = apiClient;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,16 +8,16 @@ import com.fasterxml.jackson.core.JsonGenerator.Feature;
|
||||
import com.fasterxml.jackson.datatype.joda.*;
|
||||
|
||||
public class JsonUtil {
|
||||
public static ObjectMapper mapper;
|
||||
public static ObjectMapper mapper;
|
||||
|
||||
static {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
mapper.registerModule(new JodaModule());
|
||||
}
|
||||
static {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
mapper.registerModule(new JodaModule());
|
||||
}
|
||||
|
||||
public static ObjectMapper getJsonMapper() {
|
||||
return mapper;
|
||||
}
|
||||
public static ObjectMapper getJsonMapper() {
|
||||
return mapper;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
package {{invokerPackage}};
|
||||
|
||||
public class StringUtil {
|
||||
/**
|
||||
* Check if the given array contains the given value (with case-insensitive comparison).
|
||||
*
|
||||
* @param array The array
|
||||
* @param value The value to search
|
||||
* @return true if the array contains the value
|
||||
*/
|
||||
public static boolean containsIgnoreCase(String[] array, String value) {
|
||||
for (String str : array) {
|
||||
if (value == null && str == null) return true;
|
||||
if (value != null && value.equalsIgnoreCase(str)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Check if the given array contains the given value (with case-insensitive comparison).
|
||||
*
|
||||
* @param array The array
|
||||
* @param value The value to search
|
||||
* @return true if the array contains the value
|
||||
*/
|
||||
public static boolean containsIgnoreCase(String[] array, String value) {
|
||||
for (String str : array) {
|
||||
if (value == null && str == null) return true;
|
||||
if (value != null && value.equalsIgnoreCase(str)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join an array of strings with the given separator.
|
||||
* <p>
|
||||
* Note: This might be replaced by utility method from commons-lang or guava someday
|
||||
* if one of those libraries is added as dependency.
|
||||
* </p>
|
||||
*
|
||||
* @param array The array of strings
|
||||
* @param separator The separator
|
||||
* @return the resulting string
|
||||
*/
|
||||
public static String join(String[] array, String separator) {
|
||||
int len = array.length;
|
||||
if (len == 0) return "";
|
||||
/**
|
||||
* Join an array of strings with the given separator.
|
||||
* <p>
|
||||
* Note: This might be replaced by utility method from commons-lang or guava someday
|
||||
* if one of those libraries is added as dependency.
|
||||
* </p>
|
||||
*
|
||||
* @param array The array of strings
|
||||
* @param separator The separator
|
||||
* @return the resulting string
|
||||
*/
|
||||
public static String join(String[] array, String separator) {
|
||||
int len = array.length;
|
||||
if (len == 0) return "";
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
out.append(array[0]);
|
||||
for (int i = 1; i < len; i++) {
|
||||
out.append(separator).append(array[i]);
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
StringBuilder out = new StringBuilder();
|
||||
out.append(array[0]);
|
||||
for (int i = 1; i < len; i++) {
|
||||
out.append(separator).append(array[i]);
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,111 +21,105 @@ import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
{{#operations}}
|
||||
public class {{classname}} {
|
||||
private ApiClient apiClient;
|
||||
public class {{classname}} {
|
||||
private ApiClient apiClient;
|
||||
|
||||
public {{classname}}() {
|
||||
public {{classname}}() {
|
||||
this(Configuration.getDefaultApiClient());
|
||||
}
|
||||
}
|
||||
|
||||
public {{classname}}(ApiClient apiClient) {
|
||||
public {{classname}}(ApiClient apiClient) {
|
||||
this.apiClient = apiClient;
|
||||
}
|
||||
}
|
||||
|
||||
public ApiClient getApiClient() {
|
||||
public ApiClient getApiClient() {
|
||||
return apiClient;
|
||||
}
|
||||
}
|
||||
|
||||
public void setApiClient(ApiClient apiClient) {
|
||||
public void setApiClient(ApiClient apiClient) {
|
||||
this.apiClient = apiClient;
|
||||
}
|
||||
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{summary}}
|
||||
* {{notes}}
|
||||
{{#allParams}} * @param {{paramName}} {{description}}
|
||||
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||
*/
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if ({{paramName}} == null) {
|
||||
throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{nickname}}");
|
||||
}
|
||||
{{/required}}{{/allParams}}
|
||||
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{summary}}
|
||||
* {{notes}}
|
||||
{{#allParams}} * @param {{paramName}} {{description}}
|
||||
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||
*/
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if ({{paramName}} == null) {
|
||||
throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{nickname}}");
|
||||
}
|
||||
{{/required}}{{/allParams}}
|
||||
// create path and map variables
|
||||
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}
|
||||
.replaceAll("\\{" + "{{paramName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||
|
||||
// create path and map variables
|
||||
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}
|
||||
.replaceAll("\\{" + "{{paramName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
// query params
|
||||
Map
|
||||
<String, String> queryParams = new HashMap
|
||||
<String, String>();
|
||||
Map
|
||||
<String, String> headerParams = new HashMap
|
||||
<String, String>();
|
||||
Map
|
||||
<String, String> formParams = new HashMap
|
||||
<String, String>();
|
||||
{{#queryParams}}if ({{paramName}} != null)
|
||||
queryParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
||||
{{/queryParams}}
|
||||
|
||||
{{#queryParams}}if ({{paramName}} != null)
|
||||
queryParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
||||
{{/queryParams}}
|
||||
{{#headerParams}}if ({{paramName}} != null)
|
||||
headerParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
||||
{{/headerParams}}
|
||||
|
||||
{{#headerParams}}if ({{paramName}} != null)
|
||||
headerParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
||||
{{/headerParams}}
|
||||
final String[] accepts = {
|
||||
{{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}
|
||||
};
|
||||
final String accept = apiClient.selectHeaderAccept(accepts);
|
||||
|
||||
final String[] accepts = {
|
||||
{{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}
|
||||
};
|
||||
final String accept = apiClient.selectHeaderAccept(accepts);
|
||||
final String[] contentTypes = {
|
||||
{{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}
|
||||
};
|
||||
final String contentType = apiClient.selectHeaderContentType(contentTypes);
|
||||
|
||||
final String[] contentTypes = {
|
||||
{{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}
|
||||
};
|
||||
final String contentType = apiClient.selectHeaderContentType(contentTypes);
|
||||
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
boolean hasFields = false;
|
||||
FormDataMultiPart mp = new FormDataMultiPart();
|
||||
{{#formParams}}{{#notFile}}
|
||||
if ({{paramName}} != null) {
|
||||
hasFields = true;
|
||||
mp.field("{{baseName}}", apiClient.parameterToString({{paramName}}), MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
}
|
||||
{{/notFile}}{{#isFile}}
|
||||
if ({{paramName}} != null) {
|
||||
hasFields = true;
|
||||
mp.field("{{baseName}}", {{paramName}}.getName());
|
||||
mp.bodyPart(new FileDataBodyPart("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE));
|
||||
}
|
||||
{{/isFile}}{{/formParams}}
|
||||
if(hasFields)
|
||||
if(contentType.startsWith("multipart/form-data")) {
|
||||
boolean hasFields = false;
|
||||
FormDataMultiPart mp = new FormDataMultiPart();
|
||||
{{#formParams}}{{#notFile}}
|
||||
if ({{paramName}} != null) {
|
||||
hasFields = true;
|
||||
mp.field("{{baseName}}", apiClient.parameterToString({{paramName}}), MediaType.MULTIPART_FORM_DATA_TYPE);
|
||||
}
|
||||
{{/notFile}}{{#isFile}}
|
||||
if ({{paramName}} != null) {
|
||||
hasFields = true;
|
||||
mp.field("{{baseName}}", {{paramName}}.getName());
|
||||
mp.bodyPart(new FileDataBodyPart("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE));
|
||||
}
|
||||
{{/isFile}}{{/formParams}}
|
||||
if(hasFields)
|
||||
postBody = mp;
|
||||
}
|
||||
else {
|
||||
{{#formParams}}{{#notFile}}if ({{paramName}} != null)
|
||||
formParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));{{/notFile}}
|
||||
{{/formParams}}
|
||||
}
|
||||
|
||||
try {
|
||||
String[] authNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
||||
String response = apiClient.invokeAPI(path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
|
||||
if(response != null){
|
||||
return {{#returnType}}({{{returnType}}}) apiClient.deserialize(response, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}};
|
||||
}
|
||||
else {
|
||||
return {{#returnType}}null{{/returnType}};
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
else {
|
||||
{{#formParams}}{{#notFile}}if ({{paramName}} != null)
|
||||
formParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));{{/notFile}}
|
||||
{{/formParams}}
|
||||
}
|
||||
|
||||
try {
|
||||
String[] authNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
||||
String response = apiClient.invokeAPI(path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
|
||||
if(response != null){
|
||||
return {{#returnType}}({{{returnType}}}) apiClient.deserialize(response, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}};
|
||||
}
|
||||
else {
|
||||
return {{#returnType}}null{{/returnType}};
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
|
||||
@@ -4,52 +4,44 @@ import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
public class ApiException extends Exception {
|
||||
private int code = 0;
|
||||
private String message = null;
|
||||
private Map
|
||||
<String, List
|
||||
<String>> responseHeaders = null;
|
||||
private String responseBody = null;
|
||||
private int code = 0;
|
||||
private String message = null;
|
||||
private Map<String, List<String>> responseHeaders = null;
|
||||
private String responseBody = null;
|
||||
|
||||
public ApiException() {}
|
||||
public ApiException() {}
|
||||
|
||||
public ApiException(int code, String message) {
|
||||
public ApiException(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
public ApiException(int code, String message, Map
|
||||
<String
|
||||
, List
|
||||
<String>> responseHeaders, String responseBody) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.responseHeaders = responseHeaders;
|
||||
this.responseBody = responseBody;
|
||||
}
|
||||
public ApiException(int code, String message, Map<String, List<String>> responseHeaders, String responseBody) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.responseHeaders = responseHeaders;
|
||||
this.responseBody = responseBody;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP response headers.
|
||||
*/
|
||||
public Map
|
||||
<String
|
||||
, List
|
||||
<String>> getResponseHeaders() {
|
||||
return responseHeaders;
|
||||
}
|
||||
/**
|
||||
* Get the HTTP response headers.
|
||||
*/
|
||||
public Map<String, List<String>> getResponseHeaders() {
|
||||
return responseHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTTP response body.
|
||||
*/
|
||||
public String getResponseBody() {
|
||||
return responseBody;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the HTTP response body.
|
||||
*/
|
||||
public String getResponseBody() {
|
||||
return responseBody;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,55 +3,53 @@ package {{invokerPackage}}.auth;
|
||||
import java.util.Map;
|
||||
|
||||
public class ApiKeyAuth implements Authentication {
|
||||
private final String location;
|
||||
private final String paramName;
|
||||
private final String location;
|
||||
private final String paramName;
|
||||
|
||||
private String apiKey;
|
||||
private String apiKeyPrefix;
|
||||
private String apiKey;
|
||||
private String apiKeyPrefix;
|
||||
|
||||
public ApiKeyAuth(String location, String paramName) {
|
||||
this.location = location;
|
||||
this.paramName = paramName;
|
||||
}
|
||||
public ApiKeyAuth(String location, String paramName) {
|
||||
this.location = location;
|
||||
this.paramName = paramName;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public String getParamName() {
|
||||
return paramName;
|
||||
}
|
||||
public String getParamName() {
|
||||
return paramName;
|
||||
}
|
||||
|
||||
public String getApiKey() {
|
||||
return apiKey;
|
||||
}
|
||||
public String getApiKey() {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
public void setApiKey(String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
public void setApiKey(String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
public String getApiKeyPrefix() {
|
||||
return apiKeyPrefix;
|
||||
}
|
||||
public String getApiKeyPrefix() {
|
||||
return apiKeyPrefix;
|
||||
}
|
||||
|
||||
public void setApiKeyPrefix(String apiKeyPrefix) {
|
||||
this.apiKeyPrefix = apiKeyPrefix;
|
||||
}
|
||||
public void setApiKeyPrefix(String apiKeyPrefix) {
|
||||
this.apiKeyPrefix = apiKeyPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(Map
|
||||
<String, String> queryParams, Map
|
||||
<String, String> headerParams) {
|
||||
String value;
|
||||
if (apiKeyPrefix != null) {
|
||||
value = apiKeyPrefix + " " + apiKey;
|
||||
} else {
|
||||
value = apiKey;
|
||||
}
|
||||
if (location == "query") {
|
||||
queryParams.put(paramName, value);
|
||||
} else if (location == "header") {
|
||||
headerParams.put(paramName, value);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
String value;
|
||||
if (apiKeyPrefix != null) {
|
||||
value = apiKeyPrefix + " " + apiKey;
|
||||
} else {
|
||||
value = apiKey;
|
||||
}
|
||||
if (location == "query") {
|
||||
queryParams.put(paramName, value);
|
||||
} else if (location == "header") {
|
||||
headerParams.put(paramName, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package {{invokerPackage}}.auth;
|
||||
import java.util.Map;
|
||||
|
||||
public interface Authentication {
|
||||
/** Apply authentication settings to header and query params. */
|
||||
void applyToParams(Map
|
||||
<String, String> queryParams, Map
|
||||
<String, String> headerParams);
|
||||
/** Apply authentication settings to header and query params. */
|
||||
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams);
|
||||
}
|
||||
|
||||
@@ -6,34 +6,32 @@ import java.io.UnsupportedEncodingException;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
public class HttpBasicAuth implements Authentication {
|
||||
private String username;
|
||||
private String password;
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(Map
|
||||
<String, String> queryParams, Map
|
||||
<String, String> headerParams) {
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
try {
|
||||
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
try {
|
||||
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,8 @@ package {{invokerPackage}}.auth;
|
||||
import java.util.Map;
|
||||
|
||||
public class OAuth implements Authentication {
|
||||
@Override
|
||||
public void applyToParams(Map
|
||||
<String, String> queryParams, Map
|
||||
<String, String> headerParams) {
|
||||
// TODO: support oauth
|
||||
}
|
||||
@Override
|
||||
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
// TODO: support oauth
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,45 +7,45 @@ import io.swagger.annotations.*;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
{{#models}}
|
||||
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||
};
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||
};
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
@JsonProperty("{{baseName}}")
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
@JsonProperty("{{baseName}}")
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
|
||||
{{/vars}}
|
||||
{{/vars}}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#parent}}sb.append(" " + super.toString()).append("\n");{{/parent}}
|
||||
{{#vars}}sb.append(" {{name}}: ").append({{name}}).append("\n");
|
||||
{{/vars}}sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
@@ -1,170 +1,167 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:swagger-api/swagger-mustache.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
|
||||
<url>https://github.com/swagger-api/swagger-codegen</url>
|
||||
</scm>
|
||||
<prerequisites>
|
||||
<maven>2.2.0</maven>
|
||||
</prerequisites>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:swagger-api/swagger-mustache.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
|
||||
<url>https://github.com/swagger-api/swagger-codegen</url>
|
||||
</scm>
|
||||
<prerequisites>
|
||||
<maven>2.2.0</maven>
|
||||
</prerequisites>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12</version>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>loggerPath</name>
|
||||
<value>conf/log4j.properties</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
<argLine>-Xms512m -Xmx1500m</argLine>
|
||||
<parallel>methods</parallel>
|
||||
<forkMode>pertest</forkMode>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12</version>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>loggerPath</name>
|
||||
<value>conf/log4j.properties</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
<argLine>-Xms512m -Xmx1500m</argLine>
|
||||
<parallel>methods</parallel>
|
||||
<forkMode>pertest</forkMode>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- attach test jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- attach test jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add_sources</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>
|
||||
src/main/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>add_test_sources</id>
|
||||
<phase>generate-test-sources</phase>
|
||||
<goals>
|
||||
<goal>add-test-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>
|
||||
src/test/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>
|
||||
1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey.contribs</groupId>
|
||||
<artifactId>jersey-multipart</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
<version>2.1.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${jodatime-version}</version>
|
||||
</dependency>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add_sources</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/main/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>add_test_sources</id>
|
||||
<phase>generate-test-sources</phase>
|
||||
<goals>
|
||||
<goal>add-test-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/test/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey.contribs</groupId>
|
||||
<artifactId>jersey-multipart</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-joda</artifactId>
|
||||
<version>2.1.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${jodatime-version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
||||
<jersey-version>1.18</jersey-version>
|
||||
<jackson-version>2.4.2</jackson-version>
|
||||
<jodatime-version>2.3</jodatime-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
</properties>
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
||||
<jersey-version>1.18</jersey-version>
|
||||
<jackson-version>2.4.2</jackson-version>
|
||||
<jodatime-version>2.3</jodatime-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
</properties>
|
||||
</project>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,21 +6,21 @@ import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
}
|
||||
@@ -4,65 +4,65 @@ import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
public class NotFoundException extends ApiException {
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Swagger generated server
|
||||
|
||||
## Overview
|
||||
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
|
||||
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
|
||||
[swagger-spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
|
||||
is an example of building a swagger-enabled scalatra server.
|
||||
|
||||
|
||||
@@ -27,26 +27,26 @@ import javax.ws.rs.*;
|
||||
{{#hasProduces}}@Produces({ {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}}
|
||||
@io.swagger.annotations.Api(value = "/{{baseName}}", description = "the {{baseName}} API")
|
||||
{{#operations}}
|
||||
public class {{classname}} {
|
||||
public class {{classname}} {
|
||||
|
||||
private final {{classname}}Service delegate = {{classname}}ServiceFactory.get{{classname}}();
|
||||
private final {{classname}}Service delegate = {{classname}}ServiceFactory.get{{classname}}();
|
||||
|
||||
{{#operation}}
|
||||
@{{httpMethod}}
|
||||
{{#subresourceOperation}}@Path("{{path}}"){{/subresourceOperation}}
|
||||
{{#hasConsumes}}@Consumes({ {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}
|
||||
{{#hasProduces}}@Produces({ {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}}
|
||||
@io.swagger.annotations.ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}})
|
||||
@io.swagger.annotations.ApiResponses(value = { {{#responses}}
|
||||
@io.swagger.annotations.ApiResponse(code = {{{code}}}, message = "{{{message}}}"){{#hasMore}},
|
||||
{{/hasMore}}{{/responses}} })
|
||||
{{#operation}}
|
||||
@{{httpMethod}}
|
||||
{{#subresourceOperation}}@Path("{{path}}"){{/subresourceOperation}}
|
||||
{{#hasConsumes}}@Consumes({ {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}
|
||||
{{#hasProduces}}@Produces({ {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}}
|
||||
@io.swagger.annotations.ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}})
|
||||
@io.swagger.annotations.ApiResponses(value = { {{#responses}}
|
||||
@io.swagger.annotations.ApiResponse(code = {{{code}}}, message = "{{{message}}}"){{#hasMore}},
|
||||
{{/hasMore}}{{/responses}} })
|
||||
|
||||
public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},
|
||||
{{/hasMore}}{{/allParams}})
|
||||
throws NotFoundException {
|
||||
return delegate.{{nickname}}({{#allParams}}{{#isFile}}fileDetail{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}}{{#hasMore}},{{/hasMore}}{{/allParams}});
|
||||
}
|
||||
{{/operation}}
|
||||
public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},
|
||||
{{/hasMore}}{{/allParams}})
|
||||
throws NotFoundException {
|
||||
return delegate.{{nickname}}({{#allParams}}{{#isFile}}fileDetail{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}}{{#hasMore}},{{/hasMore}}{{/allParams}});
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ import com.sun.jersey.multipart.FormDataParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
{{#operations}}
|
||||
public abstract class {{classname}}Service {
|
||||
{{#operation}}
|
||||
public abstract Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}}{{#hasMore}},{{/hasMore}}{{/allParams}})
|
||||
throws NotFoundException;
|
||||
{{/operation}}
|
||||
}
|
||||
public abstract class {{classname}}Service {
|
||||
{{#operation}}
|
||||
public abstract Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}}{{#hasMore}},{{/hasMore}}{{/allParams}})
|
||||
throws NotFoundException;
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
|
||||
@@ -5,10 +5,10 @@ import {{package}}.impl.{{classname}}ServiceImpl;
|
||||
|
||||
public class {{classname}}ServiceFactory {
|
||||
|
||||
private final static {{classname}}Service service = new {{classname}}ServiceImpl();
|
||||
private final static {{classname}}Service service = new {{classname}}ServiceImpl();
|
||||
|
||||
public static {{classname}}Service get{{classname}}()
|
||||
{
|
||||
return service;
|
||||
}
|
||||
public static {{classname}}Service get{{classname}}()
|
||||
{
|
||||
return service;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@ import com.sun.jersey.multipart.FormDataParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
{{#operations}}
|
||||
public class {{classname}}ServiceImpl extends {{classname}}Service {
|
||||
{{#operation}}
|
||||
@Override
|
||||
public Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}}{{#hasMore}},{{/hasMore}}{{/allParams}})
|
||||
throws NotFoundException {
|
||||
// do some magic!
|
||||
return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
public class {{classname}}ServiceImpl extends {{classname}}Service {
|
||||
{{#operation}}
|
||||
@Override
|
||||
public Response {{nickname}}({{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{>serviceFormParams}}{{#hasMore}},{{/hasMore}}{{/allParams}})
|
||||
throws NotFoundException {
|
||||
// do some magic!
|
||||
return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
{{#isFormParam}}{{#notFile}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}})@FormParam("{{paramName}}") {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}@ApiParam(value = "{{{description}}}") @FormDataParam("file") InputStream inputStream,
|
||||
@ApiParam(value = "file detail") @FormDataParam("file") FormDataContentDisposition fileDetail{{/isFile}}{{/isFormParam}}
|
||||
@ApiParam(value = "file detail") @FormDataParam("file") FormDataContentDisposition fileDetail{{/isFile}}{{/isFormParam}}
|
||||
@@ -7,45 +7,45 @@ import io.swagger.annotations.*;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
{{#models}}
|
||||
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||
};
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||
};
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
@JsonProperty("{{name}}")
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
@JsonProperty("{{name}}")
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
|
||||
{{/vars}}
|
||||
{{/vars}}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#parent}}sb.append(" " + super.toString()).append("\n");{{/parent}}
|
||||
{{#vars}}sb.append(" {{name}}: ").append({{name}}).append("\n");
|
||||
{{/vars}}sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
@@ -1,161 +1,159 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.1.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
<configuration>
|
||||
<webApp>
|
||||
<contextPath>/</contextPath>
|
||||
</webApp>
|
||||
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
|
||||
<stopPort>8079</stopPort>
|
||||
<stopKey>stopit</stopKey>
|
||||
<httpConnector>
|
||||
<port>8080</port>
|
||||
<idleTimeout>60000</idleTimeout>
|
||||
</httpConnector>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-jetty</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>start</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||
<daemon>true</daemon>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop-jetty</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>stop</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>1.9.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-source</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>
|
||||
src/gen/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-jersey-jaxrs</artifactId>
|
||||
<version>${swagger-core-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-core</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-json</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-servlet</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey.contribs</groupId>
|
||||
<artifactId>jersey-multipart</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-server</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.1.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
<configuration>
|
||||
<webApp>
|
||||
<contextPath>/</contextPath>
|
||||
</webApp>
|
||||
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
|
||||
<stopPort>8079</stopPort>
|
||||
<stopKey>stopit</stopKey>
|
||||
<httpConnector>
|
||||
<port>8080</port>
|
||||
<idleTimeout>60000</idleTimeout>
|
||||
</httpConnector>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-jetty</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>start</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||
<daemon>true</daemon>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop-jetty</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>stop</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>1.9.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-source</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/gen/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-jersey-jaxrs</artifactId>
|
||||
<version>${swagger-core-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-core</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-json</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-servlet</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey.contribs</groupId>
|
||||
<artifactId>jersey-multipart</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-server</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.scalatest</groupId>
|
||||
<artifactId>scalatest_2.9.1</artifactId>
|
||||
<version>${scala-test-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>${servlet-api-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-core-version>1.5.0</swagger-core-version>
|
||||
<jetty-version>9.2.9.v20150224</jetty-version>
|
||||
<jersey-version>1.13</jersey-version>
|
||||
<slf4j-version>1.6.3</slf4j-version>
|
||||
<scala-test-version>1.6.1</scala-test-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
</properties>
|
||||
<dependency>
|
||||
<groupId>org.scalatest</groupId>
|
||||
<artifactId>scalatest_2.9.1</artifactId>
|
||||
<version>${scala-test-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>${servlet-api-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-core-version>1.5.0</swagger-core-version>
|
||||
<jetty-version>9.2.9.v20150224</jetty-version>
|
||||
<jersey-version>1.13</jersey-version>
|
||||
<slf4j-version>1.6.3</slf4j-version>
|
||||
<scala-test-version>1.6.1</scala-test-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
</properties>
|
||||
</project>
|
||||
@@ -1,54 +1,54 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
>
|
||||
xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
|
||||
|
||||
<servlet>
|
||||
<servlet-name>jersey</servlet-name>
|
||||
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
|
||||
<init-param>
|
||||
<param-name>com.sun.jersey.config.property.packages</param-name>
|
||||
<param-value>io.swagger.jaxrs.json;io.swagger.jaxrs.listing;{{apiPackage}}</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
|
||||
<param-value>com.sun.jersey.api.container.filter.PostReplaceFilter</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet>
|
||||
<servlet-name>jersey</servlet-name>
|
||||
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
|
||||
<init-param>
|
||||
<param-name>com.sun.jersey.config.property.packages</param-name>
|
||||
<param-value>io.swagger.jaxrs.json;io.swagger.jaxrs.listing;{{apiPackage}}</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
|
||||
<param-value>com.sun.jersey.api.container.filter.PostReplaceFilter</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>DefaultJaxrsConfig</servlet-name>
|
||||
<servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
|
||||
<init-param>
|
||||
<param-name>api.version</param-name>
|
||||
<param-value>1.0.0</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>swagger.api.title</param-name>
|
||||
<param-value>{{{title}}}</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>swagger.api.basepath</param-name>
|
||||
<param-value>http://localhost:8080</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>2</load-on-startup>
|
||||
</servlet>
|
||||
<servlet>
|
||||
<servlet-name>DefaultJaxrsConfig</servlet-name>
|
||||
<servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
|
||||
<init-param>
|
||||
<param-name>api.version</param-name>
|
||||
<param-value>1.0.0</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>swagger.api.title</param-name>
|
||||
<param-value>{{{title}}}</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>swagger.api.basepath</param-name>
|
||||
<param-value>http://localhost:8080</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>2</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>jersey</servlet-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
<filter>
|
||||
<filter-name>ApiOriginFilter</filter-name>
|
||||
<filter-class>{{apiPackage}}.ApiOriginFilter</filter-class>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>ApiOriginFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>jersey</servlet-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
<filter>
|
||||
<filter-name>ApiOriginFilter</filter-name>
|
||||
<filter-class>{{apiPackage}}.ApiOriginFilter</filter-class>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>ApiOriginFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
</web-app>
|
||||
|
||||
@@ -31,23 +31,23 @@ import static org.springframework.http.MediaType.*;
|
||||
@RequestMapping(value = "/{{baseName}}", produces = {APPLICATION_JSON_VALUE})
|
||||
@Api(value = "/{{baseName}}", description = "the {{baseName}} API")
|
||||
{{#operations}}
|
||||
public class {{classname}} {
|
||||
{{#operation}}
|
||||
public class {{classname}} {
|
||||
{{#operation}}
|
||||
|
||||
@ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}})
|
||||
@ApiResponses(value = { {{#responses}}
|
||||
@ApiResponse(code = {{{code}}}, message = "{{{message}}}"){{#hasMore}},{{/hasMore}}{{/responses}} })
|
||||
@RequestMapping(value = "{{path}}",
|
||||
{{#hasProduces}}produces = { {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}
|
||||
{{#hasConsumes}}consumes = { {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}
|
||||
method = RequestMethod.{{httpMethod}})
|
||||
public ResponseEntity<{{returnType}}> {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},
|
||||
{{/hasMore}}{{/allParams}})
|
||||
throws NotFoundException {
|
||||
// do some magic!
|
||||
return new ResponseEntity<{{returnType}}>(HttpStatus.OK);
|
||||
}
|
||||
@ApiOperation(value = "{{{summary}}}", notes = "{{{notes}}}", response = {{{returnType}}}.class{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}})
|
||||
@ApiResponses(value = { {{#responses}}
|
||||
@ApiResponse(code = {{{code}}}, message = "{{{message}}}"){{#hasMore}},{{/hasMore}}{{/responses}} })
|
||||
@RequestMapping(value = "{{path}}",
|
||||
{{#hasProduces}}produces = { {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }, {{/hasProduces}}
|
||||
{{#hasConsumes}}consumes = { {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} },{{/hasConsumes}}
|
||||
method = RequestMethod.{{httpMethod}})
|
||||
public ResponseEntity<{{returnType}}> {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},
|
||||
{{/hasMore}}{{/allParams}})
|
||||
throws NotFoundException {
|
||||
// do some magic!
|
||||
return new ResponseEntity<{{returnType}}>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
public class ApiException extends Exception{
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
private int code;
|
||||
public ApiException (int code, String msg) {
|
||||
super(msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,21 +6,21 @@ import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class ApiOriginFilter implements javax.servlet.Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
HttpServletResponse res = (HttpServletResponse) response;
|
||||
res.addHeader("Access-Control-Allow-Origin", "*");
|
||||
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
|
||||
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
|
||||
chain.doFilter(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
}
|
||||
@@ -4,65 +4,65 @@ import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
@javax.xml.bind.annotation.XmlRootElement
|
||||
public class ApiResponseMessage {
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
public static final int ERROR = 1;
|
||||
public static final int WARNING = 2;
|
||||
public static final int INFO = 3;
|
||||
public static final int OK = 4;
|
||||
public static final int TOO_BUSY = 5;
|
||||
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
int code;
|
||||
String type;
|
||||
String message;
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public ApiResponseMessage(){}
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public ApiResponseMessage(int code, String message){
|
||||
this.code = code;
|
||||
switch(code){
|
||||
case ERROR:
|
||||
setType("error");
|
||||
break;
|
||||
case WARNING:
|
||||
setType("warning");
|
||||
break;
|
||||
case INFO:
|
||||
setType("info");
|
||||
break;
|
||||
case OK:
|
||||
setType("ok");
|
||||
break;
|
||||
case TOO_BUSY:
|
||||
setType("too busy");
|
||||
break;
|
||||
default:
|
||||
setType("unknown");
|
||||
break;
|
||||
}
|
||||
this.message = message;
|
||||
}
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@XmlTransient
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
{{#isFormParam}}{{#notFile}}
|
||||
@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @RequestPart(value="{{paramName}}"{{#required}}, required=true{{/required}}{{^required}}, required=false{{/required}}) {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}@ApiParam(value = "file detail") @RequestPart("file") MultipartFile fileDetail{{/isFile}}{{/isFormParam}}
|
||||
@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}} {{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue="{{{defaultValue}}}"{{/defaultValue}}) @RequestPart(value="{{paramName}}"{{#required}}, required=true{{/required}}{{^required}}, required=false{{/required}}) {{{dataType}}} {{paramName}}{{/notFile}}{{#isFile}}@ApiParam(value = "file detail") @RequestPart("file") MultipartFile fileDetail{{/isFile}}{{/isFormParam}}
|
||||
@@ -7,45 +7,45 @@ import io.swagger.annotations.*;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
{{#models}}
|
||||
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||
};
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||
};
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
@JsonProperty("{{name}}")
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
@JsonProperty("{{name}}")
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
|
||||
{{/vars}}
|
||||
{{/vars}}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#parent}}sb.append(" " + super.toString()).append("\n");{{/parent}}
|
||||
{{#vars}}sb.append(" {{name}}: ").append({{name}}).append("\n");
|
||||
{{/vars}}sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
public class NotFoundException extends ApiException {
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
private int code;
|
||||
public NotFoundException (int code, String msg) {
|
||||
super(code, msg);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,232 +1,229 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.1.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
<configuration>
|
||||
<webAppConfig>
|
||||
<contextPath>{{^contextPath}}
|
||||
/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}</contextPath>
|
||||
</webAppConfig>
|
||||
<webAppSourceDirectory>target/${project.artifactId}-${project-version}</webAppSourceDirectory>
|
||||
<webDefaultXml>${project.basedir}/conf/jetty/webdefault.xml</webDefaultXml>
|
||||
<stopPort>8079</stopPort>
|
||||
<stopKey>stopit</stopKey>
|
||||
<httpConnector>
|
||||
<port>8002</port>
|
||||
<idleTimeout>60000</idleTimeout>
|
||||
</httpConnector>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-jetty</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>start</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||
<daemon>true</daemon>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop-jetty</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>stop</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.googlecode.maven-download-plugin</groupId>
|
||||
<artifactId>download-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>swagger-ui</id>
|
||||
<goals>
|
||||
<goal>wget</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<url>https://github.com/swagger-api/swagger-ui/archive/v${swagger-ui-version}.tar.gz</url>
|
||||
<unpack>true</unpack>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-resources</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>target/${project.artifactId}-${project.version}</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.build.directory}/swagger-ui-${swagger-ui-version}/dist
|
||||
</directory>
|
||||
<filtering>true</filtering>
|
||||
<excludes>
|
||||
<exclude>index.html</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-jersey-jaxrs</artifactId>
|
||||
<version>${swagger-core-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-core</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-json</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-servlet</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey.contribs</groupId>
|
||||
<artifactId>jersey-multipart</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-server</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.1.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
<configuration>
|
||||
<webAppConfig>
|
||||
<contextPath>{{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}</contextPath>
|
||||
</webAppConfig>
|
||||
<webAppSourceDirectory>target/${project.artifactId}-${project-version}</webAppSourceDirectory>
|
||||
<webDefaultXml>${project.basedir}/conf/jetty/webdefault.xml</webDefaultXml>
|
||||
<stopPort>8079</stopPort>
|
||||
<stopKey>stopit</stopKey>
|
||||
<httpConnector>
|
||||
<port>8002</port>
|
||||
<idleTimeout>60000</idleTimeout>
|
||||
</httpConnector>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-jetty</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>start</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||
<daemon>true</daemon>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop-jetty</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>stop</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.googlecode.maven-download-plugin</groupId>
|
||||
<artifactId>download-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>swagger-ui</id>
|
||||
<goals>
|
||||
<goal>wget</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<url>https://github.com/swagger-api/swagger-ui/archive/v${swagger-ui-version}.tar.gz</url>
|
||||
<unpack>true</unpack>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-resources</id>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>target/${project.artifactId}-${project.version}</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.build.directory}/swagger-ui-${swagger-ui-version}/dist</directory>
|
||||
<filtering>true</filtering>
|
||||
<excludes>
|
||||
<exclude>index.html</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-jersey-jaxrs</artifactId>
|
||||
<version>${swagger-core-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-core</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-json</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-servlet</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey.contribs</groupId>
|
||||
<artifactId>jersey-multipart</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey</groupId>
|
||||
<artifactId>jersey-server</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--Spring dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
<!--Spring dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--SpringFox dependencies-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-core</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-spi</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-spring-web</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
<!--SpringFox dependencies-->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-core</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-spi</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-spring-web</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${springfox-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.scalatest</groupId>
|
||||
<artifactId>scalatest_2.9.1</artifactId>
|
||||
<version>${scala-test-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>${servlet-api-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jcenter-snapshots</id>
|
||||
<name>jcenter</name>
|
||||
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-core-version>1.5.0</swagger-core-version>
|
||||
<jetty-version>9.2.9.v20150224</jetty-version>
|
||||
<swagger-ui-version>2.1.0-M2</swagger-ui-version>
|
||||
<jersey-version>1.13</jersey-version>
|
||||
<slf4j-version>1.6.3</slf4j-version>
|
||||
<scala-test-version>1.6.1</scala-test-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
<springfox-version>2.0.0-SNAPSHOT</springfox-version>
|
||||
<spring-version>4.0.9.RELEASE</spring-version>
|
||||
</properties>
|
||||
<dependency>
|
||||
<groupId>org.scalatest</groupId>
|
||||
<artifactId>scalatest_2.9.1</artifactId>
|
||||
<version>${scala-test-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>${servlet-api-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jcenter-snapshots</id>
|
||||
<name>jcenter</name>
|
||||
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-core-version>1.5.0</swagger-core-version>
|
||||
<jetty-version>9.2.9.v20150224</jetty-version>
|
||||
<swagger-ui-version>2.1.0-M2</swagger-ui-version>
|
||||
<jersey-version>1.13</jersey-version>
|
||||
<slf4j-version>1.6.3</slf4j-version>
|
||||
<scala-test-version>1.6.1</scala-test-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
<springfox-version>2.0.0-SNAPSHOT</springfox-version>
|
||||
<spring-version>4.0.9.RELEASE</spring-version>
|
||||
</properties>
|
||||
</project>
|
||||
@@ -19,22 +19,22 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
@PropertySource("classpath:swagger.properties")
|
||||
@Import(SwaggerUiConfiguration.class)
|
||||
public class SwaggerConfig {
|
||||
@Bean
|
||||
ApiInfo apiInfo() {
|
||||
ApiInfo apiInfo = new ApiInfo(
|
||||
"{{appName}}",
|
||||
"{{{appDescription}}}",
|
||||
"{{appVersion}}",
|
||||
"{{infoUrl}}",
|
||||
"{{infoEmail}}",
|
||||
"{{licenseInfo}}",
|
||||
"{{licenseUrl}}" );
|
||||
return apiInfo;
|
||||
}
|
||||
@Bean
|
||||
ApiInfo apiInfo() {
|
||||
ApiInfo apiInfo = new ApiInfo(
|
||||
"{{appName}}",
|
||||
"{{{appDescription}}}",
|
||||
"{{appVersion}}",
|
||||
"{{infoUrl}}",
|
||||
"{{infoEmail}}",
|
||||
"{{licenseInfo}}",
|
||||
"{{licenseUrl}}" );
|
||||
return apiInfo;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket customImplementation(){
|
||||
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
|
||||
}
|
||||
@Bean
|
||||
public Docket customImplementation(){
|
||||
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,38 +9,38 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
public class SwaggerUiConfiguration extends WebMvcConfigurerAdapter {
|
||||
private static final String[] SERVLET_RESOURCE_LOCATIONS = { "/" };
|
||||
private static final String[] SERVLET_RESOURCE_LOCATIONS = { "/" };
|
||||
|
||||
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
|
||||
"classpath:/META-INF/resources/", "classpath:/resources/",
|
||||
"classpath:/static/", "classpath:/public/" };
|
||||
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
|
||||
"classpath:/META-INF/resources/", "classpath:/resources/",
|
||||
"classpath:/static/", "classpath:/public/" };
|
||||
|
||||
private static final String[] RESOURCE_LOCATIONS;
|
||||
static {
|
||||
RESOURCE_LOCATIONS = new String[CLASSPATH_RESOURCE_LOCATIONS.length
|
||||
+ SERVLET_RESOURCE_LOCATIONS.length];
|
||||
System.arraycopy(SERVLET_RESOURCE_LOCATIONS, 0, RESOURCE_LOCATIONS, 0,
|
||||
SERVLET_RESOURCE_LOCATIONS.length);
|
||||
System.arraycopy(CLASSPATH_RESOURCE_LOCATIONS, 0, RESOURCE_LOCATIONS,
|
||||
SERVLET_RESOURCE_LOCATIONS.length, CLASSPATH_RESOURCE_LOCATIONS.length);
|
||||
}
|
||||
private static final String[] RESOURCE_LOCATIONS;
|
||||
static {
|
||||
RESOURCE_LOCATIONS = new String[CLASSPATH_RESOURCE_LOCATIONS.length
|
||||
+ SERVLET_RESOURCE_LOCATIONS.length];
|
||||
System.arraycopy(SERVLET_RESOURCE_LOCATIONS, 0, RESOURCE_LOCATIONS, 0,
|
||||
SERVLET_RESOURCE_LOCATIONS.length);
|
||||
System.arraycopy(CLASSPATH_RESOURCE_LOCATIONS, 0, RESOURCE_LOCATIONS,
|
||||
SERVLET_RESOURCE_LOCATIONS.length, CLASSPATH_RESOURCE_LOCATIONS.length);
|
||||
}
|
||||
|
||||
private static final String[] STATIC_INDEX_HTML_RESOURCES;
|
||||
static {
|
||||
STATIC_INDEX_HTML_RESOURCES = new String[RESOURCE_LOCATIONS.length];
|
||||
for (int i = 0; i < STATIC_INDEX_HTML_RESOURCES.length; i++) {
|
||||
STATIC_INDEX_HTML_RESOURCES[i] = RESOURCE_LOCATIONS[i] + "index.html";
|
||||
}
|
||||
}
|
||||
private static final String[] STATIC_INDEX_HTML_RESOURCES;
|
||||
static {
|
||||
STATIC_INDEX_HTML_RESOURCES = new String[RESOURCE_LOCATIONS.length];
|
||||
for (int i = 0; i < STATIC_INDEX_HTML_RESOURCES.length; i++) {
|
||||
STATIC_INDEX_HTML_RESOURCES[i] = RESOURCE_LOCATIONS[i] + "index.html";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
if (!registry.hasMappingForPattern("/webjars/**")) {
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
if (!registry.hasMappingForPattern("/**")) {
|
||||
registry.addResourceHandler("/**").addResourceLocations(RESOURCE_LOCATIONS);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
if (!registry.hasMappingForPattern("/webjars/**")) {
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
if (!registry.hasMappingForPattern("/**")) {
|
||||
registry.addResourceHandler("/**").addResourceLocations(RESOURCE_LOCATIONS);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,18 +4,18 @@ import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatche
|
||||
|
||||
public class WebApplication extends AbstractAnnotationConfigDispatcherServletInitializer {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getRootConfigClasses() {
|
||||
return new Class[] { SwaggerConfig.class };
|
||||
}
|
||||
@Override
|
||||
protected Class<?>[] getRootConfigClasses() {
|
||||
return new Class[] { SwaggerConfig.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getServletConfigClasses() {
|
||||
return new Class<?>[] { WebMvcConfiguration.class };
|
||||
}
|
||||
@Override
|
||||
protected Class<?>[] getServletConfigClasses() {
|
||||
return new Class<?>[] { WebMvcConfiguration.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getServletMappings() {
|
||||
return new String[] { "/" };
|
||||
}
|
||||
@Override
|
||||
protected String[] getServletMappings() {
|
||||
return new String[] { "/" };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import org.springframework.web.servlet.config.annotation.DefaultServletHandlerCo
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
|
||||
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||
@Override
|
||||
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
|
||||
configurer.enable();
|
||||
}
|
||||
@Override
|
||||
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
|
||||
configurer.enable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,103 +18,97 @@ import java.util.HashMap;
|
||||
import java.io.File;
|
||||
|
||||
{{#operations}}
|
||||
public class {{classname}} {
|
||||
String basePath = "{{basePath}}";
|
||||
ApiInvoker apiInvoker = ApiInvoker.getInstance();
|
||||
public class {{classname}} {
|
||||
String basePath = "{{basePath}}";
|
||||
ApiInvoker apiInvoker = ApiInvoker.getInstance();
|
||||
|
||||
public void addHeader(String key, String value) {
|
||||
public void addHeader(String key, String value) {
|
||||
getInvoker().addDefaultHeader(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public ApiInvoker getInvoker() {
|
||||
public ApiInvoker getInvoker() {
|
||||
return apiInvoker;
|
||||
}
|
||||
}
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
}
|
||||
|
||||
public String getBasePath() {
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{summary}}
|
||||
* {{notes}}
|
||||
{{#allParams}} * @param {{paramName}} {{description}}
|
||||
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||
*/
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if ({{paramName}} == null) {
|
||||
throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{nickname}}");
|
||||
}
|
||||
{{/required}}{{/allParams}}
|
||||
|
||||
// create path and map variables
|
||||
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{paramName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
// header params
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
// form params
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
{{#queryParams}}if ({{paramName}} != null)
|
||||
queryParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));
|
||||
{{/queryParams}}
|
||||
|
||||
{{#headerParams}}headerParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));
|
||||
{{/headerParams}}
|
||||
|
||||
String[] contentTypes = {
|
||||
{{#consumes}}"{{mediaType}}"{{#hasMore}},{{/hasMore}}{{/consumes}}
|
||||
};
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
|
||||
if (contentType.startsWith("multipart/form-data")) {
|
||||
// file uploading
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||
{{#formParams}}{{#notFile}}
|
||||
if ({{paramName}} != null) {
|
||||
builder.addTextBody("{{baseName}}", ApiInvoker.parameterToString({{paramName}}), ApiInvoker.TEXT_PLAIN_UTF8);
|
||||
}
|
||||
{{/notFile}}{{#isFile}}
|
||||
if ({{paramName}} != null) {
|
||||
builder.addBinaryBody("{{baseName}}", {{paramName}});
|
||||
}
|
||||
{{/isFile}}{{/formParams}}
|
||||
|
||||
HttpEntity httpEntity = builder.build();
|
||||
postBody = httpEntity;
|
||||
} else {
|
||||
// normal form params
|
||||
{{#formParams}}{{#notFile}}formParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));{{/notFile}}
|
||||
{{/formParams}}
|
||||
}
|
||||
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{summary}}
|
||||
* {{notes}}
|
||||
{{#allParams}} * @param {{paramName}} {{description}}
|
||||
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||
*/
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if ({{paramName}} == null) {
|
||||
throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{nickname}}");
|
||||
}
|
||||
{{/required}}{{/allParams}}
|
||||
|
||||
// create path and map variables
|
||||
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{paramName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||
|
||||
// query params
|
||||
Map
|
||||
<String, String> queryParams = new HashMap
|
||||
<String, String>();
|
||||
// header params
|
||||
Map
|
||||
<String, String> headerParams = new HashMap
|
||||
<String, String>();
|
||||
// form params
|
||||
Map
|
||||
<String, String> formParams = new HashMap
|
||||
<String, String>();
|
||||
|
||||
{{#queryParams}}if ({{paramName}} != null)
|
||||
queryParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));
|
||||
{{/queryParams}}
|
||||
|
||||
{{#headerParams}}headerParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));
|
||||
{{/headerParams}}
|
||||
|
||||
String[] contentTypes = {
|
||||
{{#consumes}}"{{mediaType}}"{{#hasMore}},{{/hasMore}}{{/consumes}}
|
||||
};
|
||||
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
|
||||
|
||||
if (contentType.startsWith("multipart/form-data")) {
|
||||
// file uploading
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||
{{#formParams}}{{#notFile}}
|
||||
if ({{paramName}} != null) {
|
||||
builder.addTextBody("{{baseName}}", ApiInvoker.parameterToString({{paramName}}), ApiInvoker.TEXT_PLAIN_UTF8);
|
||||
}
|
||||
{{/notFile}}{{#isFile}}
|
||||
if ({{paramName}} != null) {
|
||||
builder.addBinaryBody("{{baseName}}", {{paramName}});
|
||||
}
|
||||
{{/isFile}}{{/formParams}}
|
||||
|
||||
HttpEntity httpEntity = builder.build();
|
||||
postBody = httpEntity;
|
||||
} else {
|
||||
// normal form params
|
||||
{{#formParams}}{{#notFile}}formParams.put("{{baseName}}", ApiInvoker.parameterToString({{paramName}}));{{/notFile}}
|
||||
{{/formParams}}
|
||||
}
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, contentType);
|
||||
if(response != null){
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, contentType);
|
||||
if(response != null){
|
||||
return {{#returnType}}({{{returnType}}}) ApiInvoker.deserialize(response, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}};
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
return {{#returnType}}null{{/returnType}};
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
package {{invokerPackage}};
|
||||
|
||||
public class ApiException extends Exception {
|
||||
int code = 0;
|
||||
String message = null;
|
||||
int code = 0;
|
||||
String message = null;
|
||||
|
||||
public ApiException() {}
|
||||
public ApiException() {}
|
||||
|
||||
public ApiException(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
public ApiException(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -52,345 +52,338 @@ import javax.net.ssl.X509TrustManager;
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
public class ApiInvoker {
|
||||
private static ApiInvoker INSTANCE = new ApiInvoker();
|
||||
private Map
|
||||
<String, String> defaultHeaderMap = new HashMap
|
||||
<String, String>();
|
||||
private static ApiInvoker INSTANCE = new ApiInvoker();
|
||||
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
|
||||
private HttpClient client = null;
|
||||
private HttpClient client = null;
|
||||
|
||||
private boolean ignoreSSLCertificates = false;
|
||||
private boolean ignoreSSLCertificates = false;
|
||||
|
||||
private ClientConnectionManager ignoreSSLConnectionManager;
|
||||
private ClientConnectionManager ignoreSSLConnectionManager;
|
||||
|
||||
/** Content type "text/plain" with UTF-8 encoding. */
|
||||
public static final ContentType TEXT_PLAIN_UTF8 = ContentType.create("text/plain", Consts.UTF_8);
|
||||
/** Content type "text/plain" with UTF-8 encoding. */
|
||||
public static final ContentType TEXT_PLAIN_UTF8 = ContentType.create("text/plain", Consts.UTF_8);
|
||||
|
||||
/**
|
||||
* ISO 8601 date time format.
|
||||
* @see https://en.wikipedia.org/wiki/ISO_8601
|
||||
*/
|
||||
public static final SimpleDateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
/**
|
||||
* ISO 8601 date time format.
|
||||
* @see https://en.wikipedia.org/wiki/ISO_8601
|
||||
*/
|
||||
public static final SimpleDateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
|
||||
/**
|
||||
* ISO 8601 date format.
|
||||
* @see https://en.wikipedia.org/wiki/ISO_8601
|
||||
*/
|
||||
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
|
||||
/**
|
||||
* ISO 8601 date format.
|
||||
* @see https://en.wikipedia.org/wiki/ISO_8601
|
||||
*/
|
||||
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
static {
|
||||
// Use UTC as the default time zone.
|
||||
DATE_TIME_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
static {
|
||||
// Use UTC as the default time zone.
|
||||
DATE_TIME_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
// Set default User-Agent.
|
||||
setUserAgent("Android-Java-Swagger");
|
||||
}
|
||||
// Set default User-Agent.
|
||||
setUserAgent("Android-Java-Swagger");
|
||||
}
|
||||
|
||||
public static void setUserAgent(String userAgent) {
|
||||
INSTANCE.addDefaultHeader("User-Agent", userAgent);
|
||||
}
|
||||
public static void setUserAgent(String userAgent) {
|
||||
INSTANCE.addDefaultHeader("User-Agent", userAgent);
|
||||
}
|
||||
|
||||
public static Date parseDateTime(String str) {
|
||||
try {
|
||||
return DATE_TIME_FORMAT.parse(str);
|
||||
} catch (java.text.ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public static Date parseDateTime(String str) {
|
||||
try {
|
||||
return DATE_TIME_FORMAT.parse(str);
|
||||
} catch (java.text.ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Date parseDate(String str) {
|
||||
try {
|
||||
return DATE_FORMAT.parse(str);
|
||||
} catch (java.text.ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
public static Date parseDate(String str) {
|
||||
try {
|
||||
return DATE_FORMAT.parse(str);
|
||||
} catch (java.text.ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatDateTime(Date datetime) {
|
||||
return DATE_TIME_FORMAT.format(datetime);
|
||||
}
|
||||
public static String formatDateTime(Date datetime) {
|
||||
return DATE_TIME_FORMAT.format(datetime);
|
||||
}
|
||||
|
||||
public static String formatDate(Date date) {
|
||||
return DATE_FORMAT.format(date);
|
||||
}
|
||||
public static String formatDate(Date date) {
|
||||
return DATE_FORMAT.format(date);
|
||||
}
|
||||
|
||||
public static String parameterToString(Object param) {
|
||||
if (param == null) {
|
||||
return "";
|
||||
} else if (param instanceof Date) {
|
||||
return formatDateTime((Date) param);
|
||||
} else if (param instanceof Collection) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(Object o : (Collection)param) {
|
||||
if(b.length() > 0) {
|
||||
b.append(",");
|
||||
}
|
||||
b.append(String.valueOf(o));
|
||||
}
|
||||
return b.toString();
|
||||
} else {
|
||||
return String.valueOf(param);
|
||||
}
|
||||
}
|
||||
public static String parameterToString(Object param) {
|
||||
if (param == null) {
|
||||
return "";
|
||||
} else if (param instanceof Date) {
|
||||
return formatDateTime((Date) param);
|
||||
} else if (param instanceof Collection) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(Object o : (Collection)param) {
|
||||
if(b.length() > 0) {
|
||||
b.append(",");
|
||||
}
|
||||
b.append(String.valueOf(o));
|
||||
}
|
||||
return b.toString();
|
||||
} else {
|
||||
return String.valueOf(param);
|
||||
}
|
||||
}
|
||||
|
||||
public ApiInvoker() {
|
||||
initConnectionManager();
|
||||
}
|
||||
public ApiInvoker() {
|
||||
initConnectionManager();
|
||||
}
|
||||
|
||||
public static ApiInvoker getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
public static ApiInvoker getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void ignoreSSLCertificates(boolean ignoreSSLCertificates) {
|
||||
this.ignoreSSLCertificates = ignoreSSLCertificates;
|
||||
}
|
||||
public void ignoreSSLCertificates(boolean ignoreSSLCertificates) {
|
||||
this.ignoreSSLCertificates = ignoreSSLCertificates;
|
||||
}
|
||||
|
||||
public void addDefaultHeader(String key, String value) {
|
||||
defaultHeaderMap.put(key, value);
|
||||
}
|
||||
public void addDefaultHeader(String key, String value) {
|
||||
defaultHeaderMap.put(key, value);
|
||||
}
|
||||
|
||||
public String escapeString(String str) {
|
||||
return str;
|
||||
}
|
||||
public String escapeString(String str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
||||
try{
|
||||
if("list".equalsIgnoreCase(containerType) || "array".equalsIgnoreCase(containerType)) {
|
||||
return JsonUtil.deserializeToList(json, cls);
|
||||
}
|
||||
else if(String.class.equals(cls)) {
|
||||
if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
|
||||
return json.substring(1, json.length() - 2);
|
||||
else
|
||||
return json;
|
||||
}
|
||||
else {
|
||||
return JsonUtil.deserializeToObject(json, cls);
|
||||
}
|
||||
}
|
||||
catch (JsonParseException e) {
|
||||
throw new ApiException(500, e.getMessage());
|
||||
}
|
||||
}
|
||||
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
||||
try{
|
||||
if("list".equalsIgnoreCase(containerType) || "array".equalsIgnoreCase(containerType)) {
|
||||
return JsonUtil.deserializeToList(json, cls);
|
||||
}
|
||||
else if(String.class.equals(cls)) {
|
||||
if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
|
||||
return json.substring(1, json.length() - 2);
|
||||
else
|
||||
return json;
|
||||
}
|
||||
else {
|
||||
return JsonUtil.deserializeToObject(json, cls);
|
||||
}
|
||||
}
|
||||
catch (JsonParseException e) {
|
||||
throw new ApiException(500, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static String serialize(Object obj) throws ApiException {
|
||||
try {
|
||||
if (obj != null)
|
||||
return JsonUtil.serialize(obj);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ApiException(500, e.getMessage());
|
||||
}
|
||||
}
|
||||
public static String serialize(Object obj) throws ApiException {
|
||||
try {
|
||||
if (obj != null)
|
||||
return JsonUtil.serialize(obj);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ApiException(500, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public String invokeAPI(String host, String path, String method, Map
|
||||
<String, String> queryParams, Object body, Map
|
||||
<String, String> headerParams, Map
|
||||
<String, String> formParams, String contentType) throws ApiException {
|
||||
HttpClient client = getClient(host);
|
||||
public String invokeAPI(String host, String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType) throws ApiException {
|
||||
HttpClient client = getClient(host);
|
||||
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(String key : queryParams.keySet()) {
|
||||
String value = queryParams.get(key);
|
||||
if (value != null){
|
||||
if(b.toString().length() == 0)
|
||||
b.append("?");
|
||||
else
|
||||
b.append("&");
|
||||
b.append(escapeString(key)).append("=").append(escapeString(value));
|
||||
}
|
||||
}
|
||||
String url = host + path + b.toString();
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(String key : queryParams.keySet()) {
|
||||
String value = queryParams.get(key);
|
||||
if (value != null){
|
||||
if(b.toString().length() == 0)
|
||||
b.append("?");
|
||||
else
|
||||
b.append("&");
|
||||
b.append(escapeString(key)).append("=").append(escapeString(value));
|
||||
}
|
||||
}
|
||||
String url = host + path + b.toString();
|
||||
|
||||
HashMap
|
||||
<String, String> headers = new HashMap
|
||||
<String, String>();
|
||||
HashMap<String, String> headers = new HashMap<String, String>();
|
||||
|
||||
for(String key : headerParams.keySet()) {
|
||||
headers.put(key, headerParams.get(key));
|
||||
}
|
||||
for(String key : headerParams.keySet()) {
|
||||
headers.put(key, headerParams.get(key));
|
||||
}
|
||||
|
||||
for(String key : defaultHeaderMap.keySet()) {
|
||||
if(!headerParams.containsKey(key)) {
|
||||
headers.put(key, defaultHeaderMap.get(key));
|
||||
}
|
||||
}
|
||||
headers.put("Accept", "application/json");
|
||||
for(String key : defaultHeaderMap.keySet()) {
|
||||
if(!headerParams.containsKey(key)) {
|
||||
headers.put(key, defaultHeaderMap.get(key));
|
||||
}
|
||||
}
|
||||
headers.put("Accept", "application/json");
|
||||
|
||||
// URL encoded string from form parameters
|
||||
String formParamStr = null;
|
||||
// URL encoded string from form parameters
|
||||
String formParamStr = null;
|
||||
|
||||
// for form data
|
||||
if ("application/x-www-form-urlencoded".equals(contentType)) {
|
||||
StringBuilder formParamBuilder = new StringBuilder();
|
||||
// for form data
|
||||
if ("application/x-www-form-urlencoded".equals(contentType)) {
|
||||
StringBuilder formParamBuilder = new StringBuilder();
|
||||
|
||||
// encode the form params
|
||||
for (String key : formParams.keySet()) {
|
||||
String value = formParams.get(key);
|
||||
if (value != null && !"".equals(value.trim())) {
|
||||
if (formParamBuilder.length() > 0) {
|
||||
formParamBuilder.append("&");
|
||||
}
|
||||
try {
|
||||
formParamBuilder.append(URLEncoder.encode(key, "utf8")).append("=").append(URLEncoder.encode(value, "utf8"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// move on to next
|
||||
}
|
||||
}
|
||||
}
|
||||
formParamStr = formParamBuilder.toString();
|
||||
}
|
||||
// encode the form params
|
||||
for (String key : formParams.keySet()) {
|
||||
String value = formParams.get(key);
|
||||
if (value != null && !"".equals(value.trim())) {
|
||||
if (formParamBuilder.length() > 0) {
|
||||
formParamBuilder.append("&");
|
||||
}
|
||||
try {
|
||||
formParamBuilder.append(URLEncoder.encode(key, "utf8")).append("=").append(URLEncoder.encode(value, "utf8"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// move on to next
|
||||
}
|
||||
}
|
||||
}
|
||||
formParamStr = formParamBuilder.toString();
|
||||
}
|
||||
|
||||
HttpResponse response = null;
|
||||
try {
|
||||
if ("GET".equals(method)) {
|
||||
HttpGet get = new HttpGet(url);
|
||||
get.addHeader("Accept", "application/json");
|
||||
for(String key : headers.keySet()) {
|
||||
get.setHeader(key, headers.get(key));
|
||||
}
|
||||
response = client.execute(get);
|
||||
}
|
||||
else if ("POST".equals(method)) {
|
||||
HttpPost post = new HttpPost(url);
|
||||
if (formParamStr != null) {
|
||||
post.setHeader("Content-Type", contentType);
|
||||
post.setEntity(new StringEntity(formParamStr, "UTF-8"));
|
||||
} else if (body != null) {
|
||||
if (body instanceof HttpEntity) {
|
||||
// this is for file uploading
|
||||
post.setEntity((HttpEntity) body);
|
||||
} else {
|
||||
post.setHeader("Content-Type", contentType);
|
||||
post.setEntity(new StringEntity(serialize(body), "UTF-8"));
|
||||
}
|
||||
}
|
||||
for(String key : headers.keySet()) {
|
||||
post.setHeader(key, headers.get(key));
|
||||
}
|
||||
response = client.execute(post);
|
||||
}
|
||||
else if ("PUT".equals(method)) {
|
||||
HttpPut put = new HttpPut(url);
|
||||
if (formParamStr != null) {
|
||||
put.setHeader("Content-Type", contentType);
|
||||
put.setEntity(new StringEntity(formParamStr, "UTF-8"));
|
||||
} else if (body != null) {
|
||||
put.setHeader("Content-Type", contentType);
|
||||
put.setEntity(new StringEntity(serialize(body), "UTF-8"));
|
||||
}
|
||||
for(String key : headers.keySet()) {
|
||||
put.setHeader(key, headers.get(key));
|
||||
}
|
||||
response = client.execute(put);
|
||||
}
|
||||
else if ("DELETE".equals(method)) {
|
||||
HttpDelete delete = new HttpDelete(url);
|
||||
for(String key : headers.keySet()) {
|
||||
delete.setHeader(key, headers.get(key));
|
||||
}
|
||||
response = client.execute(delete);
|
||||
}
|
||||
else if ("PATCH".equals(method)) {
|
||||
HttpPatch patch = new HttpPatch(url);
|
||||
if (formParamStr != null) {
|
||||
patch.setHeader("Content-Type", contentType);
|
||||
patch.setEntity(new StringEntity(formParamStr, "UTF-8"));
|
||||
} else if (body != null) {
|
||||
patch.setHeader("Content-Type", contentType);
|
||||
patch.setEntity(new StringEntity(serialize(body), "UTF-8"));
|
||||
}
|
||||
for(String key : headers.keySet()) {
|
||||
patch.setHeader(key, headers.get(key));
|
||||
}
|
||||
response = client.execute(patch);
|
||||
}
|
||||
HttpResponse response = null;
|
||||
try {
|
||||
if ("GET".equals(method)) {
|
||||
HttpGet get = new HttpGet(url);
|
||||
get.addHeader("Accept", "application/json");
|
||||
for(String key : headers.keySet()) {
|
||||
get.setHeader(key, headers.get(key));
|
||||
}
|
||||
response = client.execute(get);
|
||||
}
|
||||
else if ("POST".equals(method)) {
|
||||
HttpPost post = new HttpPost(url);
|
||||
if (formParamStr != null) {
|
||||
post.setHeader("Content-Type", contentType);
|
||||
post.setEntity(new StringEntity(formParamStr, "UTF-8"));
|
||||
} else if (body != null) {
|
||||
if (body instanceof HttpEntity) {
|
||||
// this is for file uploading
|
||||
post.setEntity((HttpEntity) body);
|
||||
} else {
|
||||
post.setHeader("Content-Type", contentType);
|
||||
post.setEntity(new StringEntity(serialize(body), "UTF-8"));
|
||||
}
|
||||
}
|
||||
for(String key : headers.keySet()) {
|
||||
post.setHeader(key, headers.get(key));
|
||||
}
|
||||
response = client.execute(post);
|
||||
}
|
||||
else if ("PUT".equals(method)) {
|
||||
HttpPut put = new HttpPut(url);
|
||||
if (formParamStr != null) {
|
||||
put.setHeader("Content-Type", contentType);
|
||||
put.setEntity(new StringEntity(formParamStr, "UTF-8"));
|
||||
} else if (body != null) {
|
||||
put.setHeader("Content-Type", contentType);
|
||||
put.setEntity(new StringEntity(serialize(body), "UTF-8"));
|
||||
}
|
||||
for(String key : headers.keySet()) {
|
||||
put.setHeader(key, headers.get(key));
|
||||
}
|
||||
response = client.execute(put);
|
||||
}
|
||||
else if ("DELETE".equals(method)) {
|
||||
HttpDelete delete = new HttpDelete(url);
|
||||
for(String key : headers.keySet()) {
|
||||
delete.setHeader(key, headers.get(key));
|
||||
}
|
||||
response = client.execute(delete);
|
||||
}
|
||||
else if ("PATCH".equals(method)) {
|
||||
HttpPatch patch = new HttpPatch(url);
|
||||
if (formParamStr != null) {
|
||||
patch.setHeader("Content-Type", contentType);
|
||||
patch.setEntity(new StringEntity(formParamStr, "UTF-8"));
|
||||
} else if (body != null) {
|
||||
patch.setHeader("Content-Type", contentType);
|
||||
patch.setEntity(new StringEntity(serialize(body), "UTF-8"));
|
||||
}
|
||||
for(String key : headers.keySet()) {
|
||||
patch.setHeader(key, headers.get(key));
|
||||
}
|
||||
response = client.execute(patch);
|
||||
}
|
||||
|
||||
int code = response.getStatusLine().getStatusCode();
|
||||
String responseString = null;
|
||||
if(code == 204)
|
||||
responseString = "";
|
||||
else if(code >= 200 && code < 300) {
|
||||
if(response.getEntity() != null) {
|
||||
HttpEntity resEntity = response.getEntity();
|
||||
responseString = EntityUtils.toString(resEntity);
|
||||
}
|
||||
return responseString;
|
||||
}
|
||||
else {
|
||||
if(response.getEntity() != null) {
|
||||
HttpEntity resEntity = response.getEntity();
|
||||
responseString = EntityUtils.toString(resEntity);
|
||||
}
|
||||
else
|
||||
responseString = "no data";
|
||||
}
|
||||
throw new ApiException(code, responseString);
|
||||
}
|
||||
catch(IOException e) {
|
||||
throw new ApiException(500, e.getMessage());
|
||||
}
|
||||
}
|
||||
int code = response.getStatusLine().getStatusCode();
|
||||
String responseString = null;
|
||||
if(code == 204)
|
||||
responseString = "";
|
||||
else if(code >= 200 && code < 300) {
|
||||
if(response.getEntity() != null) {
|
||||
HttpEntity resEntity = response.getEntity();
|
||||
responseString = EntityUtils.toString(resEntity);
|
||||
}
|
||||
return responseString;
|
||||
}
|
||||
else {
|
||||
if(response.getEntity() != null) {
|
||||
HttpEntity resEntity = response.getEntity();
|
||||
responseString = EntityUtils.toString(resEntity);
|
||||
}
|
||||
else
|
||||
responseString = "no data";
|
||||
}
|
||||
throw new ApiException(code, responseString);
|
||||
}
|
||||
catch(IOException e) {
|
||||
throw new ApiException(500, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private HttpClient getClient(String host) {
|
||||
if (client == null) {
|
||||
if (ignoreSSLCertificates && ignoreSSLConnectionManager != null) {
|
||||
// Trust self signed certificates
|
||||
client = new DefaultHttpClient(ignoreSSLConnectionManager, new BasicHttpParams());
|
||||
} else {
|
||||
client = new DefaultHttpClient();
|
||||
}
|
||||
}
|
||||
return client;
|
||||
}
|
||||
private HttpClient getClient(String host) {
|
||||
if (client == null) {
|
||||
if (ignoreSSLCertificates && ignoreSSLConnectionManager != null) {
|
||||
// Trust self signed certificates
|
||||
client = new DefaultHttpClient(ignoreSSLConnectionManager, new BasicHttpParams());
|
||||
} else {
|
||||
client = new DefaultHttpClient();
|
||||
}
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
private void initConnectionManager() {
|
||||
try {
|
||||
final SSLContext sslContext = SSLContext.getInstance("SSL");
|
||||
private void initConnectionManager() {
|
||||
try {
|
||||
final SSLContext sslContext = SSLContext.getInstance("SSL");
|
||||
|
||||
// set up a TrustManager that trusts everything
|
||||
TrustManager[] trustManagers = new TrustManager[] {
|
||||
new X509TrustManager() {
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
|
||||
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
|
||||
}};
|
||||
|
||||
sslContext.init(null, trustManagers, new SecureRandom());
|
||||
|
||||
SSLSocketFactory sf = new SSLSocketFactory((KeyStore)null) {
|
||||
private javax.net.ssl.SSLSocketFactory sslFactory = sslContext.getSocketFactory();
|
||||
|
||||
public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
|
||||
throws IOException, UnknownHostException {
|
||||
return sslFactory.createSocket(socket, host, port, autoClose);
|
||||
}
|
||||
|
||||
public Socket createSocket() throws IOException {
|
||||
return sslFactory.createSocket();
|
||||
}
|
||||
};
|
||||
|
||||
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||
Scheme httpsScheme = new Scheme("https", sf, 443);
|
||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
schemeRegistry.register(httpsScheme);
|
||||
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
||||
|
||||
ignoreSSLConnectionManager = new ThreadSafeClientConnManager(new BasicHttpParams(), schemeRegistry);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
// This will only be thrown if SSL isn't available for some reason.
|
||||
} catch (KeyManagementException e) {
|
||||
// This might be thrown when passing a key into init(), but no key is being passed.
|
||||
} catch (GeneralSecurityException e) {
|
||||
// This catches anything else that might go wrong.
|
||||
// If anything goes wrong we default to the standard connection manager.
|
||||
}
|
||||
}
|
||||
// set up a TrustManager that trusts everything
|
||||
TrustManager[] trustManagers = new TrustManager[] {
|
||||
new X509TrustManager() {
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
public void checkClientTrusted(X509Certificate[] certs, String authType) {}
|
||||
public void checkServerTrusted(X509Certificate[] certs, String authType) {}
|
||||
}};
|
||||
|
||||
sslContext.init(null, trustManagers, new SecureRandom());
|
||||
|
||||
SSLSocketFactory sf = new SSLSocketFactory((KeyStore)null) {
|
||||
private javax.net.ssl.SSLSocketFactory sslFactory = sslContext.getSocketFactory();
|
||||
|
||||
public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
|
||||
throws IOException, UnknownHostException {
|
||||
return sslFactory.createSocket(socket, host, port, autoClose);
|
||||
}
|
||||
|
||||
public Socket createSocket() throws IOException {
|
||||
return sslFactory.createSocket();
|
||||
}
|
||||
};
|
||||
|
||||
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||
Scheme httpsScheme = new Scheme("https", sf, 443);
|
||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
schemeRegistry.register(httpsScheme);
|
||||
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
||||
|
||||
ignoreSSLConnectionManager = new ThreadSafeClientConnManager(new BasicHttpParams(), schemeRegistry);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
// This will only be thrown if SSL isn't available for some reason.
|
||||
} catch (KeyManagementException e) {
|
||||
// This might be thrown when passing a key into init(), but no key is being passed.
|
||||
} catch (GeneralSecurityException e) {
|
||||
// This catches anything else that might go wrong.
|
||||
// If anything goes wrong we default to the standard connection manager.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,93 +1,93 @@
|
||||
{{#useAndroidMavenGradlePlugin}}
|
||||
group = '{{groupId}}'
|
||||
project.version = '{{artifactVersion}}'
|
||||
group = '{{groupId}}'
|
||||
project.version = '{{artifactVersion}}'
|
||||
{{/useAndroidMavenGradlePlugin}}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:1.2.2'
|
||||
{{#useAndroidMavenGradlePlugin}}
|
||||
classpath 'com.github.dcendents:android-maven-plugin:1.2'
|
||||
{{/useAndroidMavenGradlePlugin}}
|
||||
}
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:1.2.2'
|
||||
{{#useAndroidMavenGradlePlugin}}
|
||||
classpath 'com.github.dcendents:android-maven-plugin:1.2'
|
||||
{{/useAndroidMavenGradlePlugin}}
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
{{#useAndroidMavenGradlePlugin}}
|
||||
apply plugin: 'com.github.dcendents.android-maven'
|
||||
apply plugin: 'com.github.dcendents.android-maven'
|
||||
{{/useAndroidMavenGradlePlugin}}
|
||||
|
||||
android {
|
||||
compileSdkVersion 22
|
||||
buildToolsVersion '22.0.0'
|
||||
defaultConfig {
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 22
|
||||
}
|
||||
compileSdkVersion 22
|
||||
buildToolsVersion '22.0.0'
|
||||
defaultConfig {
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 22
|
||||
}
|
||||
|
||||
// Rename the aar correctly
|
||||
libraryVariants.all { variant ->
|
||||
variant.outputs.each { output ->
|
||||
def outputFile = output.outputFile
|
||||
if (outputFile != null && outputFile.name.endsWith('.aar')) {
|
||||
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
|
||||
output.outputFile = new File(outputFile.parent, fileName)
|
||||
}
|
||||
}
|
||||
}
|
||||
// Rename the aar correctly
|
||||
libraryVariants.all { variant ->
|
||||
variant.outputs.each { output ->
|
||||
def outputFile = output.outputFile
|
||||
if (outputFile != null && outputFile.name.endsWith('.aar')) {
|
||||
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
|
||||
output.outputFile = new File(outputFile.parent, fileName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ext {
|
||||
swagger_annotations_version = "1.5.0"
|
||||
gson_version = "2.3.1"
|
||||
httpclient_version = "4.3.3"
|
||||
junit_version = "4.8.1"
|
||||
swagger_annotations_version = "1.5.0"
|
||||
gson_version = "2.3.1"
|
||||
httpclient_version = "4.3.3"
|
||||
junit_version = "4.8.1"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
|
||||
compile "com.google.code.gson:gson:$gson_version"
|
||||
compile "org.apache.httpcomponents:httpcore:$httpclient_version"
|
||||
compile "org.apache.httpcomponents:httpclient:$httpclient_version"
|
||||
compile ("org.apache.httpcomponents:httpcore:$httpclient_version") {
|
||||
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
|
||||
}
|
||||
compile ("org.apache.httpcomponents:httpmime:$httpclient_version") {
|
||||
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
|
||||
}
|
||||
testCompile "junit:junit:$junit_version"
|
||||
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
|
||||
compile "com.google.code.gson:gson:$gson_version"
|
||||
compile "org.apache.httpcomponents:httpcore:$httpclient_version"
|
||||
compile "org.apache.httpcomponents:httpclient:$httpclient_version"
|
||||
compile ("org.apache.httpcomponents:httpcore:$httpclient_version") {
|
||||
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
|
||||
}
|
||||
compile ("org.apache.httpcomponents:httpmime:$httpclient_version") {
|
||||
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
|
||||
}
|
||||
testCompile "junit:junit:$junit_version"
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
android.libraryVariants.all { variant ->
|
||||
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
|
||||
task.description = "Create jar artifact for ${variant.name}"
|
||||
task.dependsOn variant.javaCompile
|
||||
task.from variant.javaCompile.destinationDir
|
||||
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
|
||||
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
|
||||
artifacts.add('archives', task);
|
||||
}
|
||||
android.libraryVariants.all { variant ->
|
||||
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
|
||||
task.description = "Create jar artifact for ${variant.name}"
|
||||
task.dependsOn variant.javaCompile
|
||||
task.from variant.javaCompile.destinationDir
|
||||
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
|
||||
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
|
||||
artifacts.add('archives', task);
|
||||
}
|
||||
}
|
||||
|
||||
{{#useAndroidMavenGradlePlugin}}
|
||||
task sourcesJar(type: Jar) {
|
||||
task sourcesJar(type: Jar) {
|
||||
from android.sourceSets.main.java.srcDirs
|
||||
classifier = 'sources'
|
||||
}
|
||||
}
|
||||
|
||||
artifacts {
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
}
|
||||
}
|
||||
{{/useAndroidMavenGradlePlugin}}
|
||||
@@ -3,14 +3,14 @@ package {{invokerPackage}};
|
||||
import org.apache.http.client.methods.*;
|
||||
|
||||
public class HttpPatch extends HttpPost {
|
||||
public static final String METHOD_PATCH = "PATCH";
|
||||
public static final String METHOD_PATCH = "PATCH";
|
||||
|
||||
public HttpPatch(final String url) {
|
||||
super(url);
|
||||
}
|
||||
public HttpPatch(final String url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return METHOD_PATCH;
|
||||
}
|
||||
@Override
|
||||
public String getMethod() {
|
||||
return METHOD_PATCH;
|
||||
}
|
||||
}
|
||||
@@ -8,55 +8,48 @@ import java.util.List;
|
||||
import {{modelPackage}}.*;
|
||||
|
||||
public class JsonUtil {
|
||||
public static GsonBuilder gsonBuilder;
|
||||
public static GsonBuilder gsonBuilder;
|
||||
|
||||
static {
|
||||
gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.serializeNulls();
|
||||
gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
}
|
||||
static {
|
||||
gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.serializeNulls();
|
||||
gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
}
|
||||
|
||||
public static Gson getGson() {
|
||||
return gsonBuilder.create();
|
||||
}
|
||||
public static Gson getGson() {
|
||||
return gsonBuilder.create();
|
||||
}
|
||||
|
||||
public static String serialize(Object obj){
|
||||
return getGson().toJson(obj);
|
||||
}
|
||||
public static String serialize(Object obj){
|
||||
return getGson().toJson(obj);
|
||||
}
|
||||
|
||||
public static
|
||||
<T> T deserializeToList(String jsonString, Class cls){
|
||||
public static <T> T deserializeToList(String jsonString, Class cls){
|
||||
return getGson().fromJson(jsonString, getListTypeForDeserialization(cls));
|
||||
}
|
||||
|
||||
public static <T> T deserializeToObject(String jsonString, Class cls){
|
||||
return getGson().fromJson(jsonString, getTypeForDeserialization(cls));
|
||||
}
|
||||
|
||||
public static Type getListTypeForDeserialization(Class cls) {
|
||||
String className = cls.getSimpleName();
|
||||
{{#models}}{{#model}}
|
||||
if ("{{classname}}".equalsIgnoreCase(className)) {
|
||||
return new TypeToken<List<{{classname}}>>(){}.getType();
|
||||
}
|
||||
{{/model}}{{/models}}
|
||||
return new TypeToken<List<Object>>(){}.getType();
|
||||
}
|
||||
|
||||
public static
|
||||
<T> T deserializeToObject(String jsonString, Class cls){
|
||||
return getGson().fromJson(jsonString, getTypeForDeserialization(cls));
|
||||
}
|
||||
public static Type getTypeForDeserialization(Class cls) {
|
||||
String className = cls.getSimpleName();
|
||||
{{#models}}{{#model}}
|
||||
if ("{{classname}}".equalsIgnoreCase(className)) {
|
||||
return new TypeToken<{{classname}}>(){}.getType();
|
||||
}
|
||||
{{/model}}{{/models}}
|
||||
return new TypeToken<Object>(){}.getType();
|
||||
}
|
||||
|
||||
public static Type getListTypeForDeserialization(Class cls) {
|
||||
String className = cls.getSimpleName();
|
||||
{{#models}}{{#model}}
|
||||
if ("{{classname}}".equalsIgnoreCase(className)) {
|
||||
return new TypeToken
|
||||
<List
|
||||
<{{classname}}>>(){}.getType();
|
||||
}
|
||||
{{/model}}{{/models}}
|
||||
return new TypeToken
|
||||
<List
|
||||
<Object>>(){}.getType();
|
||||
}
|
||||
|
||||
public static Type getTypeForDeserialization(Class cls) {
|
||||
String className = cls.getSimpleName();
|
||||
{{#models}}{{#model}}
|
||||
if ("{{classname}}".equalsIgnoreCase(className)) {
|
||||
return new TypeToken<{{classname}}>(){}.getType();
|
||||
}
|
||||
{{/model}}{{/models}}
|
||||
return new TypeToken
|
||||
<Object>(){}.getType();
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<manifest package="{{invokerPackage}}">
|
||||
<application/>
|
||||
<application />
|
||||
</manifest>
|
||||
|
||||
@@ -7,46 +7,46 @@ import io.swagger.annotations.*;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
{{#models}}
|
||||
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||
};
|
||||
@SerializedName("{{baseName}}")
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
|
||||
@SerializedName("{{baseName}}")
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||
};
|
||||
@SerializedName("{{baseName}}")
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
|
||||
@SerializedName("{{baseName}}")
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
|
||||
{{/vars}}
|
||||
{{/vars}}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#parent}}sb.append(" " + super.toString()).append("\n");{{/parent}}
|
||||
{{#vars}}sb.append(" {{name}}: ").append({{name}}).append("\n");
|
||||
{{/vars}}sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
@@ -1,158 +1,155 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:swagger-api/swagger-mustache.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
|
||||
<url>https://github.com/swagger-api/swagger-codegen</url>
|
||||
</scm>
|
||||
<prerequisites>
|
||||
<maven>2.2.0</maven>
|
||||
</prerequisites>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:swagger-api/swagger-mustache.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:swagger-api/swagger-codegen.git</developerConnection>
|
||||
<url>https://github.com/swagger-api/swagger-codegen</url>
|
||||
</scm>
|
||||
<prerequisites>
|
||||
<maven>2.2.0</maven>
|
||||
</prerequisites>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12</version>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>loggerPath</name>
|
||||
<value>conf/log4j.properties</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
<argLine>-Xms512m -Xmx1500m</argLine>
|
||||
<parallel>methods</parallel>
|
||||
<forkMode>pertest</forkMode>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12</version>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>loggerPath</name>
|
||||
<value>conf/log4j.properties</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
<argLine>-Xms512m -Xmx1500m</argLine>
|
||||
<parallel>methods</parallel>
|
||||
<forkMode>pertest</forkMode>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- attach test jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- attach test jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add_sources</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>
|
||||
src/main/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>add_test_sources</id>
|
||||
<phase>generate-test-sources</phase>
|
||||
<goals>
|
||||
<goal>add-test-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>
|
||||
src/test/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>
|
||||
1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${gson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpmime</artifactId>
|
||||
<version>${httpclient-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add_sources</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/main/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>add_test_sources</id>
|
||||
<phase>generate-test-sources</phase>
|
||||
<goals>
|
||||
<goal>add-test-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/test/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${gson-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpmime</artifactId>
|
||||
<version>${httpclient-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
||||
<gson-version>2.3.1</gson-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<httpclient-version>4.3.6</httpclient-version>
|
||||
</properties>
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
||||
<gson-version>2.3.1</gson-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<httpclient-version>4.3.6</httpclient-version>
|
||||
</properties>
|
||||
</project>
|
||||
@@ -8,37 +8,37 @@ 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}} = {
|
||||
// create path and map variables
|
||||
val path = (addFmt("{{path}}"){{#pathParams}}
|
||||
replaceAll ("\\{" + "{{baseName}}" + "\\}",{{paramName}}.toString){{/pathParams}})
|
||||
{{#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}} = {
|
||||
// create path and map variables
|
||||
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]
|
||||
// query params
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
{{#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}}
|
||||
{{#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}}
|
||||
|
||||
{{#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}}
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
{{#headerParams}}headerParams += "{{baseName}}" -> {{paramName}}.toString{{/headerParams}}
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
|
||||
}
|
||||
{{/operations}}
|
||||
|
||||
@@ -9,17 +9,17 @@ import io.swagger.client._
|
||||
import java.io.Closeable
|
||||
|
||||
class {{clientName}}(config: SwaggerConfig) extends Closeable {
|
||||
val locator = config.locator
|
||||
val name = config.name
|
||||
val locator = config.locator
|
||||
val name = config.name
|
||||
|
||||
private[this] val client = transportClient
|
||||
private[this] val client = transportClient
|
||||
|
||||
protected def transportClient: TransportClient = new RestClient(config)
|
||||
{{#apiInfo}}{{#apis}}
|
||||
val {{classVarName}} = new {{classname}}(client, config)
|
||||
{{/apis}}{{/apiInfo}}
|
||||
protected def transportClient: TransportClient = new RestClient(config)
|
||||
{{#apiInfo}}{{#apis}}
|
||||
val {{classVarName}} = new {{classname}}(client, config)
|
||||
{{/apis}}{{/apiInfo}}
|
||||
|
||||
def close() {
|
||||
client.close()
|
||||
}
|
||||
def close() {
|
||||
client.close()
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,10 @@ import org.joda.time.DateTime
|
||||
|
||||
{{#models}}
|
||||
|
||||
{{#model}}
|
||||
case class {{classname}} (
|
||||
{{#vars}}{{name}}: {{#isNotRequired}}Option[{{/isNotRequired}}{{datatype}}{{#isNotRequired}}]{{/isNotRequired}}{{#hasMore}},{{/hasMore}}{{#description}} // {{description}}{{/description}}
|
||||
{{/vars}}
|
||||
)
|
||||
{{/model}}
|
||||
{{#model}}
|
||||
case class {{classname}} (
|
||||
{{#vars}}{{name}}: {{#isNotRequired}}Option[{{/isNotRequired}}{{datatype}}{{#isNotRequired}}]{{/isNotRequired}}{{#hasMore}},{{/hasMore}}{{#description}} // {{description}}{{/description}}
|
||||
{{/vars}}
|
||||
)
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
@@ -3,10 +3,10 @@ organization := "{{package}}"
|
||||
name := "{{projectName}}-client"
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
"io.swagger" %% "swagger-async-httpclient" % "0.3.5",
|
||||
"joda-time" % "joda-time" % "2.3",
|
||||
"org.joda" % "joda-convert" % "1.3.1",
|
||||
"ch.qos.logback" % "logback-classic" % "1.0.13" % "provided",
|
||||
"org.scalatest" %% "scalatest" % "2.2.1" % "test",
|
||||
"junit" % "junit" % "4.11" % "test"
|
||||
"io.swagger" %% "swagger-async-httpclient" % "0.3.5",
|
||||
"joda-time" % "joda-time" % "2.3",
|
||||
"org.joda" % "joda-convert" % "1.3.1",
|
||||
"ch.qos.logback" % "logback-classic" % "1.0.13" % "provided",
|
||||
"org.scalatest" %% "scalatest" % "2.2.1" % "test",
|
||||
"junit" % "junit" % "4.11" % "test"
|
||||
)
|
||||
|
||||
@@ -9,7 +9,7 @@ your changes applied.
|
||||
The goal of Swagger™ is to define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via Swagger, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interfaces have done for lower-level programming, Swagger removes the guesswork in calling the service.
|
||||
|
||||
|
||||
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.
|
||||
|
||||
## How do I use this?
|
||||
At this point, you've likely generated a client setup. It will include something along these lines:
|
||||
|
||||
@@ -8,186 +8,184 @@ import java.io.File;
|
||||
|
||||
public class {{generatorClass}} extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// source folder where to write the files
|
||||
protected String sourceFolder = "src";
|
||||
protected String apiVersion = "1.0.0";
|
||||
// source folder where to write the files
|
||||
protected String sourceFolder = "src";
|
||||
protected String apiVersion = "1.0.0";
|
||||
|
||||
/**
|
||||
* Configures the type of generator.
|
||||
*
|
||||
* @return the CodegenType for this generator
|
||||
* @see io.swagger.codegen.CodegenType
|
||||
*/
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
/**
|
||||
* Configures the type of generator.
|
||||
*
|
||||
* @return the CodegenType for this generator
|
||||
* @see io.swagger.codegen.CodegenType
|
||||
*/
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a friendly name for the generator. This will be used by the generator
|
||||
* to select the library with the -l flag.
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
public String getName() {
|
||||
return "{{name}}";
|
||||
}
|
||||
/**
|
||||
* Configures a friendly name for the generator. This will be used by the generator
|
||||
* to select the library with the -l flag.
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
public String getName() {
|
||||
return "{{name}}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns human-friendly help for the generator. Provide the consumer with help
|
||||
* tips, parameters here
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
public String getHelp() {
|
||||
return "Generates a {{name}} client library.";
|
||||
}
|
||||
/**
|
||||
* Returns human-friendly help for the generator. Provide the consumer with help
|
||||
* tips, parameters here
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
public String getHelp() {
|
||||
return "Generates a {{name}} client library.";
|
||||
}
|
||||
|
||||
public {{generatorClass}}() {
|
||||
super();
|
||||
public {{generatorClass}}() {
|
||||
super();
|
||||
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/{{name}}";
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/{{name}}";
|
||||
|
||||
/**
|
||||
* Models. You can write model files using the modelTemplateFiles map.
|
||||
* if you want to create one template for file, you can do so here.
|
||||
* for multiple files for model, just put another entry in the `modelTemplateFiles` with
|
||||
* a different extension
|
||||
*/
|
||||
modelTemplateFiles.put(
|
||||
"model.mustache", // the template to use
|
||||
".sample"); // the extension for each file to write
|
||||
/**
|
||||
* Models. You can write model files using the modelTemplateFiles map.
|
||||
* if you want to create one template for file, you can do so here.
|
||||
* for multiple files for model, just put another entry in the `modelTemplateFiles` with
|
||||
* a different extension
|
||||
*/
|
||||
modelTemplateFiles.put(
|
||||
"model.mustache", // the template to use
|
||||
".sample"); // the extension for each file to write
|
||||
|
||||
/**
|
||||
* Api classes. You can write classes for each Api file with the apiTemplateFiles map.
|
||||
* as with models, add multiple entries with different extensions for multiple files per
|
||||
* class
|
||||
*/
|
||||
apiTemplateFiles.put(
|
||||
"api.mustache", // the template to use
|
||||
".sample"); // the extension for each file to write
|
||||
/**
|
||||
* Api classes. You can write classes for each Api file with the apiTemplateFiles map.
|
||||
* as with models, add multiple entries with different extensions for multiple files per
|
||||
* class
|
||||
*/
|
||||
apiTemplateFiles.put(
|
||||
"api.mustache", // the template to use
|
||||
".sample"); // the extension for each file to write
|
||||
|
||||
/**
|
||||
* Template Location. This is the location which templates will be read from. The generator
|
||||
* will use the resource stream to attempt to read the templates.
|
||||
*/
|
||||
templateDir = "{{name}}";
|
||||
/**
|
||||
* Template Location. This is the location which templates will be read from. The generator
|
||||
* will use the resource stream to attempt to read the templates.
|
||||
*/
|
||||
templateDir = "{{name}}";
|
||||
|
||||
/**
|
||||
* Api Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
apiPackage = "io.swagger.client.api";
|
||||
/**
|
||||
* Api Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
apiPackage = "io.swagger.client.api";
|
||||
|
||||
/**
|
||||
* Model Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
modelPackage = "io.swagger.client.model";
|
||||
/**
|
||||
* Model Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
modelPackage = "io.swagger.client.model";
|
||||
|
||||
/**
|
||||
* Reserved words. Override this with reserved words specific to your language
|
||||
*/
|
||||
reservedWords = new HashSet
|
||||
<String> (
|
||||
Arrays.asList(
|
||||
"sample1", // replace with static values
|
||||
"sample2")
|
||||
/**
|
||||
* Reserved words. Override this with reserved words specific to your language
|
||||
*/
|
||||
reservedWords = new HashSet<String> (
|
||||
Arrays.asList(
|
||||
"sample1", // replace with static values
|
||||
"sample2")
|
||||
);
|
||||
|
||||
/**
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
*/
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
*/
|
||||
additionalProperties.put("apiVersion", apiVersion);
|
||||
|
||||
/**
|
||||
* Supporting Files. You can write single files for the generator with the
|
||||
* entire object tree available. If the input file has a suffix of `.mustache
|
||||
* it will be processed by the template engine. Otherwise, it will be copied
|
||||
*/
|
||||
supportingFiles.add(new SupportingFile("myFile.mustache", // the input template or file
|
||||
"", // the destination folder, relative `outputFolder`
|
||||
"myFile.sample") // the output file
|
||||
* Supporting Files. You can write single files for the generator with the
|
||||
* entire object tree available. If the input file has a suffix of `.mustache
|
||||
* it will be processed by the template engine. Otherwise, it will be copied
|
||||
*/
|
||||
supportingFiles.add(new SupportingFile("myFile.mustache", // the input template or file
|
||||
"", // the destination folder, relative `outputFolder`
|
||||
"myFile.sample") // the output file
|
||||
);
|
||||
|
||||
/**
|
||||
* Language Specific Primitives. These types will not trigger imports by
|
||||
* the client generator
|
||||
*/
|
||||
languageSpecificPrimitives = new HashSet
|
||||
<String>(
|
||||
Arrays.asList(
|
||||
"Type1", // replace these with your types
|
||||
* Language Specific Primitives. These types will not trigger imports by
|
||||
* the client generator
|
||||
*/
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"Type1", // replace these with your types
|
||||
"Type2")
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
|
||||
* those terms here. This logic is only called if a variable matches the reseved words
|
||||
*
|
||||
* @return the escaped term
|
||||
*/
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name; // add an underscore to the name
|
||||
}
|
||||
/**
|
||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
|
||||
* those terms here. This logic is only called if a variable matches the reseved words
|
||||
*
|
||||
* @return the escaped term
|
||||
*/
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name; // add an underscore to the name
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write model files. You can use the modelPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
/**
|
||||
* Location to write model files. You can use the modelPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write api files. You can use the apiPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
/**
|
||||
* Location to write api files. You can use the apiPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - type declaration. This is a String which is used by the templates to instantiate your
|
||||
* types. There is typically special handling for different property types
|
||||
*
|
||||
* @return a string value used as the `dataType` field for model templates, `returnType` for api templates
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
/**
|
||||
* Optional - type declaration. This is a String which is used by the templates to instantiate your
|
||||
* types. There is typically special handling for different property types
|
||||
*
|
||||
* @return a string value used as the `dataType` field for model templates, `returnType` for api templates
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - swagger type conversion. This is used to map swagger types in a `Property` into
|
||||
* either language specific types via `typeMapping` or into complex models if there is not a mapping.
|
||||
*
|
||||
* @return a string value of the type or complex model for this property
|
||||
* @see io.swagger.models.properties.Property
|
||||
*/
|
||||
@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))
|
||||
/**
|
||||
* Optional - swagger type conversion. This is used to map swagger types in a `Property` into
|
||||
* either language specific types via `typeMapping` or into complex models if there is not a mapping.
|
||||
*
|
||||
* @return a string value of the type or complex model for this property
|
||||
* @see io.swagger.models.properties.Property
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
type = swaggerType;
|
||||
return toModelName(type);
|
||||
}
|
||||
}
|
||||
@@ -1,105 +1,102 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>{{name}}-swagger-codegen</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{name}}-swagger-codegen</name>
|
||||
<version>1.0.0</version>
|
||||
<prerequisites>
|
||||
<maven>2.2.0</maven>
|
||||
</prerequisites>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12</version>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>loggerPath</name>
|
||||
<value>conf/log4j.properties</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
<argLine>-Xms512m -Xmx1500m</argLine>
|
||||
<parallel>methods</parallel>
|
||||
<forkMode>pertest</forkMode>
|
||||
</configuration>
|
||||
</plugin>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>{{name}}-swagger-codegen</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{name}}-swagger-codegen</name>
|
||||
<version>1.0.0</version>
|
||||
<prerequisites>
|
||||
<maven>2.2.0</maven>
|
||||
</prerequisites>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12</version>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>loggerPath</name>
|
||||
<value>conf/log4j.properties</value>
|
||||
</property>
|
||||
</systemProperties>
|
||||
<argLine>-Xms512m -Xmx1500m</argLine>
|
||||
<parallel>methods</parallel>
|
||||
<forkMode>pertest</forkMode>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- attach test jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- attach test jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add_sources</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>
|
||||
src/main/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>add_test_sources</id>
|
||||
<phase>generate-test-sources</phase>
|
||||
<goals>
|
||||
<goal>add-test-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>
|
||||
src/test/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>
|
||||
1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-codegen</artifactId>
|
||||
<version>${swagger-codegen-version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<swagger-codegen-version>2.1.2-M1</swagger-codegen-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
</properties>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add_sources</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/main/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>add_test_sources</id>
|
||||
<phase>generate-test-sources</phase>
|
||||
<goals>
|
||||
<goal>add-test-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/test/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-codegen</artifactId>
|
||||
<version>${swagger-codegen-version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<swagger-codegen-version>2.1.2-M1</swagger-codegen-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
</properties>
|
||||
</project>
|
||||
@@ -9,308 +9,209 @@ using Newtonsoft.Json;
|
||||
using RestSharp;
|
||||
|
||||
namespace {{invokerPackage}} {
|
||||
///
|
||||
<summary>
|
||||
/// API client is mainly responible for making the HTTP call to the API backend
|
||||
///
|
||||
</summary>
|
||||
public class ApiClient {
|
||||
/// <summary>
|
||||
/// API client is mainly responible for making the HTTP call to the API backend
|
||||
/// </summary>
|
||||
public class ApiClient {
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Initializes a new instance of the
|
||||
<see cref="ApiClient"/>
|
||||
class.
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<param name="basePath">The base path.</param>
|
||||
public ApiClient(String basePath="{{basePath}}") {
|
||||
this.basePath = basePath;
|
||||
this.restClient = new RestClient(this.basePath);
|
||||
}
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiClient"/> class.
|
||||
/// </summary>
|
||||
/// <param name="basePath">The base path.</param>
|
||||
public ApiClient(String basePath="{{basePath}}") {
|
||||
this.basePath = basePath;
|
||||
this.restClient = new RestClient(this.basePath);
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// <summary>
|
||||
/// Gets or sets the base path.
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<value>The base path.</value>
|
||||
public string basePath { get; set; }
|
||||
/// </summary>
|
||||
/// <value>The base path.</value>
|
||||
public string basePath { get; set; }
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// <summary>
|
||||
/// Gets or sets the RestClient
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<value>The RestClient.</value>
|
||||
public RestClient restClient { get; set; }
|
||||
/// </summary>
|
||||
/// <value>The RestClient.</value>
|
||||
public RestClient restClient { get; set; }
|
||||
|
||||
private Dictionary
|
||||
<String, String> defaultHeaderMap = new Dictionary
|
||||
<String, String>();
|
||||
private Dictionary<String, String> defaultHeaderMap = new Dictionary<String, String>();
|
||||
|
||||
public Object CallApi(String Path, RestSharp.Method Method, Dictionary
|
||||
<String, String> QueryParams, String PostBody,
|
||||
Dictionary
|
||||
<String, String> HeaderParams, Dictionary
|
||||
<String, String> FormParams, Dictionary
|
||||
<String, String> FileParams, String[] AuthSettings) {
|
||||
var response = Task.Run(async () => {
|
||||
var resp = await CallApiAsync(Path, Method, QueryParams, PostBody, HeaderParams, FormParams, FileParams, AuthSettings);
|
||||
return resp;
|
||||
});
|
||||
return response.Result;
|
||||
}
|
||||
|
||||
public async Task
|
||||
<Object> CallApiAsync(String Path, RestSharp.Method Method, Dictionary
|
||||
<String
|
||||
, String> QueryParams, String PostBody,
|
||||
Dictionary
|
||||
<String
|
||||
, String> HeaderParams, Dictionary
|
||||
<String
|
||||
, String> FormParams, Dictionary
|
||||
<String
|
||||
, String> FileParams, String[] AuthSettings) {
|
||||
|
||||
var request = new RestRequest(Path, Method);
|
||||
|
||||
UpdateParamsForAuth(QueryParams, HeaderParams, AuthSettings);
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair
|
||||
<string
|
||||
, string> defaultHeader in this.defaultHeaderMap)
|
||||
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
|
||||
// add header parameter, if any
|
||||
foreach(KeyValuePair
|
||||
<string
|
||||
, string> param in HeaderParams)
|
||||
request.AddHeader(param.Key, param.Value);
|
||||
|
||||
// add query parameter, if any
|
||||
foreach(KeyValuePair
|
||||
<string
|
||||
, string> param in QueryParams)
|
||||
request.AddQueryParameter(param.Key, param.Value);
|
||||
|
||||
// add form parameter, if any
|
||||
foreach(KeyValuePair
|
||||
<string
|
||||
, string> param in FormParams)
|
||||
request.AddParameter(param.Key, param.Value);
|
||||
|
||||
// add file parameter, if any
|
||||
foreach(KeyValuePair
|
||||
<string
|
||||
, string> param in FileParams)
|
||||
request.AddFile(param.Key, param.Value);
|
||||
|
||||
if (PostBody != null) {
|
||||
request.AddParameter("application/json", PostBody, ParameterType.RequestBody); // http body (model) parameter
|
||||
public Object CallApi(String Path, RestSharp.Method Method, Dictionary<String, String> QueryParams, String PostBody,
|
||||
Dictionary<String, String> HeaderParams, Dictionary<String, String> FormParams, Dictionary<String, String> FileParams, String[] AuthSettings) {
|
||||
var response = Task.Run(async () => {
|
||||
var resp = await CallApiAsync(Path, Method, QueryParams, PostBody, HeaderParams, FormParams, FileParams, AuthSettings);
|
||||
return resp;
|
||||
});
|
||||
return response.Result;
|
||||
}
|
||||
|
||||
return (Object) await restClient.ExecuteTaskAsync(request);
|
||||
public async Task<Object> CallApiAsync(String Path, RestSharp.Method Method, Dictionary<String, String> QueryParams, String PostBody,
|
||||
Dictionary<String, String> HeaderParams, Dictionary<String, String> FormParams, Dictionary<String, String> FileParams, String[] AuthSettings) {
|
||||
|
||||
var request = new RestRequest(Path, Method);
|
||||
|
||||
UpdateParamsForAuth(QueryParams, HeaderParams, AuthSettings);
|
||||
|
||||
// add default header, if any
|
||||
foreach(KeyValuePair<string, string> defaultHeader in this.defaultHeaderMap)
|
||||
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
|
||||
|
||||
// add header parameter, if any
|
||||
foreach(KeyValuePair<string, string> param in HeaderParams)
|
||||
request.AddHeader(param.Key, param.Value);
|
||||
|
||||
// add query parameter, if any
|
||||
foreach(KeyValuePair<string, string> param in QueryParams)
|
||||
request.AddQueryParameter(param.Key, param.Value);
|
||||
|
||||
// add form parameter, if any
|
||||
foreach(KeyValuePair<string, string> param in FormParams)
|
||||
request.AddParameter(param.Key, param.Value);
|
||||
|
||||
// add file parameter, if any
|
||||
foreach(KeyValuePair<string, string> param in FileParams)
|
||||
request.AddFile(param.Key, param.Value);
|
||||
|
||||
if (PostBody != null) {
|
||||
request.AddParameter("application/json", PostBody, ParameterType.RequestBody); // http body (model) parameter
|
||||
}
|
||||
|
||||
return (Object) await restClient.ExecuteTaskAsync(request);
|
||||
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Add default header
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<param name="key">
|
||||
Header field name
|
||||
///
|
||||
<param name="value">
|
||||
Header field value
|
||||
///
|
||||
<returns></returns>
|
||||
/// <summary>
|
||||
/// Add default header
|
||||
/// </summary>
|
||||
/// <param name="key"> Header field name
|
||||
/// <param name="value"> Header field value
|
||||
/// <returns></returns>
|
||||
public void AddDefaultHeader(string key, string value) {
|
||||
defaultHeaderMap.Add(key, value);
|
||||
defaultHeaderMap.Add(key, value);
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Get default header
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<returns>Dictionary of default header</returns>
|
||||
public Dictionary
|
||||
<String
|
||||
, String> GetDefaultHeader() {
|
||||
return defaultHeaderMap;
|
||||
/// <summary>
|
||||
/// Get default header
|
||||
/// </summary>
|
||||
/// <returns>Dictionary of default header</returns>
|
||||
public Dictionary<String, String> GetDefaultHeader() {
|
||||
return defaultHeaderMap;
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// escape string (url-encoded)
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<param name="str">
|
||||
String to be escaped
|
||||
///
|
||||
<returns>Escaped string</returns>
|
||||
/// <summary>
|
||||
/// escape string (url-encoded)
|
||||
/// </summary>
|
||||
/// <param name="str"> String to be escaped
|
||||
/// <returns>Escaped string</returns>
|
||||
public string EscapeString(string str) {
|
||||
return str;
|
||||
return str;
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// if parameter is DateTime, output in ISO8601 format
|
||||
/// if parameter is a list of string, join the list with ","
|
||||
/// otherwise just return the string
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<param name="obj">
|
||||
The parameter (header, path, query, form)
|
||||
///
|
||||
<returns>Formatted string</returns>
|
||||
/// <summary>
|
||||
/// if parameter is DateTime, output in ISO8601 format
|
||||
/// if parameter is a list of string, join the list with ","
|
||||
/// otherwise just return the string
|
||||
/// </summary>
|
||||
/// <param name="obj"> The parameter (header, path, query, form)
|
||||
/// <returns>Formatted string</returns>
|
||||
public string ParameterToString(object obj)
|
||||
{
|
||||
if (obj is DateTime) {
|
||||
return ((DateTime)obj).ToString ("u");
|
||||
} else if (obj is List
|
||||
<string>) {
|
||||
return String.Join(",", obj as List
|
||||
<string>);
|
||||
} else {
|
||||
return Convert.ToString (obj);
|
||||
}
|
||||
}
|
||||
if (obj is DateTime) {
|
||||
return ((DateTime)obj).ToString ("u");
|
||||
} else if (obj is List<string>) {
|
||||
return String.Join(",", obj as List<string>);
|
||||
} else {
|
||||
return Convert.ToString (obj);
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Deserialize the JSON string into a proper object
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<param name="json">
|
||||
JSON string
|
||||
///
|
||||
<param name="type">
|
||||
Object type
|
||||
///
|
||||
<returns>Object representation of the JSON string</returns>
|
||||
public object Deserialize(string content, Type type) {
|
||||
if (type.GetType() == typeof(Object))
|
||||
return (Object)content;
|
||||
/// <summary>
|
||||
/// Deserialize the JSON string into a proper object
|
||||
/// </summary>
|
||||
/// <param name="json"> JSON string
|
||||
/// <param name="type"> Object type
|
||||
/// <returns>Object representation of the JSON string</returns>
|
||||
public object Deserialize(string content, Type type) {
|
||||
if (type.GetType() == typeof(Object))
|
||||
return (Object)content;
|
||||
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject(content, type);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new ApiException(500, e.Message);
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
return JsonConvert.DeserializeObject(content, type);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new ApiException(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Serialize an object into JSON string
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<param name="obj">
|
||||
Object
|
||||
///
|
||||
<returns>JSON string</returns>
|
||||
public string Serialize(object obj) {
|
||||
try
|
||||
{
|
||||
return obj != null ? JsonConvert.SerializeObject(obj) : null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ApiException(500, e.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Serialize an object into JSON string
|
||||
/// </summary>
|
||||
/// <param name="obj"> Object
|
||||
/// <returns>JSON string</returns>
|
||||
public string Serialize(object obj) {
|
||||
try
|
||||
{
|
||||
return obj != null ? JsonConvert.SerializeObject(obj) : null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ApiException(500, e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Get the API key with prefix
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<param name="obj">
|
||||
Object
|
||||
///
|
||||
<returns>API key with prefix</returns>
|
||||
public string GetApiKeyWithPrefix (string apiKey)
|
||||
{
|
||||
var apiKeyValue = "";
|
||||
Configuration.apiKey.TryGetValue (apiKey, out apiKeyValue);
|
||||
var apiKeyPrefix = "";
|
||||
if (Configuration.apiKeyPrefix.TryGetValue (apiKey, out apiKeyPrefix)) {
|
||||
return apiKeyPrefix + " " + apiKeyValue;
|
||||
} else {
|
||||
return apiKeyValue;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Get the API key with prefix
|
||||
/// </summary>
|
||||
/// <param name="obj"> Object
|
||||
/// <returns>API key with prefix</returns>
|
||||
public string GetApiKeyWithPrefix (string apiKey)
|
||||
{
|
||||
var apiKeyValue = "";
|
||||
Configuration.apiKey.TryGetValue (apiKey, out apiKeyValue);
|
||||
var apiKeyPrefix = "";
|
||||
if (Configuration.apiKeyPrefix.TryGetValue (apiKey, out apiKeyPrefix)) {
|
||||
return apiKeyPrefix + " " + apiKeyValue;
|
||||
} else {
|
||||
return apiKeyValue;
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Update parameters based on authentication
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<param name="QueryParams">
|
||||
Query parameters</param>
|
||||
///
|
||||
<param name="HeaderParams">
|
||||
Header parameters</param>
|
||||
///
|
||||
<param name="AuthSettings">
|
||||
Authentication settings</param>
|
||||
public void UpdateParamsForAuth(Dictionary
|
||||
<String
|
||||
, String> QueryParams, Dictionary
|
||||
<String
|
||||
, String> HeaderParams, string[] AuthSettings) {
|
||||
if (AuthSettings == null || AuthSettings.Length == 0)
|
||||
return;
|
||||
|
||||
foreach (string auth in AuthSettings) {
|
||||
// determine which one to use
|
||||
switch(auth) {
|
||||
{{#authMethods}}
|
||||
case "{{name}}":
|
||||
{{#isApiKey}}{{#isKeyInHeader}}HeaderParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}
|
||||
");{{/isKeyInHeader}}{{#isKeyInQuery}}QueryParams["{{keyParamName}}"] =
|
||||
GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}
|
||||
HeaderParams["Authorization"] = "Basic " + Base64Encode(Configuration.username + ":" +
|
||||
Configuration.password);{{/isBasic}}
|
||||
{{#isOAuth}}//TODO support oauth{{/isOAuth}}
|
||||
break;
|
||||
{{/authMethods}}
|
||||
default:
|
||||
//TODO show warning about security definition not found
|
||||
/// <summary>
|
||||
/// Update parameters based on authentication
|
||||
/// </summary>
|
||||
/// <param name="QueryParams">Query parameters</param>
|
||||
/// <param name="HeaderParams">Header parameters</param>
|
||||
/// <param name="AuthSettings">Authentication settings</param>
|
||||
public void UpdateParamsForAuth(Dictionary<String, String> QueryParams, Dictionary<String, String> HeaderParams, string[] AuthSettings) {
|
||||
if (AuthSettings == null || AuthSettings.Length == 0)
|
||||
return;
|
||||
|
||||
foreach (string auth in AuthSettings) {
|
||||
// determine which one to use
|
||||
switch(auth) {
|
||||
{{#authMethods}}
|
||||
case "{{name}}":
|
||||
{{#isApiKey}}{{#isKeyInHeader}}HeaderParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInHeader}}{{#isKeyInQuery}}QueryParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}HeaderParams["Authorization"] = "Basic " + Base64Encode(Configuration.username + ":" + Configuration.password);{{/isBasic}}
|
||||
{{#isOAuth}}//TODO support oauth{{/isOAuth}}
|
||||
break;
|
||||
}
|
||||
}
|
||||
{{/authMethods}}
|
||||
default:
|
||||
//TODO show warning about security definition not found
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Encode string in base64 format
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<param name="text">
|
||||
String to be encoded</param>
|
||||
public static string Base64Encode(string text) {
|
||||
var textByte = System.Text.Encoding.UTF8.GetBytes(text);
|
||||
return System.Convert.ToBase64String(textByte);
|
||||
}
|
||||
/// <summary>
|
||||
/// Encode string in base64 format
|
||||
/// </summary>
|
||||
/// <param name="text">String to be encoded</param>
|
||||
public static string Base64Encode(string text) {
|
||||
var textByte = System.Text.Encoding.UTF8.GetBytes(text);
|
||||
return System.Convert.ToBase64String(textByte);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +1,42 @@
|
||||
using System;
|
||||
|
||||
namespace {{invokerPackage}} {
|
||||
///
|
||||
<summary>
|
||||
/// API Exception
|
||||
///
|
||||
</summary>
|
||||
public class ApiException : Exception {
|
||||
///
|
||||
<summary>
|
||||
/// <summary>
|
||||
/// API Exception
|
||||
/// </summary>
|
||||
public class ApiException : Exception {
|
||||
/// <summary>
|
||||
/// Gets or sets the error code (HTTP status code)
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<value>The error code (HTTP status code).</value>
|
||||
public int ErrorCode { get; set; }
|
||||
/// </summary>
|
||||
/// <value>The error code (HTTP status code).</value>
|
||||
public int ErrorCode { get; set; }
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// <summary>
|
||||
/// Gets or sets the error content (body json object)
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<value>The error content (Http response body).</value>
|
||||
public dynamic ErrorContent { get; private set; }
|
||||
/// </summary>
|
||||
/// <value>The error content (Http response body).</value>
|
||||
public dynamic ErrorContent { get; private set; }
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Initializes a new instance of the
|
||||
<see cref="ApiException"/>
|
||||
class.
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<param name="basePath">The base path.</param>
|
||||
public ApiException() {}
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="basePath">The base path.</param>
|
||||
public ApiException() {}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Initializes a new instance of the
|
||||
<see cref="ApiException"/>
|
||||
class.
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<param name="errorCode">HTTP status code.</param>
|
||||
///
|
||||
<param name="message">Error message.</param>
|
||||
public ApiException(int errorCode, string message) : base(message) {
|
||||
this.ErrorCode = errorCode;
|
||||
}
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiException"/> class.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">HTTP status code.</param>
|
||||
/// <param name="message">Error message.</param>
|
||||
public ApiException(int errorCode, string message) : base(message) {
|
||||
this.ErrorCode = errorCode;
|
||||
}
|
||||
|
||||
public ApiException(int errorCode, string message, dynamic errorContent = null) : base(message) {
|
||||
this.ErrorCode = errorCode;
|
||||
this.ErrorContent = errorContent;
|
||||
}
|
||||
|
||||
}
|
||||
public ApiException(int errorCode, string message, dynamic errorContent = null) : base(message) {
|
||||
this.ErrorCode = errorCode;
|
||||
this.ErrorContent = errorContent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,62 +7,41 @@ using System.Text;
|
||||
using {{invokerPackage}};
|
||||
|
||||
namespace {{invokerPackage}} {
|
||||
///
|
||||
<summary>
|
||||
/// Represents a set of configuration settings
|
||||
///
|
||||
</summary>
|
||||
public class Configuration{
|
||||
/// <summary>
|
||||
/// Represents a set of configuration settings
|
||||
/// </summary>
|
||||
public class Configuration{
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// <summary>
|
||||
/// Gets or sets the API client. This is the default API client for making HTTP calls.
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<value>The API client.</value>
|
||||
public static ApiClient apiClient = new ApiClient();
|
||||
/// </summary>
|
||||
/// <value>The API client.</value>
|
||||
public static ApiClient apiClient = new ApiClient();
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// <summary>
|
||||
/// Gets or sets the username (HTTP basic authentication)
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<value>The username.</value>
|
||||
public static String username { get; set; }
|
||||
/// </summary>
|
||||
/// <value>The username.</value>
|
||||
public static String username { get; set; }
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// <summary>
|
||||
/// Gets or sets the password (HTTP basic authentication)
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<value>The password.</value>
|
||||
public static String password { get; set; }
|
||||
/// </summary>
|
||||
/// <value>The password.</value>
|
||||
public static String password { get; set; }
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Gets or sets the API key based on the authentication name
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<value>The API key.</value>
|
||||
public static Dictionary
|
||||
<String, String> apiKey = new Dictionary
|
||||
<String, String>();
|
||||
/// <summary>
|
||||
/// Gets or sets the API key based on the authentication name
|
||||
/// </summary>
|
||||
/// <value>The API key.</value>
|
||||
public static Dictionary<String, String> apiKey = new Dictionary<String, String>();
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<value>The prefix of the API key.</value>
|
||||
public static Dictionary
|
||||
<String, String> apiKeyPrefix = new Dictionary
|
||||
<String, String>();
|
||||
/// <summary>
|
||||
/// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name
|
||||
/// </summary>
|
||||
/// <value>The prefix of the API key.</value>
|
||||
public static Dictionary<String, String> apiKeyPrefix = new Dictionary<String, String>();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,212 +8,166 @@ using {{modelPackage}};
|
||||
{{/imports}}
|
||||
|
||||
namespace {{package}} {
|
||||
{{#operations}}
|
||||
{{#operations}}
|
||||
|
||||
public interface I{{classname}} {
|
||||
public interface I{{classname}} {
|
||||
{{#operation}}
|
||||
///
|
||||
<summary>
|
||||
/// {{summary}} {{notes}}
|
||||
///
|
||||
</summary>
|
||||
{{#allParams}}///
|
||||
<param name="{{paramName}}">{{description}}</param>{{/allParams}}
|
||||
///
|
||||
<returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
||||
{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
/// <summary>
|
||||
/// {{summary}} {{notes}}
|
||||
/// </summary>
|
||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>{{/allParams}}
|
||||
/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
||||
{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// {{summary}} {{notes}}
|
||||
///
|
||||
</summary>
|
||||
{{#allParams}}///
|
||||
<param name="{{paramName}}">{{description}}</param>{{/allParams}}
|
||||
///
|
||||
<returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
||||
{{#returnType}}Task<{{{returnType}}}>{{/returnType}}{{^returnType}}Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
/// <summary>
|
||||
/// {{summary}} {{notes}}
|
||||
/// </summary>
|
||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>{{/allParams}}
|
||||
/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
||||
{{#returnType}}Task<{{{returnType}}}>{{/returnType}}{{^returnType}}Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
{{/operation}}
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Represents a collection of functions to interact with the API endpoints
|
||||
///
|
||||
</summary>
|
||||
public class {{classname}} : I{{classname}} {
|
||||
/// <summary>
|
||||
/// Represents a collection of functions to interact with the API endpoints
|
||||
/// </summary>
|
||||
public class {{classname}} : I{{classname}} {
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Initializes a new instance of the
|
||||
<see cref="{{classname}}"/>
|
||||
class.
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<param name="apiClient"> an instance of ApiClient (optional)
|
||||
///
|
||||
<returns></returns>
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="{{classname}}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiClient"> an instance of ApiClient (optional)
|
||||
/// <returns></returns>
|
||||
public {{classname}}(ApiClient apiClient = null) {
|
||||
if (apiClient == null) { // use the default one in Configuration
|
||||
this.apiClient = Configuration.apiClient;
|
||||
} else {
|
||||
this.apiClient = apiClient;
|
||||
}
|
||||
if (apiClient == null) { // use the default one in Configuration
|
||||
this.apiClient = Configuration.apiClient;
|
||||
} else {
|
||||
this.apiClient = apiClient;
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Initializes a new instance of the
|
||||
<see cref="{{classname}}"/>
|
||||
class.
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<returns></returns>
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="{{classname}}"/> class.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public {{classname}}(String basePath)
|
||||
{
|
||||
this.apiClient = new ApiClient(basePath);
|
||||
this.apiClient = new ApiClient(basePath);
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Sets the base path of the API client.
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<value>The base path</value>
|
||||
/// <summary>
|
||||
/// Sets the base path of the API client.
|
||||
/// </summary>
|
||||
/// <value>The base path</value>
|
||||
public void SetBasePath(String basePath) {
|
||||
this.apiClient.basePath = basePath;
|
||||
this.apiClient.basePath = basePath;
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Gets the base path of the API client.
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<value>The base path</value>
|
||||
/// <summary>
|
||||
/// Gets the base path of the API client.
|
||||
/// </summary>
|
||||
/// <value>The base path</value>
|
||||
public String GetBasePath(String basePath) {
|
||||
return this.apiClient.basePath;
|
||||
return this.apiClient.basePath;
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Gets or sets the API client.
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<value>The API client</value>
|
||||
/// <summary>
|
||||
/// Gets or sets the API client.
|
||||
/// </summary>
|
||||
/// <value>The API client</value>
|
||||
public ApiClient apiClient {get; set;}
|
||||
|
||||
|
||||
{{#operation}}
|
||||
///
|
||||
<summary>
|
||||
/// {{summary}} {{notes}}
|
||||
///
|
||||
</summary>
|
||||
{{#allParams}}///
|
||||
<param name="{{paramName}}">{{description}}</param>{{/allParams}}
|
||||
///
|
||||
<returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
||||
public {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
|
||||
/// <summary>
|
||||
/// {{summary}} {{notes}}
|
||||
/// </summary>
|
||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>{{/allParams}}
|
||||
/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
||||
public {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
|
||||
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}");
|
||||
{{/required}}{{/allParams}}
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}");
|
||||
{{/required}}{{/allParams}}
|
||||
|
||||
var path = "{{path}}";
|
||||
path = path.Replace("{format}", "json");
|
||||
{{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", apiClient.ParameterToString({{{paramName}}}));
|
||||
{{/pathParams}}
|
||||
var path = "{{path}}";
|
||||
path = path.Replace("{format}", "json");
|
||||
{{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", apiClient.ParameterToString({{{paramName}}}));
|
||||
{{/pathParams}}
|
||||
|
||||
var queryParams = new Dictionary
|
||||
<String, String>();
|
||||
var headerParams = new Dictionary
|
||||
<String, String>();
|
||||
var formParams = new Dictionary
|
||||
<String, String>();
|
||||
var fileParams = new Dictionary
|
||||
<String, String>();
|
||||
String postBody = null;
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
{{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // query parameter
|
||||
{{/queryParams}}
|
||||
{{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // header parameter
|
||||
{{/headerParams}}
|
||||
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", {{paramName}});{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
|
||||
{{/formParams}}
|
||||
{{#bodyParam}}postBody = apiClient.Serialize({{paramName}}); // http body (model) parameter
|
||||
{{/bodyParam}}
|
||||
{{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // query parameter
|
||||
{{/queryParams}}
|
||||
{{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // header parameter
|
||||
{{/headerParams}}
|
||||
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", {{paramName}});{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
|
||||
{{/formParams}}
|
||||
{{#bodyParam}}postBody = apiClient.Serialize({{paramName}}); // http body (model) parameter
|
||||
{{/bodyParam}}
|
||||
|
||||
// authentication setting, if any
|
||||
String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
||||
// authentication setting, if any
|
||||
String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) apiClient.CallApi(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
|
||||
}
|
||||
{{#returnType}}return ({{{returnType}}}) apiClient.Deserialize(response.Content, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}
|
||||
return;{{/returnType}}
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// {{summary}} {{notes}}
|
||||
///
|
||||
</summary>
|
||||
{{#allParams}}///
|
||||
<param name="{{paramName}}">{{description}}</param>{{/allParams}}
|
||||
///
|
||||
<returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
||||
public async {{#returnType}}Task<{{{returnType}}}>{{/returnType}}{{^returnType}}Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
|
||||
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}");
|
||||
{{/required}}{{/allParams}}
|
||||
|
||||
var path = "{{path}}";
|
||||
path = path.Replace("{format}", "json");
|
||||
{{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", apiClient.ParameterToString({{{paramName}}}));
|
||||
{{/pathParams}}
|
||||
|
||||
var queryParams = new Dictionary
|
||||
<String, String>();
|
||||
var headerParams = new Dictionary
|
||||
<String, String>();
|
||||
var formParams = new Dictionary
|
||||
<String, String>();
|
||||
var fileParams = new Dictionary
|
||||
<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
{{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // query parameter
|
||||
{{/queryParams}}
|
||||
{{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // header parameter
|
||||
{{/headerParams}}
|
||||
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", {{paramName}});{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
|
||||
{{/formParams}}
|
||||
{{#bodyParam}}postBody = apiClient.Serialize({{paramName}}); // http body (model) parameter
|
||||
{{/bodyParam}}
|
||||
|
||||
// authentication setting, if any
|
||||
String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
|
||||
}
|
||||
{{#returnType}}return ({{{returnType}}}) ApiInvoker.Deserialize(response.Content, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}
|
||||
return;{{/returnType}}
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{#returnType}}return ({{{returnType}}}) apiClient.Deserialize(response.Content, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}
|
||||
return;{{/returnType}}
|
||||
}
|
||||
{{/operations}}
|
||||
|
||||
/// <summary>
|
||||
/// {{summary}} {{notes}}
|
||||
/// </summary>
|
||||
{{#allParams}}/// <param name="{{paramName}}">{{description}}</param>{{/allParams}}
|
||||
/// <returns>{{#returnType}}{{{returnType}}}{{/returnType}}</returns>
|
||||
public async {{#returnType}}Task<{{{returnType}}}>{{/returnType}}{{^returnType}}Task{{/returnType}} {{nickname}}Async ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
|
||||
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
if ({{paramName}} == null) throw new ApiException(400, "Missing required parameter '{{paramName}}' when calling {{nickname}}");
|
||||
{{/required}}{{/allParams}}
|
||||
|
||||
var path = "{{path}}";
|
||||
path = path.Replace("{format}", "json");
|
||||
{{#pathParams}}path = path.Replace("{" + "{{baseName}}" + "}", apiClient.ParameterToString({{{paramName}}}));
|
||||
{{/pathParams}}
|
||||
|
||||
var queryParams = new Dictionary<String, String>();
|
||||
var headerParams = new Dictionary<String, String>();
|
||||
var formParams = new Dictionary<String, String>();
|
||||
var fileParams = new Dictionary<String, String>();
|
||||
String postBody = null;
|
||||
|
||||
{{#queryParams}} if ({{paramName}} != null) queryParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // query parameter
|
||||
{{/queryParams}}
|
||||
{{#headerParams}} if ({{paramName}} != null) headerParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // header parameter
|
||||
{{/headerParams}}
|
||||
{{#formParams}}if ({{paramName}} != null) {{#isFile}}fileParams.Add("{{baseName}}", {{paramName}});{{/isFile}}{{^isFile}}formParams.Add("{{baseName}}", apiClient.ParameterToString({{paramName}})); // form parameter{{/isFile}}
|
||||
{{/formParams}}
|
||||
{{#bodyParam}}postBody = apiClient.Serialize({{paramName}}); // http body (model) parameter
|
||||
{{/bodyParam}}
|
||||
|
||||
// authentication setting, if any
|
||||
String[] authSettings = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
|
||||
|
||||
// make the HTTP request
|
||||
IRestResponse response = (IRestResponse) await apiClient.CallApiAsync(path, Method.{{httpMethod}}, queryParams, postBody, headerParams, formParams, fileParams, authSettings);
|
||||
if (((int)response.StatusCode) >= 400) {
|
||||
throw new ApiException ((int)response.StatusCode, "Error calling {{nickname}}: " + response.Content, response.Content);
|
||||
}
|
||||
{{#returnType}}return ({{{returnType}}}) apiClient.Deserialize(response.Content, typeof({{{returnType}}}));{{/returnType}}{{^returnType}}
|
||||
return;{{/returnType}}
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
}
|
||||
|
||||
@@ -6,52 +6,44 @@ using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
namespace {{package}} {
|
||||
{{#model}}
|
||||
namespace {{package}} {
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// {{description}}
|
||||
///
|
||||
</summary>
|
||||
[DataContract]
|
||||
public class {{classname}} {
|
||||
{{#vars}}
|
||||
{{#description}}/* {{{description}}} */{{/description}}
|
||||
[DataMember(Name="{{baseName}}", EmitDefaultValue=false)]
|
||||
public {{{datatype}}} {{name}} { get; set; }
|
||||
/// <summary>
|
||||
/// {{description}}
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class {{classname}} {
|
||||
{{#vars}}
|
||||
{{#description}}/* {{{description}}} */{{/description}}
|
||||
[DataMember(Name="{{baseName}}", EmitDefaultValue=false)]
|
||||
public {{{datatype}}} {{name}} { get; set; }
|
||||
|
||||
{{/vars}}
|
||||
{{/vars}}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Get the string presentation of the object
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<returns>String presentation of the object</returns>
|
||||
public override string ToString() {
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class {{classname}} {\n");
|
||||
{{#vars}}
|
||||
sb.Append(" {{name}}: ").Append({{name}}).Append("\n");
|
||||
{{/vars}}
|
||||
sb.Append("}\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// Get the string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>String presentation of the object</returns>
|
||||
public override string ToString() {
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("class {{classname}} {\n");
|
||||
{{#vars}}
|
||||
sb.Append(" {{name}}: ").Append({{name}}).Append("\n");
|
||||
{{/vars}}
|
||||
sb.Append("}\n");
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
///
|
||||
<summary>
|
||||
/// Get the JSON string presentation of the object
|
||||
///
|
||||
</summary>
|
||||
///
|
||||
<returns>JSON string presentation of the object</returns>
|
||||
public string ToJson() {
|
||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
}
|
||||
/// <summary>
|
||||
/// Get the JSON string presentation of the object
|
||||
/// </summary>
|
||||
/// <returns>JSON string presentation of the object</returns>
|
||||
public string ToJson() {
|
||||
return JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
}
|
||||
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
}
|
||||
|
||||
@@ -1,87 +1,87 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<application xmlns="http://ns.adobe.com/air/application/2.0">
|
||||
|
||||
<!-- Adobe AIR Application Descriptor File Template.
|
||||
<!-- Adobe AIR Application Descriptor File Template.
|
||||
|
||||
Specifies parameters for identifying, installing, and launching AIR applications.
|
||||
Specifies parameters for identifying, installing, and launching AIR applications.
|
||||
|
||||
xmlns - The Adobe AIR namespace: http://ns.adobe.com/air/application/2.0
|
||||
The last segment of the namespace specifies the version
|
||||
of the AIR runtime required for this application to run.
|
||||
xmlns - The Adobe AIR namespace: http://ns.adobe.com/air/application/2.0
|
||||
The last segment of the namespace specifies the version
|
||||
of the AIR runtime required for this application to run.
|
||||
|
||||
minimumPatchLevel - The minimum patch level of the AIR runtime required to run
|
||||
the application. Optional.
|
||||
-->
|
||||
|
||||
minimumPatchLevel - The minimum patch level of the AIR runtime required to run
|
||||
the application. Optional.
|
||||
-->
|
||||
<!-- A universally unique application identifier. Must be unique across all AIR applications.
|
||||
Using a reverse DNS-style name as the id is recommended. (Eg. com.example.ExampleApplication.) Required. -->
|
||||
<id>AirExecutorApp</id>
|
||||
|
||||
<!-- A universally unique application identifier. Must be unique across all AIR applications.
|
||||
Using a reverse DNS-style name as the id is recommended. (Eg. com.example.ExampleApplication.) Required. -->
|
||||
<id>AirExecutorApp</id>
|
||||
<!-- Used as the filename for the application. Required. -->
|
||||
<filename>AirExecutorApp</filename>
|
||||
|
||||
<!-- Used as the filename for the application. Required. -->
|
||||
<filename>AirExecutorApp</filename>
|
||||
<!-- The name that is displayed in the AIR application installer.
|
||||
May have multiple values for each language. See samples or xsd schema file. Optional. -->
|
||||
<name>AirExecutorApp</name>
|
||||
|
||||
<!-- The name that is displayed in the AIR application installer.
|
||||
May have multiple values for each language. See samples or xsd schema file. Optional. -->
|
||||
<name>AirExecutorApp</name>
|
||||
<!-- An application version designator (such as "v1", "2.5", or "Alpha 1"). Required. -->
|
||||
<version>v1</version>
|
||||
|
||||
<!-- An application version designator (such as "v1", "2.5", or "Alpha 1"). Required. -->
|
||||
<version>v1</version>
|
||||
<!-- Description, displayed in the AIR application installer.
|
||||
May have multiple values for each language. See samples or xsd schema file. Optional. -->
|
||||
<!-- <description></description> -->
|
||||
|
||||
<!-- Description, displayed in the AIR application installer.
|
||||
May have multiple values for each language. See samples or xsd schema file. Optional. -->
|
||||
<!-- <description></description> -->
|
||||
<!-- Copyright information. Optional -->
|
||||
<!-- <copyright></copyright> -->
|
||||
|
||||
<!-- Copyright information. Optional -->
|
||||
<!-- <copyright></copyright> -->
|
||||
<!-- Publisher ID. Used if you're updating an application created prior to 1.5.3 -->
|
||||
<!-- <publisherID></publisherID> -->
|
||||
|
||||
<!-- Publisher ID. Used if you're updating an application created prior to 1.5.3 -->
|
||||
<!-- <publisherID></publisherID> -->
|
||||
<!-- Settings for the application's initial window. Required. -->
|
||||
<initialWindow>
|
||||
<!-- The main SWF or HTML file of the application. Required. -->
|
||||
<!-- Note: In Flash Builder, the SWF reference is set automatically. -->
|
||||
<content>AirExecutorApp.swf</content>
|
||||
|
||||
<!-- The title of the main window. Optional. -->
|
||||
<!-- <title></title> -->
|
||||
|
||||
<!-- Settings for the application's initial window. Required. -->
|
||||
<initialWindow>
|
||||
<!-- The main SWF or HTML file of the application. Required. -->
|
||||
<!-- Note: In Flash Builder, the SWF reference is set automatically. -->
|
||||
<content>AirExecutorApp.swf</content>
|
||||
<!-- The type of system chrome to use (either "standard" or "none"). Optional. Default standard. -->
|
||||
<!-- <systemChrome></systemChrome> -->
|
||||
|
||||
<!-- The title of the main window. Optional. -->
|
||||
<!-- <title></title> -->
|
||||
<!-- Whether the window is transparent. Only applicable when systemChrome is none. Optional. Default false. -->
|
||||
<!-- <transparent></transparent> -->
|
||||
|
||||
<!-- The type of system chrome to use (either "standard" or "none"). Optional. Default standard. -->
|
||||
<!-- <systemChrome></systemChrome> -->
|
||||
<!-- Whether the window is initially visible. Optional. Default false. -->
|
||||
<!-- <visible></visible> -->
|
||||
|
||||
<!-- Whether the window is transparent. Only applicable when systemChrome is none. Optional. Default false. -->
|
||||
<!-- <transparent></transparent> -->
|
||||
<!-- Whether the user can minimize the window. Optional. Default true. -->
|
||||
<!-- <minimizable></minimizable> -->
|
||||
|
||||
<!-- Whether the window is initially visible. Optional. Default false. -->
|
||||
<!-- <visible></visible> -->
|
||||
<!-- Whether the user can maximize the window. Optional. Default true. -->
|
||||
<!-- <maximizable></maximizable> -->
|
||||
|
||||
<!-- Whether the user can minimize the window. Optional. Default true. -->
|
||||
<!-- <minimizable></minimizable> -->
|
||||
<!-- Whether the user can resize the window. Optional. Default true. -->
|
||||
<!-- <resizable></resizable> -->
|
||||
|
||||
<!-- Whether the user can maximize the window. Optional. Default true. -->
|
||||
<!-- <maximizable></maximizable> -->
|
||||
<!-- The window's initial width in pixels. Optional. -->
|
||||
<!-- <width></width> -->
|
||||
|
||||
<!-- Whether the user can resize the window. Optional. Default true. -->
|
||||
<!-- <resizable></resizable> -->
|
||||
<!-- The window's initial height in pixels. Optional. -->
|
||||
<!-- <height></height> -->
|
||||
|
||||
<!-- The window's initial width in pixels. Optional. -->
|
||||
<!-- <width></width> -->
|
||||
<!-- The window's initial x position. Optional. -->
|
||||
<!-- <x></x> -->
|
||||
|
||||
<!-- The window's initial height in pixels. Optional. -->
|
||||
<!-- <height></height> -->
|
||||
<!-- The window's initial y position. Optional. -->
|
||||
<!-- <y></y> -->
|
||||
|
||||
<!-- The window's initial x position. Optional. -->
|
||||
<!-- <x></x> -->
|
||||
<!-- The window's minimum size, specified as a width/height pair in pixels, such as "400 200". Optional. -->
|
||||
<!-- <minSize></minSize> -->
|
||||
|
||||
<!-- The window's initial y position. Optional. -->
|
||||
<!-- <y></y> -->
|
||||
|
||||
<!-- The window's minimum size, specified as a width/height pair in pixels, such as "400 200". Optional. -->
|
||||
<!-- <minSize></minSize> -->
|
||||
|
||||
<!-- The window's initial maximum size, specified as a width/height pair in pixels, such as "1600 1200". Optional. -->
|
||||
<!-- <maxSize></maxSize> -->
|
||||
</initialWindow>
|
||||
<!-- The window's initial maximum size, specified as a width/height pair in pixels, such as "1600 1200". Optional. -->
|
||||
<!-- <maxSize></maxSize> -->
|
||||
</initialWindow>
|
||||
|
||||
<!-- We recommend omitting the supportedProfiles element, -->
|
||||
<!-- which in turn permits your application to be deployed to all -->
|
||||
@@ -90,57 +90,57 @@
|
||||
<!-- only the profiles which your application does support. -->
|
||||
<!-- <supportedProfiles>desktop extendedDesktop mobileDevice extendedMobileDevice</supportedProfiles> -->
|
||||
|
||||
<!-- The subpath of the standard default installation location to use. Optional. -->
|
||||
<!-- <installFolder></installFolder> -->
|
||||
<!-- The subpath of the standard default installation location to use. Optional. -->
|
||||
<!-- <installFolder></installFolder> -->
|
||||
|
||||
<!-- The subpath of the Programs menu to use. (Ignored on operating systems without a Programs menu.) Optional. -->
|
||||
<!-- <programMenuFolder></programMenuFolder> -->
|
||||
<!-- The subpath of the Programs menu to use. (Ignored on operating systems without a Programs menu.) Optional. -->
|
||||
<!-- <programMenuFolder></programMenuFolder> -->
|
||||
|
||||
<!-- The icon the system uses for the application. For at least one resolution,
|
||||
specify the path to a PNG file included in the AIR package. Optional. -->
|
||||
<!-- <icon>
|
||||
<image16x16></image16x16>
|
||||
<image32x32></image32x32>
|
||||
<image48x48></image48x48>
|
||||
<image128x128></image128x128>
|
||||
</icon> -->
|
||||
<!-- The icon the system uses for the application. For at least one resolution,
|
||||
specify the path to a PNG file included in the AIR package. Optional. -->
|
||||
<!-- <icon>
|
||||
<image16x16></image16x16>
|
||||
<image32x32></image32x32>
|
||||
<image48x48></image48x48>
|
||||
<image128x128></image128x128>
|
||||
</icon> -->
|
||||
|
||||
<!-- Whether the application handles the update when a user double-clicks an update version
|
||||
of the AIR file (true), or the default AIR application installer handles the update (false).
|
||||
Optional. Default false. -->
|
||||
<!-- <customUpdateUI></customUpdateUI> -->
|
||||
<!-- Whether the application handles the update when a user double-clicks an update version
|
||||
of the AIR file (true), or the default AIR application installer handles the update (false).
|
||||
Optional. Default false. -->
|
||||
<!-- <customUpdateUI></customUpdateUI> -->
|
||||
|
||||
<!-- Whether the application can be launched when the user clicks a link in a web browser.
|
||||
Optional. Default false. -->
|
||||
<!-- <allowBrowserInvocation></allowBrowserInvocation> -->
|
||||
|
||||
<!-- Whether the application can be launched when the user clicks a link in a web browser.
|
||||
Optional. Default false. -->
|
||||
<!-- <allowBrowserInvocation></allowBrowserInvocation> -->
|
||||
<!-- Listing of file types for which the application can register. Optional. -->
|
||||
<!-- <fileTypes> -->
|
||||
|
||||
<!-- Listing of file types for which the application can register. Optional. -->
|
||||
<!-- <fileTypes> -->
|
||||
<!-- Defines one file type. Optional. -->
|
||||
<!-- <fileType> -->
|
||||
|
||||
<!-- Defines one file type. Optional. -->
|
||||
<!-- <fileType> -->
|
||||
<!-- The name that the system displays for the registered file type. Required. -->
|
||||
<!-- <name></name> -->
|
||||
|
||||
<!-- The name that the system displays for the registered file type. Required. -->
|
||||
<!-- <name></name> -->
|
||||
|
||||
<!-- The extension to register. Required. -->
|
||||
<!-- <extension></extension> -->
|
||||
|
||||
<!-- The description of the file type. Optional. -->
|
||||
<!-- <description></description> -->
|
||||
|
||||
<!-- The MIME content type. -->
|
||||
<!-- <contentType></contentType> -->
|
||||
|
||||
<!-- The icon to display for the file type. Optional. -->
|
||||
<!-- <icon>
|
||||
<image16x16></image16x16>
|
||||
<image32x32></image32x32>
|
||||
<image48x48></image48x48>
|
||||
<image128x128></image128x128>
|
||||
</icon> -->
|
||||
|
||||
<!-- </fileType> -->
|
||||
<!-- </fileTypes> -->
|
||||
<!-- The extension to register. Required. -->
|
||||
<!-- <extension></extension> -->
|
||||
|
||||
<!-- The description of the file type. Optional. -->
|
||||
<!-- <description></description> -->
|
||||
|
||||
<!-- The MIME content type. -->
|
||||
<!-- <contentType></contentType> -->
|
||||
|
||||
<!-- The icon to display for the file type. Optional. -->
|
||||
<!-- <icon>
|
||||
<image16x16></image16x16>
|
||||
<image32x32></image32x32>
|
||||
<image48x48></image48x48>
|
||||
<image128x128></image128x128>
|
||||
</icon> -->
|
||||
|
||||
<!-- </fileType> -->
|
||||
<!-- </fileTypes> -->
|
||||
|
||||
</application>
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package io.swagger.event {
|
||||
import io.swagger.event.Response;
|
||||
|
||||
import flash.events.Event;
|
||||
|
||||
/**
|
||||
* Event dispatched by the SDK to communicate success events and failure events.
|
||||
* If a custom dispatcher has been assigned by the consumer on the generated client then the dispatcher dispatches
|
||||
* the ApiClientEvent to indicate success or failure of the invocation using the Response
|
||||
*/
|
||||
public class ApiClientEvent extends Event {
|
||||
public class ApiClientEvent extends Event{
|
||||
|
||||
/**
|
||||
* Event type to indicate a unsuccessful invocation
|
||||
@@ -15,17 +19,18 @@ public class ApiClientEvent extends Event {
|
||||
* Event type to indicate a successful invocation
|
||||
*/
|
||||
public static const SUCCESS_EVENT:String = "successfulInvocation";
|
||||
|
||||
public function ApiClientEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false) {
|
||||
super(type, bubbles, cancelable);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Response object which contains response info
|
||||
*/
|
||||
public var response:Response;
|
||||
public var response: Response;
|
||||
/**
|
||||
* Any additional info
|
||||
*/
|
||||
public var message:String;
|
||||
|
||||
public function ApiClientEvent(type:String,bubbles:Boolean = false,cancelable:Boolean = false) {
|
||||
super(type, bubbles, cancelable);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
package io.swagger.exception {
|
||||
public class ApiError extends Error {
|
||||
public function ApiError(id:* = 0, message:* = "") {
|
||||
super(message, id);
|
||||
}
|
||||
}
|
||||
package io.swagger.exception
|
||||
{
|
||||
public class ApiError extends Error
|
||||
{
|
||||
public function ApiError(id:*=0, message:*="")
|
||||
{
|
||||
super(message,id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,34 @@
|
||||
package io.swagger.exception {
|
||||
public class ApiErrorCodes {
|
||||
/**
|
||||
* System exception.
|
||||
*/
|
||||
public static const SYSTEM_EXCEPTION:Number = 0;
|
||||
|
||||
/**
|
||||
* With Arguments as current key.
|
||||
*/
|
||||
public static const API_KEY_NOT_VALID:Number = 1000;
|
||||
/**
|
||||
* With arguments as current token value
|
||||
*/
|
||||
public static const AUTH_TOKEN_NOT_VALID:Number = 1001;
|
||||
/**
|
||||
* With arguments as input JSON and output class anme
|
||||
*/
|
||||
public static const ERROR_CONVERTING_JSON_TO_JAVA:Number = 1002;
|
||||
/**
|
||||
* With arguments as JAVA class name
|
||||
*/
|
||||
public static const ERROR_CONVERTING_JAVA_TO_JSON:Number = 1003;
|
||||
|
||||
public static const ERROR_FROM_WEBSERVICE_CALL:Number = 1004;
|
||||
/**
|
||||
* With arguments as current API server name
|
||||
*/
|
||||
public static const API_SERVER_NOT_VALID:Number = 1005;
|
||||
|
||||
}
|
||||
package io.swagger.exception
|
||||
{
|
||||
public class ApiErrorCodes
|
||||
{
|
||||
/**
|
||||
* System exception.
|
||||
*/
|
||||
public static const SYSTEM_EXCEPTION: Number = 0;
|
||||
|
||||
/**
|
||||
* With Arguments as current key.
|
||||
*/
|
||||
public static const API_KEY_NOT_VALID: Number = 1000;
|
||||
/**
|
||||
* With arguments as current token value
|
||||
*/
|
||||
public static const AUTH_TOKEN_NOT_VALID: Number = 1001;
|
||||
/**
|
||||
* With arguments as input JSON and output class anme
|
||||
*/
|
||||
public static const ERROR_CONVERTING_JSON_TO_JAVA: Number = 1002;
|
||||
/**
|
||||
* With arguments as JAVA class name
|
||||
*/
|
||||
public static const ERROR_CONVERTING_JAVA_TO_JSON: Number = 1003;
|
||||
|
||||
public static const ERROR_FROM_WEBSERVICE_CALL: Number = 1004;
|
||||
/**
|
||||
* With arguments as current API server name
|
||||
*/
|
||||
public static const API_SERVER_NOT_VALID: Number = 1005;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
package io.swagger.common {
|
||||
import io.swagger.common.ApiUserCredentials;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Internal class for the Rest client
|
||||
@@ -10,17 +12,17 @@ internal class ApiUrlHelper {
|
||||
|
||||
private static const HTTP_URL_PREFIX:String = "http://";
|
||||
|
||||
internal static function appendTokenInfo(restUrl:String, requestHeader:Object, credentials:ApiUserCredentials):String {
|
||||
internal static function appendTokenInfo(restUrl:String, requestHeader: Object, credentials: ApiUserCredentials): String {
|
||||
//checks for the presence api credentials on client initialization and not repeated here
|
||||
if (restUrl.indexOf("?") == -1) {
|
||||
if(restUrl.indexOf("?") == -1){
|
||||
restUrl += ( "?" + API_URL_KEY + "=" + credentials.apiToken );
|
||||
}
|
||||
else {
|
||||
else{
|
||||
restUrl += ( "&" + API_URL_KEY + "=" + credentials.apiToken );
|
||||
}
|
||||
requestHeader.api_key = credentials.apiToken;
|
||||
|
||||
if (credentials.authToken != null && credentials.authToken != "") {
|
||||
if(credentials.authToken != null && credentials.authToken != ""){
|
||||
restUrl += ( "&" + AUTH_TOKEN_URL_KEY + "=" + credentials.authToken );
|
||||
requestHeader.auth_token = credentials.authToken;
|
||||
}
|
||||
@@ -28,7 +30,7 @@ internal class ApiUrlHelper {
|
||||
return restUrl;
|
||||
}
|
||||
|
||||
internal static function getProxyUrl(hostName:String, proxyPath:String):String {
|
||||
internal static function getProxyUrl(hostName: String, proxyPath: String): String{
|
||||
if (hostName(hostName.length - 1) == "/") //remove trailing slash
|
||||
{
|
||||
hostName = hostName.substring(0, hostName.length - 1);
|
||||
|
||||
@@ -5,24 +5,6 @@ package io.swagger.common {
|
||||
*
|
||||
*/
|
||||
public class ApiUserCredentials {
|
||||
/**
|
||||
* Constructor of ApiUserCredentials
|
||||
* @param apiToken An apitoken that is passed along with the requests
|
||||
* @param authToken A valid auth_token which could necessary for certain operations
|
||||
* @param hostName The host name for the Rest API eg. api.companyName.com
|
||||
* @param userId The userId which is required for certain operations - currently, get user lists
|
||||
*/
|
||||
public function ApiUserCredentials(hostName:String, apiPath:String, apiToken:String,
|
||||
authToken:String = null, userId:Number = -1, apiProxyServerUrl:String = "",
|
||||
proxyPath:String = null) {
|
||||
this.hostName = hostName;
|
||||
this.apiToken = apiToken;
|
||||
this.authToken = authToken;
|
||||
this.userId = userId;
|
||||
this.apiPath = apiPath;
|
||||
this.apiProxyServerUrl = apiProxyServerUrl;
|
||||
this.proxyPath = proxyPath;
|
||||
}
|
||||
/**
|
||||
* An apitoken that is passed along with the requests
|
||||
*/
|
||||
@@ -39,21 +21,43 @@ public class ApiUserCredentials {
|
||||
* The host name for the Rest API eg. api.companyName.com
|
||||
*/
|
||||
public var hostName:String;
|
||||
|
||||
/**
|
||||
* The base path to the api resources - used along with the hostname
|
||||
* eg. /v4
|
||||
*/
|
||||
public var apiPath: String;
|
||||
|
||||
/**
|
||||
* The base path to the blazeds proxy
|
||||
* eg. /v4/messagebroker/restproxy
|
||||
*/
|
||||
public var proxyPath: String;
|
||||
|
||||
/**
|
||||
* If a proxy server has been set up for the services specify the URL here. This value is used when the Api is invoked with
|
||||
* the value useProxy as true
|
||||
*/
|
||||
public var apiProxyServerUrl: String;
|
||||
|
||||
/**
|
||||
* The base path to the api resources - used along with the hostname
|
||||
* eg. /v4
|
||||
* Constructor of ApiUserCredentials
|
||||
* @param apiToken An apitoken that is passed along with the requests
|
||||
* @param authToken A valid auth_token which could necessary for certain operations
|
||||
* @param hostName The host name for the Rest API eg. api.companyName.com
|
||||
* @param userId The userId which is required for certain operations - currently, get user lists
|
||||
*/
|
||||
public var apiPath:String;
|
||||
/**
|
||||
* The base path to the blazeds proxy
|
||||
* eg. /v4/messagebroker/restproxy
|
||||
*/
|
||||
public var proxyPath:String;
|
||||
/**
|
||||
* If a proxy server has been set up for the services specify the URL here. This value is used when the Api is invoked with
|
||||
* the value useProxy as true
|
||||
*/
|
||||
public var apiProxyServerUrl:String;
|
||||
public function ApiUserCredentials(hostName: String, apiPath: String, apiToken: String,
|
||||
authToken: String = null, userId: Number = -1, apiProxyServerUrl: String="",
|
||||
proxyPath: String = null) {
|
||||
this.hostName = hostName;
|
||||
this.apiToken = apiToken;
|
||||
this.authToken = authToken;
|
||||
this.userId = userId;
|
||||
this.apiPath = apiPath;
|
||||
this.apiProxyServerUrl = apiProxyServerUrl;
|
||||
this.proxyPath = proxyPath;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package io.swagger.common {
|
||||
public interface ListWrapper {
|
||||
|
||||
function getList():Array;
|
||||
|
||||
}
|
||||
package io.swagger.common
|
||||
{
|
||||
public interface ListWrapper
|
||||
{
|
||||
|
||||
function getList(): Array;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,47 +6,50 @@ package io.swagger.event {
|
||||
*/
|
||||
public class Response {
|
||||
|
||||
/**
|
||||
* Indicates whether the invoked operation failed or succeeded
|
||||
*/
|
||||
public var isSuccess:Boolean;
|
||||
|
||||
/**
|
||||
* The payload of the succesful operation eg. a Word in a WordRequest
|
||||
*/
|
||||
public var payload:Object;
|
||||
|
||||
/**
|
||||
* Error message in case of failure
|
||||
*/
|
||||
public var errorMessage:String;
|
||||
|
||||
/**
|
||||
* A request Id that was passed in by the user as a param when invoking the operation
|
||||
*/
|
||||
public var requestId:String;
|
||||
private static const API_ERROR_MSG:String = "Api error response: ";
|
||||
|
||||
private static function getFriendlyMessage(errorMessage:String):String {
|
||||
var result:String = errorMessage;
|
||||
if (errorMessage == null)
|
||||
public function Response(isSuccessful: Boolean, payload: Object = null, errorMessage: String = null, requestId: String = null) {
|
||||
this.isSuccess = isSuccessful;
|
||||
this.payload = payload;
|
||||
this.errorMessage = getFriendlyMessage(errorMessage);
|
||||
}
|
||||
|
||||
private static function getFriendlyMessage(errorMessage: String): String{
|
||||
var result: String = errorMessage;
|
||||
if(errorMessage == null)
|
||||
return null;
|
||||
var errorCode:String;
|
||||
var errorCodeArray:Array = errorMessage.match(/(?<=HTTP\/1.1 )[0-9][0-9][0-9]/);
|
||||
if (errorCodeArray != null && errorCodeArray.length == 1) {
|
||||
var errorCode: String;
|
||||
var errorCodeArray: Array = errorMessage.match(/(?<=HTTP\/1.1 )[0-9][0-9][0-9]/);
|
||||
if(errorCodeArray != null && errorCodeArray.length == 1){
|
||||
errorCode = String(errorCodeArray[0]);
|
||||
}
|
||||
var msgArray:Array = errorMessage.match(/(?<=HTTP\/1.1 [0-9][0-9][0-9] )[^]*/);
|
||||
if (msgArray != null && msgArray.length == 1) {
|
||||
var msgArray: Array = errorMessage.match(/(?<=HTTP\/1.1 [0-9][0-9][0-9] )[^]*/);
|
||||
if(msgArray != null && msgArray.length == 1){
|
||||
result = API_ERROR_MSG + String(msgArray[0]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public function Response(isSuccessful:Boolean, payload:Object = null, errorMessage:String = null, requestId:String = null) {
|
||||
this.isSuccess = isSuccessful;
|
||||
this.payload = payload;
|
||||
this.errorMessage = getFriendlyMessage(errorMessage);
|
||||
}
|
||||
/**
|
||||
* Indicates whether the invoked operation failed or succeeded
|
||||
*/
|
||||
public var isSuccess:Boolean;
|
||||
/**
|
||||
* The payload of the succesful operation eg. a Word in a WordRequest
|
||||
*/
|
||||
public var payload:Object;
|
||||
/**
|
||||
* Error message in case of failure
|
||||
*/
|
||||
public var errorMessage:String;
|
||||
/**
|
||||
* A request Id that was passed in by the user as a param when invoking the operation
|
||||
*/
|
||||
public var requestId:String;
|
||||
|
||||
public function toString():String {
|
||||
public function toString(): String {
|
||||
return "Response (requestId:" + requestId + "; isSuccess:" + isSuccess + "; errorMessage:" + errorMessage + "; payload:" + payload + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +1,75 @@
|
||||
package io.swagger.common {
|
||||
public class SwaggerApi extends EventDispatcher {
|
||||
package io.swagger.common
|
||||
{
|
||||
import io.swagger.common.ApiUserCredentials;
|
||||
|
||||
import flash.events.EventDispatcher;
|
||||
import flash.events.IEventDispatcher;
|
||||
|
||||
import mx.utils.UIDUtil;
|
||||
|
||||
public class SwaggerApi extends EventDispatcher
|
||||
{
|
||||
|
||||
protected var _apiUsageCredentials:ApiUserCredentials;
|
||||
protected var _apiEventNotifier:EventDispatcher;
|
||||
protected var _apiInvoker: ApiInvoker;
|
||||
|
||||
protected var _useProxyServer: Boolean = false;
|
||||
|
||||
/**
|
||||
* Method for returning the path value
|
||||
* For a string value an empty value is returned if the value is null
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
protected static function toPathValue(value:Object):String {
|
||||
if (value is Array) {
|
||||
return arrayToPathValue(value as Array);
|
||||
}
|
||||
return value == null ? "" : value.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for returning a path value
|
||||
* For a list of objects a comma separated string is returned
|
||||
* @param objects
|
||||
* @return
|
||||
*/
|
||||
protected static function arrayToPathValue(objects:Array):String {
|
||||
var out:String = "";
|
||||
|
||||
return objects.join(",");
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the api client
|
||||
* @param apiCredentials Wrapper object for tokens and hostName required towards authentication
|
||||
* @param eventDispatcher Optional event dispatcher that when provided is used by the SDK to dispatch any Response
|
||||
*/
|
||||
public function SwaggerApi(apiCredentials:ApiUserCredentials, eventDispatcher:EventDispatcher = null) {
|
||||
super();
|
||||
_apiUsageCredentials = apiCredentials;
|
||||
_apiEventNotifier = eventDispatcher;
|
||||
}
|
||||
protected var _apiUsageCredentials:ApiUserCredentials;
|
||||
protected var _apiEventNotifier:EventDispatcher;
|
||||
protected var _apiInvoker:ApiInvoker;
|
||||
protected var _useProxyServer:Boolean = false;
|
||||
|
||||
public function useProxyServer(value:Boolean, proxyServerUrl:String = null):void {
|
||||
_useProxyServer = value;
|
||||
}
|
||||
|
||||
protected function getApiInvoker():ApiInvoker {
|
||||
if (_apiInvoker == null) {
|
||||
if (_apiEventNotifier == null) {
|
||||
_apiEventNotifier = this;
|
||||
}
|
||||
_apiInvoker = new ApiInvoker(_apiUsageCredentials, _apiEventNotifier, _useProxyServer);
|
||||
}
|
||||
return _apiInvoker;
|
||||
}
|
||||
|
||||
protected function getUniqueId():String {
|
||||
return UIDUtil.createUID();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the api client
|
||||
* @param apiCredentials Wrapper object for tokens and hostName required towards authentication
|
||||
* @param eventDispatcher Optional event dispatcher that when provided is used by the SDK to dispatch any Response
|
||||
*/
|
||||
public function SwaggerApi(apiCredentials: ApiUserCredentials, eventDispatcher: EventDispatcher = null) {
|
||||
super();
|
||||
_apiUsageCredentials = apiCredentials;
|
||||
_apiEventNotifier = eventDispatcher;
|
||||
}
|
||||
|
||||
public function useProxyServer(value:Boolean, proxyServerUrl: String = null):void {
|
||||
_useProxyServer = value;
|
||||
}
|
||||
|
||||
protected function getApiInvoker():ApiInvoker {
|
||||
if(_apiInvoker == null){
|
||||
if(_apiEventNotifier == null){
|
||||
_apiEventNotifier = this;
|
||||
}
|
||||
_apiInvoker = new ApiInvoker(_apiUsageCredentials, _apiEventNotifier, _useProxyServer);
|
||||
}
|
||||
return _apiInvoker;
|
||||
}
|
||||
|
||||
protected function getUniqueId():String {
|
||||
return UIDUtil.createUID();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for returning the path value
|
||||
* For a string value an empty value is returned if the value is null
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
protected static function toPathValue(value: Object): String {
|
||||
if(value is Array){
|
||||
return arrayToPathValue(value as Array);
|
||||
}
|
||||
return value == null ? "" : value.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for returning a path value
|
||||
* For a list of objects a comma separated string is returned
|
||||
* @param objects
|
||||
* @return
|
||||
*/
|
||||
protected static function arrayToPathValue(objects: Array): String {
|
||||
var out: String = "";
|
||||
|
||||
return objects.join(",");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,28 @@
|
||||
package io.swagger.common {
|
||||
public class XMLWriter {
|
||||
public function XMLWriter() {
|
||||
xml = <obj/>;
|
||||
}
|
||||
public var xml:XML;
|
||||
|
||||
public function reset():void {
|
||||
xml = new XML();
|
||||
}
|
||||
|
||||
public function addProperty(propertyName:String, propertyValue:String):XML {
|
||||
var xmlProperty:XML = <new/>
|
||||
xmlProperty.setName(propertyName);
|
||||
xmlProperty.appendChild(propertyValue);
|
||||
xml.appendChild(xmlProperty);
|
||||
return xmlProperty;
|
||||
}
|
||||
|
||||
public function addAttribute(propertyName:String, attribute:String, attributeValue:String):void {
|
||||
xml.elements(propertyName)[0].@[attribute] = attributeValue;
|
||||
}
|
||||
}
|
||||
package io.swagger.common
|
||||
{
|
||||
public class XMLWriter
|
||||
{
|
||||
public var xml:XML;
|
||||
|
||||
public function XMLWriter()
|
||||
{
|
||||
xml=<obj/>;
|
||||
}
|
||||
|
||||
public function reset():void {
|
||||
xml=new XML();
|
||||
}
|
||||
|
||||
public function addProperty(propertyName:String, propertyValue:String):XML {
|
||||
var xmlProperty:XML=<new/>
|
||||
xmlProperty.setName(propertyName);
|
||||
xmlProperty.appendChild(propertyValue);
|
||||
xml.appendChild(xmlProperty);
|
||||
return xmlProperty;
|
||||
}
|
||||
|
||||
public function addAttribute(propertyName:String, attribute:String, attributeValue:String):void {
|
||||
xml.elements(propertyName)[0].@[attribute]=attributeValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,26 +15,26 @@ import flash.utils.Dictionary;
|
||||
import flash.events.EventDispatcher;
|
||||
|
||||
{{#operations}}
|
||||
public class {{classname}} extends SwaggerApi {
|
||||
public class {{classname}} extends SwaggerApi {
|
||||
/**
|
||||
* Constructor for the {{classname}} api client
|
||||
* @param apiCredentials Wrapper object for tokens and hostName required towards authentication
|
||||
* @param eventDispatcher Optional event dispatcher that when provided is used by the SDK to dispatch any Response
|
||||
*/
|
||||
public function {{classname}}(apiCredentials: ApiUserCredentials, eventDispatcher: EventDispatcher = null) {
|
||||
super(apiCredentials, eventDispatcher);
|
||||
super(apiCredentials, eventDispatcher);
|
||||
}
|
||||
|
||||
{{#operation}}
|
||||
{{#operation}}
|
||||
public static const event_{{nickname}}: String = "{{nickname}}";
|
||||
{{/operation}}
|
||||
{{/operation}}
|
||||
|
||||
{{#operation}}
|
||||
{{#operation}}
|
||||
|
||||
/*
|
||||
* Returns {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}
|
||||
*/
|
||||
public function {{nickname}} ({{#allParams}}{{paramName}}: {{{dataType}}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#hasMore}}, {{/hasMore}}{{/allParams}}): String {
|
||||
/*
|
||||
* Returns {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}
|
||||
*/
|
||||
public function {{nickname}} ({{#allParams}}{{paramName}}: {{{dataType}}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#hasMore}}, {{/hasMore}}{{/allParams}}): String {
|
||||
// create path and map variables
|
||||
var path: String = "{{path}}".replace(/{format}/g,"xml"){{#pathParams}}.replace("{" + "{{paramName}}" + "}", getApiInvoker().escapeString({{{paramName}}})){{/pathParams}};
|
||||
|
||||
@@ -43,14 +43,14 @@ import flash.events.EventDispatcher;
|
||||
var headerParams: Dictionary = new Dictionary();
|
||||
|
||||
{{#requiredParamCount}}
|
||||
// verify required params are set
|
||||
if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) {
|
||||
throw new ApiError(400, "missing required params");
|
||||
// verify required params are set
|
||||
if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) {
|
||||
throw new ApiError(400, "missing required params");
|
||||
}
|
||||
{{/requiredParamCount}}
|
||||
|
||||
{{#queryParams}}if("null" != String({{paramName}}))
|
||||
queryParams["{{paramName}}"] = toPathValue({{paramName}});
|
||||
queryParams["{{paramName}}"] = toPathValue({{paramName}});
|
||||
{{/queryParams}}
|
||||
|
||||
{{#headerParams}}headerParams["{{paramName}}"] = toPathValue({{paramName}});
|
||||
@@ -66,8 +66,8 @@ import flash.events.EventDispatcher;
|
||||
token.returnType = {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}null {{/returnType}};
|
||||
return requestId;
|
||||
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.wordnik.client.model {
|
||||
|
||||
public class FacetValue {
|
||||
public var value:String = null;
|
||||
public var count:Number = 0;
|
||||
}
|
||||
public class FacetValue {
|
||||
public var value: String = null;
|
||||
public var count: Number = 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,37 +4,37 @@ package {{package}} {
|
||||
{{/imports}}
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
[XmlRootNode(name="{{classname}}")]
|
||||
public class {{classname}} {
|
||||
{{#vars}}
|
||||
{{#model}}
|
||||
[XmlRootNode(name="{{classname}}")]
|
||||
public class {{classname}} {
|
||||
{{#vars}}
|
||||
|
||||
{{#description}}/* {{description}} */
|
||||
{{/description}}
|
||||
{{#description}}/* {{description}} */
|
||||
{{/description}}
|
||||
|
||||
{{#isList}}
|
||||
// This declaration below of _{{name}}_obj_class is to force flash compiler to include this class
|
||||
private var _{{name}}_obj_class: {{baseType}} = null;
|
||||
[XmlElementWrapper(name="{{name}}")]
|
||||
[XmlElements(name="{{nameSingular}}", type="{{baseType}}")]
|
||||
{{/isList}}
|
||||
{{#isNotContainer}}[XmlElement(name="{{name}}")]
|
||||
{{/isNotContainer}}
|
||||
public var {{name}}: {{{datatype}}} = {{{defaultValue}}};
|
||||
{{#isList}}
|
||||
// This declaration below of _{{name}}_obj_class is to force flash compiler to include this class
|
||||
private var _{{name}}_obj_class: {{baseType}} = null;
|
||||
[XmlElementWrapper(name="{{name}}")]
|
||||
[XmlElements(name="{{nameSingular}}", type="{{baseType}}")]
|
||||
{{/isList}}
|
||||
{{#isNotContainer}}[XmlElement(name="{{name}}")]
|
||||
{{/isNotContainer}}
|
||||
public var {{name}}: {{{datatype}}} = {{{defaultValue}}};
|
||||
|
||||
{{/vars}}
|
||||
{{/vars}}
|
||||
|
||||
public function toString(): String {
|
||||
var str: String = "{{classname}}: ";
|
||||
{{#vars}}
|
||||
var str: String = "{{classname}}: ";
|
||||
{{#vars}}
|
||||
str += " ({{name}}: " + {{name}} + ")";
|
||||
{{/vars}}
|
||||
return str;
|
||||
{{/vars}}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,19 +5,19 @@ import io.swagger.common.ListWrapper;
|
||||
{{/imports}}
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
public class {{classname}}List implements ListWrapper {
|
||||
{{#model}}
|
||||
public class {{classname}}List implements ListWrapper {
|
||||
// This declaration below of _{{name}}_obj_class is to force flash compiler to include this class
|
||||
private var _{{classVarName}}_obj_class: {{package}}.{{classname}} = null;
|
||||
[XmlElements(name="{{classVarName}}", type="{{package}}.{{classname}}")]
|
||||
public var {{classVarName}}: Array = new Array();
|
||||
|
||||
public function getList(): Array{
|
||||
return {{classVarName}};
|
||||
return {{classVarName}};
|
||||
}
|
||||
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
{{#isBodyParam}}
|
||||
<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
|
||||
{{#isBodyParam}}<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
|
||||
|
||||
<div class="param-desc"><span class="param-type">Body Parameter</span> — {{description}} {{#defaultValue}}
|
||||
default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isBodyParam}}
|
||||
<div class="param-desc"><span class="param-type">Body Parameter</span> — {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isBodyParam}}
|
||||
@@ -1,5 +1,3 @@
|
||||
{{#isFormParam}}
|
||||
<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
|
||||
{{#isFormParam}}<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
|
||||
|
||||
<div class="param-desc"><span class="param-type">Form Parameter</span> — {{description}} {{#defaultValue}}
|
||||
default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isFormParam}}
|
||||
<div class="param-desc"><span class="param-type">Form Parameter</span> — {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isFormParam}}
|
||||
@@ -1,5 +1,3 @@
|
||||
{{#isHeaderParam}}
|
||||
<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
|
||||
{{#isHeaderParam}}<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
|
||||
|
||||
<div class="param-desc"><span class="param-type">Header Parameter</span> — {{description}} {{#defaultValue}}
|
||||
default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isHeaderParam}}
|
||||
<div class="param-desc"><span class="param-type">Header Parameter</span> — {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isHeaderParam}}
|
||||
@@ -1,76 +1,61 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>API Reference</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{{appName}}}</h1>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{{appName}}}</h1>
|
||||
<div class="app-desc">{{{appDescription}}} for {{partner}}</div>
|
||||
{{#infoUrl}}<div class="app-desc">More information: <a href="{{{infoUrl}}}">{{{infoUrl}}}</a></div>{{/infoUrl}}
|
||||
{{#infoEmail}}<div class="app-desc">Contact Info: <a href="{{{infoEmail}}}">{{{infoEmail}}}</a></div>{{/infoEmail}}
|
||||
{{#version}}<div class="app-desc">Version: {{{version}}}</div>{{/version}}
|
||||
<div class="license-info">{{{licenseInfo}}}</div>
|
||||
<div class="license-url">{{{licenseUrl}}}</div>
|
||||
<h2>Access</h2>
|
||||
<div class="method-summary">Customize this message as you see fit!</div>
|
||||
<h2>Methods</h2>
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
{{#operations}}{{#operation}}
|
||||
<div class="method">
|
||||
<div class="method-path"><pre class="{{httpMethod}}"><code class="huge"><span>{{httpMethod}}</span>: {{path}}</code></pre></div>
|
||||
<div class="method-tags"> {{#tags}}<span class="method-tag">{{this}}</span>{{/tags}}</div>
|
||||
<div class="method-summary"><span class="nickname">{{nickname}}</span> {{summary}}</div>
|
||||
<div class="method-notes">{{notes}}</div>
|
||||
|
||||
<div class="app-desc">{{{appDescription}}} for {{partner}}</div>
|
||||
{{#infoUrl}}
|
||||
<div class="app-desc">More information: <a href="{{{infoUrl}}}">{{{infoUrl}}}</a></div>{{/infoUrl}}
|
||||
{{#infoEmail}}
|
||||
<div class="app-desc">Contact Info: <a href="{{{infoEmail}}}">{{{infoEmail}}}</a></div>{{/infoEmail}}
|
||||
{{#version}}
|
||||
<div class="app-desc">Version: {{{version}}}</div>{{/version}}
|
||||
<div class="license-info">{{{licenseInfo}}}</div>
|
||||
<div class="license-url">{{{licenseUrl}}}</div>
|
||||
<h2>Access</h2>
|
||||
<h3 class="field-label">Parameters</h3>
|
||||
<div class="field-items">
|
||||
{{#allParams}}{{>queryParam}}{{>pathParam}}{{>bodyParam}}{{>headerParam}}{{>formParam}}
|
||||
{{/allParams}}
|
||||
</div> <!-- field-items -->
|
||||
<h3 class="field-label">Return type</h3>
|
||||
|
||||
<div class="method-summary">Customize this message as you see fit!</div>
|
||||
<h2>Methods</h2>
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
{{#operations}}{{#operation}}
|
||||
<div class="method">
|
||||
<div class="method-path">
|
||||
<pre class="{{httpMethod}}"><code class="huge"><span>{{httpMethod}}</span>: {{path}}</code></pre>
|
||||
</div>
|
||||
<div class="method-tags"> {{#tags}}<span class="method-tag">{{this}}</span>{{/tags}}</div>
|
||||
<div class="method-summary"><span class="nickname">{{nickname}}</span> {{summary}}</div>
|
||||
<div class="method-notes">{{notes}}</div>
|
||||
<div class="return-type"><a href="#{{returnContainer}}">{{{returnType}}}</a></div>
|
||||
|
||||
<h3 class="field-label">Parameters</h3>
|
||||
{{#examples}}
|
||||
<h3 class="field-label">Example data</h3>
|
||||
<div class="example-data-content-type">Content-Type: {{{contentType}}}</div>
|
||||
<pre class="example"><code>{{example}}</code></pre>
|
||||
{{/examples}}
|
||||
</div> <!-- method -->
|
||||
<hr>
|
||||
{{/operation}}{{/operations}}
|
||||
{{/apis}}{{/apiInfo}}
|
||||
|
||||
<div class="field-items">
|
||||
{{#allParams}}{{>queryParam}}{{>pathParam}}{{>bodyParam}}{{>headerParam}}{{>formParam}}
|
||||
{{/allParams}}
|
||||
</div>
|
||||
<!-- field-items -->
|
||||
<h3 class="field-label">Return type</h3>
|
||||
|
||||
<div class="return-type"><a href="#{{returnContainer}}">{{{returnType}}}</a></div>
|
||||
|
||||
{{#examples}}
|
||||
<h3 class="field-label">Example data</h3>
|
||||
|
||||
<div class="example-data-content-type">Content-Type: {{{contentType}}}</div>
|
||||
<pre class="example"><code>{{example}}</code></pre>
|
||||
{{/examples}}
|
||||
</div>
|
||||
<!-- method -->
|
||||
<hr>
|
||||
{{/operation}}{{/operations}}
|
||||
{{/apis}}{{/apiInfo}}
|
||||
|
||||
<h2>Models</h2>
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
<div class="model">
|
||||
<h3 class="field-label"><a name="{{classname}}">{{classname}}</a></h3>
|
||||
|
||||
<div class="field-items">
|
||||
{{#vars}}
|
||||
<div class="param">{{name}} {{#isNotRequired}}(optional){{/isNotRequired}}</div>
|
||||
<div class="param-desc"><span class="param-type">{{datatype}}</span> {{description}}</div>
|
||||
{{/vars}}
|
||||
</div>
|
||||
<!-- field-items -->
|
||||
</div>
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
<style>
|
||||
{{>style.css}}
|
||||
</style>
|
||||
</body>
|
||||
<h2>Models</h2>
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
<div class="model">
|
||||
<h3 class="field-label"><a name="{{classname}}">{{classname}}</a></h3>
|
||||
<div class="field-items">
|
||||
{{#vars}}<div class="param">{{name}} {{#isNotRequired}}(optional){{/isNotRequired}}</div><div class="param-desc"><span class="param-type">{{datatype}}</span> {{description}}</div>
|
||||
{{/vars}}
|
||||
</div> <!-- field-items -->
|
||||
</div>
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
<style>
|
||||
{{>style.css}}
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,5 +1,3 @@
|
||||
{{#isPathParam}}
|
||||
<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
|
||||
{{#isPathParam}}<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
|
||||
|
||||
<div class="param-desc"><span class="param-type">Path Parameter</span> — {{description}} {{#defaultValue}}
|
||||
default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isPathParam}}
|
||||
<div class="param-desc"><span class="param-type">Path Parameter</span> — {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isPathParam}}
|
||||
@@ -1,5 +1,3 @@
|
||||
{{#isQueryParam}}
|
||||
<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
|
||||
{{#isQueryParam}}<div class="param">{{paramName}} {{^required}}(optional){{/required}}{{#required}}(required){{/required}}</div>
|
||||
|
||||
<div class="param-desc"><span class="param-type">Query Parameter</span> — {{description}} {{#defaultValue}}
|
||||
default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isQueryParam}}
|
||||
<div class="param-desc"><span class="param-type">Query Parameter</span> — {{description}} {{#defaultValue}}default: {{{defaultValue}}}{{/defaultValue}}</div>{{/isQueryParam}}
|
||||
@@ -1,151 +1,151 @@
|
||||
body {
|
||||
font-family: Trebuchet MS, sans-serif;
|
||||
font-size: 15px;
|
||||
color: #444;
|
||||
margin-right: 24px;
|
||||
body {
|
||||
font-family: Trebuchet MS, sans-serif;
|
||||
font-size: 15px;
|
||||
color: #444;
|
||||
margin-right: 24px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 25px;
|
||||
h1 {
|
||||
font-size: 25px;
|
||||
}
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
}
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
hr {
|
||||
height: 1px;
|
||||
border: 0;
|
||||
color: #ddd;
|
||||
background-color: #ddd;
|
||||
display: none;
|
||||
hr {
|
||||
height: 1px;
|
||||
border: 0;
|
||||
color: #ddd;
|
||||
background-color: #ddd;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.app-desc {
|
||||
clear: both;
|
||||
margin-left: 20px;
|
||||
clear: both;
|
||||
margin-left: 20px;
|
||||
}
|
||||
.param-name {
|
||||
width: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
.license-info {
|
||||
margin-left: 20px;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.license-url {
|
||||
margin-left: 20px;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.model {
|
||||
margin: 0 0 0px 20px;
|
||||
margin: 0 0 0px 20px;
|
||||
}
|
||||
|
||||
.method {
|
||||
margin-left: 20px;
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.method-notes {
|
||||
margin: 10px 0 20px 0;
|
||||
font-size: 90%;
|
||||
color: #555;
|
||||
.method-notes {
|
||||
margin: 10px 0 20px 0;
|
||||
font-size: 90%;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
pre {
|
||||
padding: 10px;
|
||||
margin-bottom: 2px;
|
||||
padding: 10px;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
pre.get {
|
||||
background-color: #0f6ab4;
|
||||
background-color: #0f6ab4;
|
||||
}
|
||||
|
||||
pre.post {
|
||||
background-color: #10a54a;
|
||||
background-color: #10a54a;
|
||||
}
|
||||
|
||||
pre.put {
|
||||
background-color: #c5862b;
|
||||
background-color: #c5862b;
|
||||
}
|
||||
|
||||
pre.delete {
|
||||
background-color: #a41e22;
|
||||
background-color: #a41e22;
|
||||
}
|
||||
|
||||
.huge {
|
||||
color: #fff;
|
||||
.huge {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
pre.example {
|
||||
background-color: #f3f3f3;
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
background-color: #f3f3f3;
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
|
||||
code {
|
||||
white-space: pre;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
.nickname {
|
||||
font-weight: bold;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.method-path {
|
||||
font-size: 1.5em;
|
||||
background-color: #0f6ab4;
|
||||
font-size: 1.5em;
|
||||
background-color: #0f6ab4;
|
||||
}
|
||||
|
||||
.parameter {
|
||||
width: 500px;
|
||||
width: 500px;
|
||||
}
|
||||
|
||||
.param {
|
||||
width: 500px;
|
||||
padding: 10px 0 0 20px;
|
||||
font-weight: bold;
|
||||
width: 500px;
|
||||
padding: 10px 0 0 20px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.param-desc {
|
||||
width: 700px;
|
||||
padding: 0 0 0 20px;
|
||||
color: #777;
|
||||
width: 700px;
|
||||
padding: 0 0 0 20px;
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.param-type {
|
||||
font-style: italic;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.field-label {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
clear: both;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.field-items {
|
||||
padding: 0 0 15px 0;
|
||||
margin-bottom: 15px;
|
||||
.field-items {
|
||||
padding: 0 0 15px 0;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.return-type {
|
||||
clear: both;
|
||||
padding-bottom: 10px;
|
||||
clear: both;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.param-header {
|
||||
font-weight: bold;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.method-tags {
|
||||
text-align: right;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.method-tag {
|
||||
background: none repeat scroll 0% 0% #24A600;
|
||||
border-radius: 3px;
|
||||
padding: 2px 10px;
|
||||
margin: 2px;
|
||||
color: #FFF;
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
background: none repeat scroll 0% 0% #24A600;
|
||||
border-radius: 3px;
|
||||
padding: 2px 10px;
|
||||
margin: 2px;
|
||||
color: #FFF;
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
}
|
||||
@@ -4,22 +4,22 @@ var url = require('url');
|
||||
|
||||
{{#operations}}
|
||||
|
||||
var {{classname}} = require('./{{classname}}Service');
|
||||
var {{classname}} = require('./{{classname}}Service');
|
||||
|
||||
{{#operation}}
|
||||
{{#operation}}
|
||||
|
||||
module.exports.{{nickname}} = function {{nickname}} (req, res, next) {
|
||||
{{#allParams}}var {{paramName}} = req.swagger.params['{{baseName}}'].value;
|
||||
{{/allParams}}
|
||||
module.exports.{{nickname}} = function {{nickname}} (req, res, next) {
|
||||
{{#allParams}}var {{paramName}} = req.swagger.params['{{baseName}}'].value;
|
||||
{{/allParams}}
|
||||
|
||||
var result = {{classname}}.{{nickname}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
var result = {{classname}}.{{nickname}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
|
||||
if(typeof result !== 'undefined') {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(result || {}, null, 2));
|
||||
}
|
||||
else
|
||||
res.end();
|
||||
};
|
||||
{{/operation}}
|
||||
if(typeof result !== 'undefined') {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(result || {}, null, 2));
|
||||
}
|
||||
else
|
||||
res.end();
|
||||
};
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
@@ -8,9 +8,9 @@ var serverPort = {{serverPort}};
|
||||
|
||||
// swaggerRouter configuration
|
||||
var options = {
|
||||
swaggerUi: '/swagger.json',
|
||||
controllers: './controllers',
|
||||
useStubs: process.env.NODE_ENV === 'development' ? true : false // Conditionally turn on stubs (mock mode)
|
||||
swaggerUi: '/swagger.json',
|
||||
controllers: './controllers',
|
||||
useStubs: process.env.NODE_ENV === 'development' ? true : false // Conditionally turn on stubs (mock mode)
|
||||
};
|
||||
|
||||
// The Swagger document (require it, build it programmatically, fetch it from a URL, ...)
|
||||
@@ -18,21 +18,21 @@ var swaggerDoc = require('./api/swagger.json');
|
||||
|
||||
// Initialize the Swagger middleware
|
||||
swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
|
||||
// Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain
|
||||
app.use(middleware.swaggerMetadata());
|
||||
// Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain
|
||||
app.use(middleware.swaggerMetadata());
|
||||
|
||||
// Validate Swagger requests
|
||||
app.use(middleware.swaggerValidator());
|
||||
// Validate Swagger requests
|
||||
app.use(middleware.swaggerValidator());
|
||||
|
||||
// Route validated requests to appropriate controller
|
||||
app.use(middleware.swaggerRouter(options));
|
||||
// Route validated requests to appropriate controller
|
||||
app.use(middleware.swaggerRouter(options));
|
||||
|
||||
// Serve the Swagger documents and Swagger UI
|
||||
app.use(middleware.swaggerUi());
|
||||
// Serve the Swagger documents and Swagger UI
|
||||
app.use(middleware.swaggerUi());
|
||||
|
||||
// Start the server
|
||||
http.createServer(app).listen({{serverPort}}, function () {
|
||||
console.log('Your server is listening on port %d (http://localhost:%d)', {{serverPort}}, {{serverPort}});
|
||||
console.log('Swagger-ui is available on http://localhost:%d/docs', {{serverPort}});
|
||||
});
|
||||
// Start the server
|
||||
http.createServer(app).listen({{serverPort}}, function () {
|
||||
console.log('Your server is listening on port %d (http://localhost:%d)', {{serverPort}}, {{serverPort}});
|
||||
console.log('Swagger-ui is available on http://localhost:%d/docs', {{serverPort}});
|
||||
});
|
||||
});
|
||||
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "{{projectName}}",
|
||||
"version": "{{appVersion}}",
|
||||
"description": "{{appDescription}}",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
"swagger"
|
||||
],
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"connect": "^3.2.0",
|
||||
"swagger-tools": "0.8.*"
|
||||
}
|
||||
"name": "{{projectName}}",
|
||||
"version": "{{appVersion}}",
|
||||
"description": "{{appDescription}}",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
"swagger"
|
||||
],
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"connect": "^3.2.0",
|
||||
"swagger-tools": "0.8.*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
exports.{{nickname}} = function({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
|
||||
{{#operation}}
|
||||
exports.{{nickname}} = function({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
|
||||
|
||||
var examples = {};
|
||||
{{#examples}}
|
||||
examples['{{contentType}}'] = {{{example}}};
|
||||
{{/examples}}
|
||||
var examples = {};
|
||||
{{#examples}}
|
||||
examples['{{contentType}}'] = {{{example}}};
|
||||
{{/examples}}
|
||||
|
||||
{{#returnType}}
|
||||
if(Object.keys(examples).length > 0)
|
||||
return examples[Object.keys(examples)[0]];
|
||||
{{/returnType}}
|
||||
}
|
||||
{{/operation}}
|
||||
{{#returnType}}
|
||||
if(Object.keys(examples).length > 0)
|
||||
return examples[Object.keys(examples)[0]];
|
||||
{{/returnType}}
|
||||
}
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "{{appName}}",
|
||||
"description": "{{appDescription}}",
|
||||
"version": "{{apiVersion}}"
|
||||
},
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "{{appName}}",
|
||||
"description": "{{appDescription}}",
|
||||
"version": "{{apiVersion}}"
|
||||
},
|
||||
{{#apiInfo}}
|
||||
"produces": ["application/json"],
|
||||
"host": "localhost:{{serverPort}}",
|
||||
"basePath": "{{contextPath}}",
|
||||
"paths": {
|
||||
{{#apis}}
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
"{{{path}}}": {
|
||||
"{{httpMethod}}": {
|
||||
"x-swagger-router-controller": "{{classname}}",
|
||||
"tags": ["{{baseName}}"],
|
||||
"operationId": "{{operationId}}",{{#hasParams}}
|
||||
"parameters": [
|
||||
{{#allParams}}
|
||||
{{{jsonSchema}}}{{#hasMore}},{{/hasMore}}
|
||||
{{/allParams}}
|
||||
],{{/hasParams}}
|
||||
"responses": {
|
||||
{{#responses}}
|
||||
"{{code}}": {{{jsonSchema}}}
|
||||
{{#hasMore}},{{/hasMore}}
|
||||
{{/responses}}
|
||||
}
|
||||
}
|
||||
} {{#hasMore}},{{/hasMore}}
|
||||
{{/operation}}
|
||||
{{#hasMore}},{{/hasMore}}
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
"produces": ["application/json"],
|
||||
"host": "localhost:{{serverPort}}",
|
||||
"basePath": "{{contextPath}}",
|
||||
"paths": {
|
||||
{{#apis}}
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
"{{{path}}}": {
|
||||
"{{httpMethod}}": {
|
||||
"x-swagger-router-controller": "{{classname}}",
|
||||
"tags": ["{{baseName}}"],
|
||||
"operationId": "{{operationId}}",{{#hasParams}}
|
||||
"parameters": [
|
||||
{{#allParams}}
|
||||
{{{jsonSchema}}}{{#hasMore}},{{/hasMore}}
|
||||
{{/allParams}}
|
||||
],{{/hasParams}}
|
||||
"responses": {
|
||||
{{#responses}}
|
||||
"{{code}}": {{{jsonSchema}}}
|
||||
{{#hasMore}},{{/hasMore}}
|
||||
{{/responses}}
|
||||
}
|
||||
}
|
||||
} {{#hasMore}},{{/hasMore}}
|
||||
{{/operation}}
|
||||
{{#hasMore}},{{/hasMore}}
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
||||
}, "definitions": {
|
||||
{{#models}}{{#model}}"{{classVarName}}": {{{modelJson}}}{{#hasMoreModels}},{{/hasMoreModels}}{{/model}}{{/models}}
|
||||
}
|
||||
}, "definitions": {
|
||||
{{#models}}{{#model}}"{{classVarName}}": {{{modelJson}}}{{#hasMoreModels}},{{/hasMoreModels}}{{/model}}{{/models}}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,88 +12,88 @@
|
||||
#pragma mark - Singletion Methods
|
||||
|
||||
+ (instancetype) sharedConfig {
|
||||
static SWGConfiguration *shardConfig = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
shardConfig = [[self alloc] init];
|
||||
});
|
||||
return shardConfig;
|
||||
static SWGConfiguration *shardConfig = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
shardConfig = [[self alloc] init];
|
||||
});
|
||||
return shardConfig;
|
||||
}
|
||||
|
||||
#pragma mark - Initialize Methods
|
||||
|
||||
- (instancetype) init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.username = @"";
|
||||
self.password = @"";
|
||||
self.mutableApiKey = [NSMutableDictionary dictionary];
|
||||
self.mutableApiKeyPrefix = [NSMutableDictionary dictionary];
|
||||
}
|
||||
return self;
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.username = @"";
|
||||
self.password = @"";
|
||||
self.mutableApiKey = [NSMutableDictionary dictionary];
|
||||
self.mutableApiKeyPrefix = [NSMutableDictionary dictionary];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Instance Methods
|
||||
|
||||
- (NSString *) getApiKeyWithPrefix:(NSString *)key {
|
||||
if ([self.apiKeyPrefix objectForKey:key] && [self.apiKey objectForKey:key]) {
|
||||
return [NSString stringWithFormat:@"%@ %@", [self.apiKeyPrefix objectForKey:key], [self.apiKey objectForKey:key]];
|
||||
}
|
||||
else if ([self.apiKey objectForKey:key]) {
|
||||
return [NSString stringWithFormat:@"%@", [self.apiKey objectForKey:key]];
|
||||
}
|
||||
else {
|
||||
return @"";
|
||||
}
|
||||
if ([self.apiKeyPrefix objectForKey:key] && [self.apiKey objectForKey:key]) {
|
||||
return [NSString stringWithFormat:@"%@ %@", [self.apiKeyPrefix objectForKey:key], [self.apiKey objectForKey:key]];
|
||||
}
|
||||
else if ([self.apiKey objectForKey:key]) {
|
||||
return [NSString stringWithFormat:@"%@", [self.apiKey objectForKey:key]];
|
||||
}
|
||||
else {
|
||||
return @"";
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *) getBasicAuthToken {
|
||||
NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", self.username, self.password];
|
||||
NSData *data = [basicAuthCredentials dataUsingEncoding:NSUTF8StringEncoding];
|
||||
basicAuthCredentials = [NSString stringWithFormat:@"Basic %@", [data base64EncodedStringWithOptions:0]];
|
||||
|
||||
return basicAuthCredentials;
|
||||
NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", self.username, self.password];
|
||||
NSData *data = [basicAuthCredentials dataUsingEncoding:NSUTF8StringEncoding];
|
||||
basicAuthCredentials = [NSString stringWithFormat:@"Basic %@", [data base64EncodedStringWithOptions:0]];
|
||||
|
||||
return basicAuthCredentials;
|
||||
}
|
||||
|
||||
#pragma mark - Setter Methods
|
||||
|
||||
- (void) setValue:(NSString *)value forApiKeyField:(NSString *)field {
|
||||
[self.mutableApiKey setValue:value forKey:field];
|
||||
[self.mutableApiKey setValue:value forKey:field];
|
||||
}
|
||||
|
||||
- (void) setValue:(NSString *)value forApiKeyPrefixField:(NSString *)field {
|
||||
[self.mutableApiKeyPrefix setValue:value forKey:field];
|
||||
[self.mutableApiKeyPrefix setValue:value forKey:field];
|
||||
}
|
||||
|
||||
#pragma mark - Getter Methods
|
||||
|
||||
- (NSDictionary *) apiKey {
|
||||
return [NSDictionary dictionaryWithDictionary:self.mutableApiKey];
|
||||
return [NSDictionary dictionaryWithDictionary:self.mutableApiKey];
|
||||
}
|
||||
|
||||
- (NSDictionary *) apiKeyPrefix {
|
||||
return [NSDictionary dictionaryWithDictionary:self.mutableApiKeyPrefix];
|
||||
return [NSDictionary dictionaryWithDictionary:self.mutableApiKeyPrefix];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (NSDictionary *) authSettings {
|
||||
return @{ {{#authMethods}}{{#isApiKey}}
|
||||
@"{{name}}": @{
|
||||
@"type": @"api_key",
|
||||
@"in": {{#isKeyInHeader}}@"header"{{/isKeyInHeader}}{{#isKeyInQuery}}@"query"{{/isKeyInQuery}},
|
||||
@"key": @"{{keyParamName}}",
|
||||
@"value": [self getApiKeyWithPrefix:@"{{keyParamName}}"]
|
||||
},
|
||||
{{/isApiKey}}{{#isBasic}}
|
||||
@"{{name}}": @{
|
||||
@"type": @"basic",
|
||||
@"in": @"header",
|
||||
@"key": @"Authorization",
|
||||
@"value": [self getBasicAuthToken]
|
||||
},
|
||||
{{/isBasic}}{{/authMethods}}
|
||||
};
|
||||
return @{ {{#authMethods}}{{#isApiKey}}
|
||||
@"{{name}}": @{
|
||||
@"type": @"api_key",
|
||||
@"in": {{#isKeyInHeader}}@"header"{{/isKeyInHeader}}{{#isKeyInQuery}}@"query"{{/isKeyInQuery}},
|
||||
@"key": @"{{keyParamName}}",
|
||||
@"value": [self getApiKeyWithPrefix:@"{{keyParamName}}"]
|
||||
},
|
||||
{{/isApiKey}}{{#isBasic}}
|
||||
@"{{name}}": @{
|
||||
@"type": @"basic",
|
||||
@"in": @"header",
|
||||
@"key": @"Authorization",
|
||||
@"value": [self getBasicAuthToken]
|
||||
},
|
||||
{{/isBasic}}{{/authMethods}}
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -1,57 +1,56 @@
|
||||
#import
|
||||
<Foundation/Foundation.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface SWGConfiguration : NSObject
|
||||
|
||||
|
||||
/**
|
||||
* Api key values for Api Key type Authentication
|
||||
*
|
||||
* To add or remove api key, use `setValue:forApiKeyField:`.
|
||||
*/
|
||||
* Api key values for Api Key type Authentication
|
||||
*
|
||||
* To add or remove api key, use `setValue:forApiKeyField:`.
|
||||
*/
|
||||
@property (readonly, nonatomic, strong) NSDictionary *apiKey;
|
||||
|
||||
/**
|
||||
* Api key prefix values to be prepend to the respective api key
|
||||
*
|
||||
* To add or remove prefix, use `setValue:forApiKeyPrefixField:`.
|
||||
*/
|
||||
* Api key prefix values to be prepend to the respective api key
|
||||
*
|
||||
* To add or remove prefix, use `setValue:forApiKeyPrefixField:`.
|
||||
*/
|
||||
@property (readonly, nonatomic, strong) NSDictionary *apiKeyPrefix;
|
||||
|
||||
/**
|
||||
* Usename and Password for Basic type Authentication
|
||||
*/
|
||||
* Usename and Password for Basic type Authentication
|
||||
*/
|
||||
@property (nonatomic) NSString *username;
|
||||
@property (nonatomic) NSString *password;
|
||||
|
||||
/**
|
||||
* Get configuration singleton instance
|
||||
*/
|
||||
* Get configuration singleton instance
|
||||
*/
|
||||
+ (instancetype) sharedConfig;
|
||||
|
||||
/**
|
||||
* Sets field in `apiKey`
|
||||
*/
|
||||
* Sets field in `apiKey`
|
||||
*/
|
||||
- (void) setValue:(NSString *)value forApiKeyField:(NSString*)field;
|
||||
|
||||
/**
|
||||
* Sets field in `apiKeyPrefix`
|
||||
*/
|
||||
* Sets field in `apiKeyPrefix`
|
||||
*/
|
||||
- (void) setValue:(NSString *)value forApiKeyPrefixField:(NSString *)field;
|
||||
|
||||
/**
|
||||
* Get API key (with prefix if set)
|
||||
*/
|
||||
* Get API key (with prefix if set)
|
||||
*/
|
||||
- (NSString *) getApiKeyWithPrefix:(NSString *) key;
|
||||
|
||||
/**
|
||||
* Get Basic Auth token
|
||||
*/
|
||||
* Get Basic Auth token
|
||||
*/
|
||||
- (NSString *) getBasicAuthToken;
|
||||
|
||||
/**
|
||||
* Get Authentication Setings
|
||||
*/
|
||||
* Get Authentication Setings
|
||||
*/
|
||||
- (NSDictionary *) authSettings;
|
||||
|
||||
@end
|
||||
|
||||
@@ -1,226 +1,226 @@
|
||||
{{#operations}}
|
||||
#import "{{classname}}.h"
|
||||
#import "SWGFile.h"
|
||||
#import "SWGQueryParamCollection.h"
|
||||
{{#imports}}#import "{{import}}.h"
|
||||
{{/imports}}
|
||||
{{newline}}
|
||||
#import "{{classname}}.h"
|
||||
#import "SWGFile.h"
|
||||
#import "SWGQueryParamCollection.h"
|
||||
{{#imports}}#import "{{import}}.h"
|
||||
{{/imports}}
|
||||
{{newline}}
|
||||
|
||||
@interface {{classname}} ()
|
||||
@interface {{classname}} ()
|
||||
@property (readwrite, nonatomic, strong) NSMutableDictionary *defaultHeaders;
|
||||
@end
|
||||
@end
|
||||
|
||||
@implementation {{classname}}
|
||||
@implementation {{classname}}
|
||||
|
||||
static NSString * basePath = @"{{basePath}}";
|
||||
static NSString * basePath = @"{{basePath}}";
|
||||
|
||||
#pragma mark - Initialize methods
|
||||
#pragma mark - Initialize methods
|
||||
|
||||
- (id) init {
|
||||
- (id) init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.apiClient = [SWGApiClient sharedClientFromPool:basePath];
|
||||
self.defaultHeaders = [NSMutableDictionary dictionary];
|
||||
self.apiClient = [SWGApiClient sharedClientFromPool:basePath];
|
||||
self.defaultHeaders = [NSMutableDictionary dictionary];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
||||
- (id) initWithApiClient:(SWGApiClient *)apiClient {
|
||||
- (id) initWithApiClient:(SWGApiClient *)apiClient {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
if (apiClient) {
|
||||
self.apiClient = apiClient;
|
||||
}
|
||||
else {
|
||||
self.apiClient = [SWGApiClient sharedClientFromPool:basePath];
|
||||
}
|
||||
self.defaultHeaders = [NSMutableDictionary dictionary];
|
||||
if (apiClient) {
|
||||
self.apiClient = apiClient;
|
||||
}
|
||||
else {
|
||||
self.apiClient = [SWGApiClient sharedClientFromPool:basePath];
|
||||
}
|
||||
self.defaultHeaders = [NSMutableDictionary dictionary];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark -
|
||||
|
||||
+({{classname}}*) apiWithHeader:(NSString*)headerValue key:(NSString*)key {
|
||||
+({{classname}}*) apiWithHeader:(NSString*)headerValue key:(NSString*)key {
|
||||
static {{classname}}* singletonAPI = nil;
|
||||
|
||||
if (singletonAPI == nil) {
|
||||
singletonAPI = [[{{classname}} alloc] init];
|
||||
[singletonAPI addHeader:headerValue forKey:key];
|
||||
singletonAPI = [[{{classname}} alloc] init];
|
||||
[singletonAPI addHeader:headerValue forKey:key];
|
||||
}
|
||||
return singletonAPI;
|
||||
}
|
||||
}
|
||||
|
||||
+(void) setBasePath:(NSString*)path {
|
||||
+(void) setBasePath:(NSString*)path {
|
||||
basePath = path;
|
||||
}
|
||||
}
|
||||
|
||||
+(NSString*) getBasePath {
|
||||
+(NSString*) getBasePath {
|
||||
return basePath;
|
||||
}
|
||||
}
|
||||
|
||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
|
||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key {
|
||||
[self.defaultHeaders setValue:value forKey:key];
|
||||
}
|
||||
}
|
||||
|
||||
-(void) setHeaderValue:(NSString*) value
|
||||
forKey:(NSString*)key {
|
||||
-(void) setHeaderValue:(NSString*) value
|
||||
forKey:(NSString*)key {
|
||||
[self.defaultHeaders setValue:value forKey:key];
|
||||
}
|
||||
}
|
||||
|
||||
-(unsigned long) requestQueueSize {
|
||||
-(unsigned long) requestQueueSize {
|
||||
return [SWGApiClient requestQueueSize];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{{#operation}}
|
||||
/*!
|
||||
* {{{summary}}}
|
||||
* {{{notes}}}
|
||||
{{#allParams}} * \param {{paramName}} {{{description}}}
|
||||
{{/allParams}} * \returns {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||
*/
|
||||
-(NSNumber*) {{nickname}}WithCompletionBlock{{^allParams}}: {{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}
|
||||
{{#operation}}
|
||||
/*!
|
||||
* {{{summary}}}
|
||||
* {{{notes}}}
|
||||
{{#allParams}} * \param {{paramName}} {{{description}}}
|
||||
{{/allParams}} * \returns {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||
*/
|
||||
-(NSNumber*) {{nickname}}WithCompletionBlock{{^allParams}}: {{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}: ({{{dataType}}}) {{paramName}}
|
||||
{{/allParams}}
|
||||
{{#returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)({{{returnType}}} output, NSError* error))completionBlock{{/returnBaseType}}
|
||||
{{^returnBaseType}}{{#hasParams}}completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock{{/returnBaseType}} {
|
||||
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
NSAssert({{paramName}} != nil, @"Missing the required parameter `{{paramName}}` when calling {{nickname}}");
|
||||
{{/required}}{{/allParams}}
|
||||
{{#allParams}}{{#required}}
|
||||
// verify the required parameter '{{paramName}}' is set
|
||||
NSAssert({{paramName}} != nil, @"Missing the required parameter `{{paramName}}` when calling {{nickname}}");
|
||||
{{/required}}{{/allParams}}
|
||||
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@{{path}}", basePath];
|
||||
NSMutableString* requestUrl = [NSMutableString stringWithFormat:@"%@{{path}}", basePath];
|
||||
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
// remove format in URL if needed
|
||||
if ([requestUrl rangeOfString:@".{format}"].location != NSNotFound)
|
||||
[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:@".{format}"] withString:@".json"];
|
||||
|
||||
{{#pathParams}}[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"{{baseName}}", @"}"]] withString: [SWGApiClient escape:{{paramName}}]];
|
||||
{{/pathParams}}
|
||||
{{#pathParams}}[requestUrl replaceCharactersInRange: [requestUrl rangeOfString:[NSString stringWithFormat:@"%@%@%@", @"{", @"{{baseName}}", @"}"]] withString: [SWGApiClient escape:{{paramName}}]];
|
||||
{{/pathParams}}
|
||||
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
{{#queryParams}}if({{paramName}} != nil) {
|
||||
NSMutableDictionary* queryParams = [[NSMutableDictionary alloc] init];
|
||||
{{#queryParams}}if({{paramName}} != nil) {
|
||||
{{#collectionFormat}}
|
||||
queryParams[@"{{baseName}}"] = [[SWGQueryParamCollection alloc] initWithValuesAndFormat: {{baseName}} format: @"{{collectionFormat}}"];
|
||||
queryParams[@"{{baseName}}"] = [[SWGQueryParamCollection alloc] initWithValuesAndFormat: {{baseName}} format: @"{{collectionFormat}}"];
|
||||
{{/collectionFormat}}
|
||||
{{^collectionFormat}}queryParams[@"{{baseName}}"] = {{paramName}};{{/collectionFormat}}
|
||||
}
|
||||
{{/queryParams}}
|
||||
NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders];
|
||||
}
|
||||
{{/queryParams}}
|
||||
NSMutableDictionary* headerParams = [NSMutableDictionary dictionaryWithDictionary:self.defaultHeaders];
|
||||
|
||||
{{#headerParams}}if({{paramName}} != nil)
|
||||
{{#headerParams}}if({{paramName}} != nil)
|
||||
headerParams[@"{{baseName}}"] = {{paramName}};
|
||||
{{/headerParams}}
|
||||
|
||||
// HTTP header `Accept`
|
||||
headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[{{#produces}}@"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}]];
|
||||
if ([headerParams[@"Accept"] length] == 0) {
|
||||
{{/headerParams}}
|
||||
|
||||
// HTTP header `Accept`
|
||||
headerParams[@"Accept"] = [SWGApiClient selectHeaderAccept:@[{{#produces}}@"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}]];
|
||||
if ([headerParams[@"Accept"] length] == 0) {
|
||||
[headerParams removeObjectForKey:@"Accept"];
|
||||
}
|
||||
}
|
||||
|
||||
// response content type
|
||||
NSString *responseContentType;
|
||||
if ([headerParams objectForKey:@"Accept"]) {
|
||||
// response content type
|
||||
NSString *responseContentType;
|
||||
if ([headerParams objectForKey:@"Accept"]) {
|
||||
responseContentType = [headerParams[@"Accept"] componentsSeparatedByString:@", "][0];
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
responseContentType = @"";
|
||||
}
|
||||
}
|
||||
|
||||
// request content type
|
||||
NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[{{#consumes}}@"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}]];
|
||||
// request content type
|
||||
NSString *requestContentType = [SWGApiClient selectHeaderContentType:@[{{#consumes}}@"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}]];
|
||||
|
||||
// Authentication setting
|
||||
NSArray *authSettings = @[{{#authMethods}}@"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}}];
|
||||
// Authentication setting
|
||||
NSArray *authSettings = @[{{#authMethods}}@"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}}];
|
||||
|
||||
id bodyDictionary = nil;
|
||||
{{#bodyParam}}
|
||||
id __body = {{paramName}};
|
||||
|
||||
id bodyDictionary = nil;
|
||||
{{#bodyParam}}
|
||||
id __body = {{paramName}};
|
||||
|
||||
if(__body != nil && [__body isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] init];
|
||||
for (id dict in (NSArray*)__body) {
|
||||
if(__body != nil && [__body isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] init];
|
||||
for (id dict in (NSArray*)__body) {
|
||||
if([dict respondsToSelector:@selector(toDictionary)]) {
|
||||
[objs addObject:[(SWGObject*)dict toDictionary]];
|
||||
[objs addObject:[(SWGObject*)dict toDictionary]];
|
||||
}
|
||||
else{
|
||||
[objs addObject:dict];
|
||||
[objs addObject:dict];
|
||||
}
|
||||
}
|
||||
bodyDictionary = objs;
|
||||
}
|
||||
else if([__body respondsToSelector:@selector(toDictionary)]) {
|
||||
bodyDictionary = [(SWGObject*)__body toDictionary];
|
||||
}
|
||||
else if([__body isKindOfClass:[NSString class]]) {
|
||||
// convert it to a dictionary
|
||||
NSError * error;
|
||||
NSString * str = (NSString*)__body;
|
||||
NSDictionary *JSON =
|
||||
[NSJSONSerialization JSONObjectWithData: [str dataUsingEncoding: NSUTF8StringEncoding]
|
||||
options: NSJSONReadingMutableContainers
|
||||
error: &error];
|
||||
bodyDictionary = JSON;
|
||||
}
|
||||
{{/bodyParam}}
|
||||
{{^bodyParam}}
|
||||
|
||||
NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init];
|
||||
|
||||
{{#formParams}}
|
||||
{{#notFile}}
|
||||
formParams[@"{{paramName}}"] = {{paramName}};
|
||||
{{/notFile}}{{#isFile}}
|
||||
requestContentType = @"multipart/form-data";
|
||||
if(bodyDictionary == nil) {
|
||||
bodyDictionary = [[NSMutableArray alloc] init];
|
||||
}
|
||||
if({{paramName}} != nil) {
|
||||
[bodyDictionary addObject:{{paramName}}];
|
||||
{{paramName}}.paramName = @"{{baseName}}";
|
||||
}
|
||||
{{/isFile}}
|
||||
if(bodyDictionary == nil) {
|
||||
bodyDictionary = [[NSMutableArray alloc] init];
|
||||
}
|
||||
[bodyDictionary addObject:formParams];
|
||||
{{/formParams}}
|
||||
{{/bodyParam}}
|
||||
|
||||
{{#requiredParamCount}}
|
||||
{{#requiredParams}}
|
||||
if({{paramName}} == nil) {
|
||||
// error
|
||||
}
|
||||
{{/requiredParams}}
|
||||
{{/requiredParamCount}}
|
||||
|
||||
{{#returnContainer}}
|
||||
// response is in a container
|
||||
{{>apiBodyResponseWithContainer}}{{/returnContainer}}
|
||||
|
||||
{{#returnSimpleType}}
|
||||
// non container response
|
||||
|
||||
{{#returnTypeIsPrimitive}}
|
||||
// primitive response
|
||||
{{>apiPrimitiveResponse}}{{/returnTypeIsPrimitive}}
|
||||
|
||||
{{#returnBaseType}}
|
||||
// complex response
|
||||
{{>apiNonPrimitiveResponse}}{{/returnBaseType}}
|
||||
{{/returnSimpleType}}
|
||||
|
||||
{{^returnSimpleType}}{{^returnContainer}}
|
||||
// it's void
|
||||
{{>voidResponse}}
|
||||
{{/returnContainer}}{{/returnSimpleType}}
|
||||
}
|
||||
bodyDictionary = objs;
|
||||
}
|
||||
else if([__body respondsToSelector:@selector(toDictionary)]) {
|
||||
bodyDictionary = [(SWGObject*)__body toDictionary];
|
||||
}
|
||||
else if([__body isKindOfClass:[NSString class]]) {
|
||||
// convert it to a dictionary
|
||||
NSError * error;
|
||||
NSString * str = (NSString*)__body;
|
||||
NSDictionary *JSON =
|
||||
[NSJSONSerialization JSONObjectWithData: [str dataUsingEncoding: NSUTF8StringEncoding]
|
||||
options: NSJSONReadingMutableContainers
|
||||
error: &error];
|
||||
bodyDictionary = JSON;
|
||||
}
|
||||
{{/bodyParam}}
|
||||
{{^bodyParam}}
|
||||
|
||||
{{/operation}}
|
||||
NSMutableDictionary * formParams = [[NSMutableDictionary alloc]init];
|
||||
|
||||
{{newline}}
|
||||
{{#formParams}}
|
||||
{{#notFile}}
|
||||
formParams[@"{{paramName}}"] = {{paramName}};
|
||||
{{/notFile}}{{#isFile}}
|
||||
requestContentType = @"multipart/form-data";
|
||||
if(bodyDictionary == nil) {
|
||||
bodyDictionary = [[NSMutableArray alloc] init];
|
||||
}
|
||||
if({{paramName}} != nil) {
|
||||
[bodyDictionary addObject:{{paramName}}];
|
||||
{{paramName}}.paramName = @"{{baseName}}";
|
||||
}
|
||||
{{/isFile}}
|
||||
if(bodyDictionary == nil) {
|
||||
bodyDictionary = [[NSMutableArray alloc] init];
|
||||
}
|
||||
[bodyDictionary addObject:formParams];
|
||||
{{/formParams}}
|
||||
{{/bodyParam}}
|
||||
|
||||
{{#requiredParamCount}}
|
||||
{{#requiredParams}}
|
||||
if({{paramName}} == nil) {
|
||||
// error
|
||||
}
|
||||
{{/requiredParams}}
|
||||
{{/requiredParamCount}}
|
||||
|
||||
{{#returnContainer}}
|
||||
// response is in a container
|
||||
{{>apiBodyResponseWithContainer}}{{/returnContainer}}
|
||||
|
||||
{{#returnSimpleType}}
|
||||
// non container response
|
||||
|
||||
{{#returnTypeIsPrimitive}}
|
||||
// primitive response
|
||||
{{>apiPrimitiveResponse}}{{/returnTypeIsPrimitive}}
|
||||
|
||||
{{#returnBaseType}}
|
||||
// complex response
|
||||
{{>apiNonPrimitiveResponse}}{{/returnBaseType}}
|
||||
{{/returnSimpleType}}
|
||||
|
||||
{{^returnSimpleType}}{{^returnContainer}}
|
||||
// it's void
|
||||
{{>voidResponse}}
|
||||
{{/returnContainer}}{{/returnSimpleType}}
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
|
||||
{{newline}}
|
||||
{{/operations}}
|
||||
@end
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#import
|
||||
<Foundation/Foundation.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
{{#imports}}#import "{{import}}.h"
|
||||
{{/imports}}
|
||||
#import "SWGObject.h"
|
||||
@@ -7,36 +6,36 @@
|
||||
{{newline}}
|
||||
|
||||
{{#operations}}
|
||||
@interface {{classname}}: NSObject
|
||||
@interface {{classname}}: NSObject
|
||||
|
||||
@property(nonatomic, assign)SWGApiClient *apiClient;
|
||||
@property(nonatomic, assign)SWGApiClient *apiClient;
|
||||
|
||||
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient;
|
||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
|
||||
-(unsigned long) requestQueueSize;
|
||||
+({{classname}}*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
||||
+(void) setBasePath:(NSString*)basePath;
|
||||
+(NSString*) getBasePath;
|
||||
{{#operation}}
|
||||
/**
|
||||
-(instancetype) initWithApiClient:(SWGApiClient *)apiClient;
|
||||
-(void) addHeader:(NSString*)value forKey:(NSString*)key;
|
||||
-(unsigned long) requestQueueSize;
|
||||
+({{classname}}*) apiWithHeader:(NSString*)headerValue key:(NSString*)key;
|
||||
+(void) setBasePath:(NSString*)basePath;
|
||||
+(NSString*) getBasePath;
|
||||
{{#operation}}
|
||||
/**
|
||||
|
||||
{{{summary}}}
|
||||
{{#notes}}{{{notes}}}{{/notes}}
|
||||
{{{summary}}}
|
||||
{{#notes}}{{{notes}}}{{/notes}}
|
||||
|
||||
{{#allParams}}@param {{paramName}} {{description}}
|
||||
{{/allParams}}
|
||||
{{#allParams}}@param {{paramName}} {{description}}
|
||||
{{/allParams}}
|
||||
|
||||
return type: {{{returnType}}}
|
||||
*/
|
||||
-(NSNumber*) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}} {{#hasMore}}
|
||||
{{/hasMore}}{{/allParams}}
|
||||
{{#returnBaseType}}{{#hasParams}}
|
||||
completionHandler: {{/hasParams}}(void (^)({{{returnType}}} output, NSError* error))completionBlock;{{/returnBaseType}}
|
||||
{{^returnBaseType}}{{#hasParams}}
|
||||
completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock;{{/returnBaseType}}
|
||||
return type: {{{returnType}}}
|
||||
*/
|
||||
-(NSNumber*) {{nickname}}WithCompletionBlock {{^allParams}}:{{/allParams}}{{#allParams}}{{#secondaryParam}} {{paramName}}{{/secondaryParam}}:({{{dataType}}}) {{paramName}} {{#hasMore}}
|
||||
{{/hasMore}}{{/allParams}}
|
||||
{{#returnBaseType}}{{#hasParams}}
|
||||
completionHandler: {{/hasParams}}(void (^)({{{returnType}}} output, NSError* error))completionBlock;{{/returnBaseType}}
|
||||
{{^returnBaseType}}{{#hasParams}}
|
||||
completionHandler: {{/hasParams}}(void (^)(NSError* error))completionBlock;{{/returnBaseType}}
|
||||
|
||||
{{newline}}
|
||||
{{/operation}}
|
||||
{{newline}}
|
||||
{{/operation}}
|
||||
|
||||
{{/operations}}
|
||||
@end
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
// {{returnContainer}} container response type
|
||||
return [self.apiClient dictionary: requestUrl
|
||||
method: @"{{httpMethod}}"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
authSettings: authSettings
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
{{#returnBaseType}}completionBlock(nil, error);{{/returnBaseType}}{{^returnBaseType}}completionBlock(error);{{/returnBaseType}}
|
||||
return;
|
||||
}
|
||||
{{#isMapContainer}}
|
||||
NSDictionary *result = nil;
|
||||
if (data) {
|
||||
result = [[NSDictionary alloc]initWithDictionary: data];
|
||||
}
|
||||
completionBlock(data, nil);
|
||||
{{/isMapContainer}}{{#isListContainer}}
|
||||
{{#returnBaseType}}if([data isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
|
||||
for (NSDictionary* dict in (NSArray*)data) {
|
||||
{{#returnTypeIsPrimitive}}
|
||||
{{returnBaseType}}* d = [[{{{returnBaseType}}} alloc]initWithString: dict];
|
||||
{{/returnTypeIsPrimitive}}
|
||||
{{^returnTypeIsPrimitive}}
|
||||
{{{returnBaseType}}}* d = [[{{{returnBaseType}}} alloc] initWithDictionary:dict error:nil];
|
||||
{{/returnTypeIsPrimitive}}
|
||||
[objs addObject:d];
|
||||
}
|
||||
completionBlock(({{{returnType}}})objs, nil);
|
||||
}
|
||||
{{/returnBaseType}}
|
||||
{{/isListContainer}}
|
||||
}];
|
||||
// {{returnContainer}} container response type
|
||||
return [self.apiClient dictionary: requestUrl
|
||||
method: @"{{httpMethod}}"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
authSettings: authSettings
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
{{#returnBaseType}}completionBlock(nil, error);{{/returnBaseType}}{{^returnBaseType}}completionBlock(error);{{/returnBaseType}}
|
||||
return;
|
||||
}
|
||||
{{#isMapContainer}}
|
||||
NSDictionary *result = nil;
|
||||
if (data) {
|
||||
result = [[NSDictionary alloc]initWithDictionary: data];
|
||||
}
|
||||
completionBlock(data, nil);
|
||||
{{/isMapContainer}}{{#isListContainer}}
|
||||
{{#returnBaseType}}if([data isKindOfClass:[NSArray class]]){
|
||||
NSMutableArray * objs = [[NSMutableArray alloc] initWithCapacity:[data count]];
|
||||
for (NSDictionary* dict in (NSArray*)data) {
|
||||
{{#returnTypeIsPrimitive}}
|
||||
{{returnBaseType}}* d = [[{{{returnBaseType}}} alloc]initWithString: dict];
|
||||
{{/returnTypeIsPrimitive}}
|
||||
{{^returnTypeIsPrimitive}}
|
||||
{{{returnBaseType}}}* d = [[{{{returnBaseType}}} alloc] initWithDictionary:dict error:nil];
|
||||
{{/returnTypeIsPrimitive}}
|
||||
[objs addObject:d];
|
||||
}
|
||||
completionBlock(({{{returnType}}})objs, nil);
|
||||
}
|
||||
{{/returnBaseType}}
|
||||
{{/isListContainer}}
|
||||
}];
|
||||
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
{{^returnTypeIsPrimitive}}
|
||||
{{^returnTypeIsPrimitive}}
|
||||
// comples response type
|
||||
return [self.apiClient dictionary: requestUrl
|
||||
method: @"{{httpMethod}}"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
authSettings: authSettings
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
{{#returnBaseType}}completionBlock(nil, error);{{/returnBaseType}}
|
||||
{{^returnBaseType}}completionBlock(error);{{/returnBaseType}}
|
||||
return;
|
||||
}
|
||||
{{#returnType}}{{returnType}} result = nil;
|
||||
if (data) {
|
||||
result = [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc] {{#returnContainer}}{{#isMapContainer}}initWithDictionary{{/isMapContainer}}{{#isListContainer}} initWithDictionary{{/isListContainer}}{{/returnContainer}}{{^returnContainer}} initWithDictionary{{/returnContainer}}:data error:nil];
|
||||
}
|
||||
{{#returnType}}completionBlock(result , nil);{{/returnType}}
|
||||
{{/returnType}}
|
||||
}];
|
||||
{{/returnTypeIsPrimitive}}
|
||||
method: @"{{httpMethod}}"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
authSettings: authSettings
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSDictionary *data, NSError *error) {
|
||||
if (error) {
|
||||
{{#returnBaseType}}completionBlock(nil, error);{{/returnBaseType}}
|
||||
{{^returnBaseType}}completionBlock(error);{{/returnBaseType}}
|
||||
return;
|
||||
}
|
||||
{{#returnType}}{{returnType}} result = nil;
|
||||
if (data) {
|
||||
result = [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc] {{#returnContainer}}{{#isMapContainer}}initWithDictionary{{/isMapContainer}}{{#isListContainer}} initWithDictionary{{/isListContainer}}{{/returnContainer}}{{^returnContainer}} initWithDictionary{{/returnContainer}}:data error:nil];
|
||||
}
|
||||
{{#returnType}}completionBlock(result , nil);{{/returnType}}
|
||||
{{/returnType}}
|
||||
}];
|
||||
{{/returnTypeIsPrimitive}}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
// primitive response type
|
||||
{{#returnBaseType}}return [self.apiClient stringWithCompletionBlock: requestUrl
|
||||
method: @"{{httpMethod}}"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
authSettings: authSettings
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSString *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);
|
||||
return;
|
||||
}
|
||||
{{returnBaseType}} *result = data ? [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc]initWithString: data] : nil;
|
||||
completionBlock(result, nil);
|
||||
}];
|
||||
{{/returnBaseType}}
|
||||
{{^returnBaseType}}
|
||||
// primitive response type
|
||||
{{#returnBaseType}}return [self.apiClient stringWithCompletionBlock: requestUrl
|
||||
method: @"{{httpMethod}}"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
authSettings: authSettings
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSString *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(nil, error);
|
||||
return;
|
||||
}
|
||||
{{returnBaseType}} *result = data ? [[{{#instantiationType}}NSClassFromString(@"{{{instantiationType}}}") {{/instantiationType}}{{^instantiationType}}{{{returnBaseType}}} {{/instantiationType}} alloc]initWithString: data] : nil;
|
||||
completionBlock(result, nil);
|
||||
}];
|
||||
{{/returnBaseType}}
|
||||
{{^returnBaseType}}
|
||||
// no return base type
|
||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
||||
method: @"{{httpMethod}}"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSString *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(error);
|
||||
return;
|
||||
}
|
||||
completionBlock(nil);
|
||||
}];
|
||||
{{/returnBaseType}}
|
||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
||||
method: @"{{httpMethod}}"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSString *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(error);
|
||||
return;
|
||||
}
|
||||
completionBlock(nil);
|
||||
}];
|
||||
{{/returnBaseType}}
|
||||
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
#import "{{classname}}.h"
|
||||
{{#model}}
|
||||
#import "{{classname}}.h"
|
||||
|
||||
@implementation {{classname}}
|
||||
@implementation {{classname}}
|
||||
|
||||
+ (JSONKeyMapper *)keyMapper
|
||||
{
|
||||
return [[JSONKeyMapper alloc] initWithDictionary:@{ {{#vars}}@"{{baseName}}": @"{{name}}"{{#hasMore}}, {{/hasMore}}{{/vars}} }];
|
||||
}
|
||||
|
||||
+ (JSONKeyMapper *)keyMapper
|
||||
{
|
||||
return [[JSONKeyMapper alloc] initWithDictionary:@{ {{#vars}}@"{{baseName}}": @"{{name}}"{{#hasMore}}, {{/hasMore}}{{/vars}} }];
|
||||
}
|
||||
+ (BOOL)propertyIsOptional:(NSString *)propertyName
|
||||
{
|
||||
NSArray *optionalProperties = @[{{#vars}}{{^required}}@"{{name}}"{{#hasMore}}, {{/hasMore}}{{/required}}{{/vars}}];
|
||||
|
||||
+ (BOOL)propertyIsOptional:(NSString *)propertyName
|
||||
{
|
||||
NSArray *optionalProperties = @[{{#vars}}{{^required}}@"{{name}}"{{#hasMore}}, {{/hasMore}}{{/required}}{{/vars}}];
|
||||
if ([optionalProperties containsObject:propertyName]) {
|
||||
return YES;
|
||||
}
|
||||
else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
if ([optionalProperties containsObject:propertyName]) {
|
||||
return YES;
|
||||
}
|
||||
else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
{{/model}}
|
||||
@end
|
||||
{{/model}}
|
||||
@end
|
||||
{{/models}}
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
#import
|
||||
<Foundation/Foundation.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SWGObject.h"
|
||||
{{#imports}}#import "{{import}}.h"
|
||||
{{/imports}}
|
||||
{{newline}}
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{#model}}
|
||||
|
||||
@protocol {{classname}}
|
||||
@end
|
||||
@protocol {{classname}}
|
||||
@end
|
||||
|
||||
@interface {{classname}} : SWGObject
|
||||
|
||||
@interface {{classname}} : SWGObject
|
||||
{{#vars}}
|
||||
{{#description}}/* {{{description}}} {{^required}}[optional]{{/required}}
|
||||
*/{{/description}}
|
||||
@property(nonatomic) {{{ datatype }}} {{name}};
|
||||
{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
{{#description}}/* {{{description}}} {{^required}}[optional]{{/required}}
|
||||
*/{{/description}}
|
||||
@property(nonatomic) {{{ datatype }}} {{name}};
|
||||
{{/vars}}
|
||||
|
||||
@end
|
||||
{{/model}}
|
||||
@end
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
||||
method: @"{{httpMethod}}"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
authSettings: authSettings
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSString *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(error);
|
||||
return;
|
||||
}
|
||||
completionBlock(nil);
|
||||
}];
|
||||
return [self.apiClient stringWithCompletionBlock: requestUrl
|
||||
method: @"{{httpMethod}}"
|
||||
queryParams: queryParams
|
||||
body: bodyDictionary
|
||||
headerParams: headerParams
|
||||
authSettings: authSettings
|
||||
requestContentType: requestContentType
|
||||
responseContentType: responseContentType
|
||||
completionBlock: ^(NSString *data, NSError *error) {
|
||||
if (error) {
|
||||
completionBlock(error);
|
||||
return;
|
||||
}
|
||||
completionBlock(nil);
|
||||
}];
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user