mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 02:55:19 +00:00
added android client
This commit is contained in:
parent
cfa1f1a3c1
commit
609cef0b65
35
bin/android-java-petstore.sh
Executable file
35
bin/android-java-petstore.sh
Executable file
@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
cd $APP_DIR
|
||||
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ samples/client/petstore/android-java/AndroidJavaPetstoreCodegen.scala http://petstore.swagger.wordnik.com/api/api-docs special-key"
|
||||
|
||||
if [ -f $APP_DIR/target/scala-2.9.1/swagger-codegen.jar ]; then
|
||||
scala -cp target/scala-2.9.1/swagger-codegen.jar $ags
|
||||
elif [[ -f $APP_DIR/target/scala-2.10/swagger-codegen.jar ]]; then
|
||||
scala -cp target/scala-2.10/swagger-codegen.jar $ags
|
||||
else
|
||||
./sbt assembly
|
||||
scala -cp target/swagger-codegen.jar $ags
|
||||
fi
|
||||
|
@ -5,7 +5,7 @@ organization := "com.wordnik"
|
||||
|
||||
name := "swagger-codegen"
|
||||
|
||||
version := "2.0.9-SNAPSHOT"
|
||||
version := "2.0.10-SNAPSHOT"
|
||||
|
||||
scalaVersion := "2.9.1"
|
||||
|
||||
@ -55,13 +55,6 @@ publishTo <<= (version) { version: String =>
|
||||
Some("Sonatype Nexus Releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2")
|
||||
}
|
||||
|
||||
publishTo <<= (version) { version: String =>
|
||||
val artifactory = "https://ci.aws.wordnik.com/artifactory/m2-"
|
||||
if (version.trim.endsWith("SNAPSHOT"))
|
||||
Some("snapshots" at artifactory + "snapshots")
|
||||
else
|
||||
Some("releases" at artifactory + "releases")
|
||||
}
|
||||
|
||||
//publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath+"/.m2/repository")))
|
||||
|
||||
|
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright 2013 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import com.wordnik.swagger.codegen.BasicJavaGenerator
|
||||
|
||||
object AndroidJavaPetstoreCodegen extends BasicJavaGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
|
||||
// location of templates
|
||||
override def templateDir = "android-java"
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = "samples/client/petstore/android-java/src/main/java"
|
||||
|
||||
// package for api invoker, error files
|
||||
override def invokerPackage = Some("com.wordnik.client")
|
||||
|
||||
// package for models
|
||||
override def modelPackage = Some("com.wordnik.petstore.model")
|
||||
|
||||
// package for api classes
|
||||
override def apiPackage = Some("com.wordnik.petstore.api")
|
||||
|
||||
additionalParams ++= Map(
|
||||
"artifactId" -> "swagger-petstore",
|
||||
"artifactVersion" -> "1.0.0",
|
||||
"groupId" -> "com.wordnik")
|
||||
|
||||
// supporting classes
|
||||
override def supportingFiles = List(
|
||||
("apiInvoker.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiInvoker.java"),
|
||||
("jsonUtil.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "JsonUtil.java"),
|
||||
("apiException.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiException.java"),
|
||||
("pom.mustache", "samples/client/petstore/android-java", "pom.xml")
|
||||
)
|
||||
}
|
214
samples/client/petstore/android-java/pom.xml
Normal file
214
samples/client/petstore/android-java/pom.xml
Normal file
@ -0,0 +1,214 @@
|
||||
<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>com.wordnik</groupId>
|
||||
<artifactId>swagger-petstore</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>swagger-petstore</name>
|
||||
<version>1.0.0</version>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:wordnik/swagger-mustache.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:wordnik/swagger-codegen.git</developerConnection>
|
||||
<url>https://github.com/wordnik/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>
|
||||
|
||||
<!-- 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>
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<version>${scala-maven-plugin-version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<configuration>
|
||||
<recompileMode>incremental</recompileMode>
|
||||
</configuration>
|
||||
<jvmArgs>
|
||||
<jvmArg>-Xmx384m</jvmArg>
|
||||
</jvmArgs>
|
||||
<args>
|
||||
<arg>-target:jvm-1.5</arg>
|
||||
<arg>-deprecation</arg>
|
||||
</args>
|
||||
<launchers>
|
||||
<launcher>
|
||||
<id>run-scalatest</id>
|
||||
<mainClass>org.scalatest.tools.Runner</mainClass>
|
||||
<args>
|
||||
<arg>-p</arg>
|
||||
<arg>${project.build.testOutputDirectory}</arg>
|
||||
</args>
|
||||
<jvmArgs>
|
||||
<jvmArg>-Xmx512m</jvmArg>
|
||||
</jvmArgs>
|
||||
</launcher>
|
||||
</launchers>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<version>${scala-maven-plugin-version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.scala-lang</groupId>
|
||||
<artifactId>scala-library</artifactId>
|
||||
<version>${scala-version}</version>
|
||||
<scope>test</scope>
|
||||
</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>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<jackson-version>2.1.4</jackson-version>
|
||||
<scala-version>2.9.1-1</scala-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<scala-test-version>1.6.1</scala-test-version>
|
||||
<httpclient-version>4.2.3</httpclient-version>
|
||||
<scala-maven-plugin-version>3.1.5</scala-maven-plugin-version>
|
||||
</properties>
|
||||
</project>
|
||||
|
@ -0,0 +1,29 @@
|
||||
package com.wordnik.client;
|
||||
|
||||
public class ApiException extends Exception {
|
||||
int code = 0;
|
||||
String message = null;
|
||||
|
||||
public ApiException() {}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,174 @@
|
||||
package com.wordnik.client;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator.Feature;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
import org.apache.http.*;
|
||||
import org.apache.http.client.*;
|
||||
import org.apache.http.client.methods.*;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.*;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class ApiInvoker {
|
||||
private static ApiInvoker INSTANCE = new ApiInvoker();
|
||||
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
|
||||
private HttpClient client = null;
|
||||
public static ApiInvoker getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void addDefaultHeader(String key, String value) {
|
||||
defaultHeaderMap.put(key, value);
|
||||
}
|
||||
|
||||
public String escapeString(String str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
||||
try{
|
||||
if("List".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());
|
||||
}
|
||||
}
|
||||
|
||||
public static 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());
|
||||
}
|
||||
}
|
||||
|
||||
public String invokeAPI(String host, String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, 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();
|
||||
|
||||
HashMap<String, String> headers = new HashMap<String, String>();
|
||||
|
||||
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");
|
||||
|
||||
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);
|
||||
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(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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(response.getEntity() != null) {
|
||||
HttpEntity resEntity = response.getEntity();
|
||||
responseString = EntityUtils.toString(resEntity);
|
||||
}
|
||||
else
|
||||
responseString = "no data";
|
||||
throw new ApiException(code, responseString);
|
||||
}
|
||||
return responseString;
|
||||
}
|
||||
catch(IOException e) {
|
||||
throw new ApiException(500, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private HttpClient getClient(String host) {
|
||||
if(client == null)
|
||||
client = new DefaultHttpClient();
|
||||
return client;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.wordnik.client;
|
||||
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.core.JsonGenerator.Feature;
|
||||
|
||||
public class JsonUtil {
|
||||
public static ObjectMapper mapper;
|
||||
|
||||
static {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
}
|
||||
|
||||
public static ObjectMapper getJsonMapper() {
|
||||
return mapper;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,309 @@
|
||||
package com.wordnik.petstore.api;
|
||||
|
||||
import com.wordnik.client.ApiException;
|
||||
import com.wordnik.client.ApiInvoker;
|
||||
import java.io.File;
|
||||
import com.wordnik.petstore.model.Pet;
|
||||
import java.util.*;
|
||||
|
||||
public class PetApi {
|
||||
String basePath = "http://petstore.swagger.wordnik.com/api";
|
||||
ApiInvoker apiInvoker = ApiInvoker.getInstance();
|
||||
|
||||
public void addHeader(String key, String value) {
|
||||
getInvoker().addDefaultHeader(key, value);
|
||||
}
|
||||
|
||||
public ApiInvoker getInvoker() {
|
||||
return apiInvoker;
|
||||
}
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public Pet getPetById (Long petId) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(petId == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
|
||||
if(response != null){
|
||||
return (Pet) ApiInvoker.deserialize(response, "", Pet.class);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void deletePet (String petId) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(petId == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "DELETE", queryParams, null, headerParams, contentType);
|
||||
if(response != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public List<Pet> partialUpdate (String petId, Pet body) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(petId == null || body == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "PATCH", queryParams, body, headerParams, contentType);
|
||||
if(response != null){
|
||||
return (List<Pet>) ApiInvoker.deserialize(response, "Array", Pet.class);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void updatePetWithForm (String petId, String name, String status) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(petId == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, null, headerParams, contentType);
|
||||
if(response != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void uploadFile (String additionalMetadata, File body) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/pet/uploadImage".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
|
||||
if(response != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void addPet (Pet body) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/pet".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(body == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
|
||||
if(response != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void updatePet (Pet body) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/pet".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(body == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "PUT", queryParams, body, headerParams, contentType);
|
||||
if(response != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public List<Pet> findPetsByStatus (String status) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/pet/findByStatus".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(status == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
if(!"null".equals(String.valueOf(status)))
|
||||
queryParams.put("status", String.valueOf(status));
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
|
||||
if(response != null){
|
||||
return (List<Pet>) ApiInvoker.deserialize(response, "Array", Pet.class);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public List<Pet> findPetsByTags (String tags) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/pet/findByTags".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(tags == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
if(!"null".equals(String.valueOf(tags)))
|
||||
queryParams.put("tags", String.valueOf(tags));
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
|
||||
if(response != null){
|
||||
return (List<Pet>) ApiInvoker.deserialize(response, "Array", Pet.class);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,122 @@
|
||||
package com.wordnik.petstore.api;
|
||||
|
||||
import com.wordnik.client.ApiException;
|
||||
import com.wordnik.client.ApiInvoker;
|
||||
import com.wordnik.petstore.model.Order;
|
||||
import java.util.*;
|
||||
|
||||
public class StoreApi {
|
||||
String basePath = "http://petstore.swagger.wordnik.com/api";
|
||||
ApiInvoker apiInvoker = ApiInvoker.getInstance();
|
||||
|
||||
public void addHeader(String key, String value) {
|
||||
getInvoker().addDefaultHeader(key, value);
|
||||
}
|
||||
|
||||
public ApiInvoker getInvoker() {
|
||||
return apiInvoker;
|
||||
}
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public Order getOrderById (String orderId) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}", apiInvoker.escapeString(orderId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(orderId == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
|
||||
if(response != null){
|
||||
return (Order) ApiInvoker.deserialize(response, "", Order.class);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void deleteOrder (String orderId) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}", apiInvoker.escapeString(orderId.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(orderId == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "DELETE", queryParams, null, headerParams, contentType);
|
||||
if(response != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void placeOrder (Order body) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/store/order".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(body == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
|
||||
if(response != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,277 @@
|
||||
package com.wordnik.petstore.api;
|
||||
|
||||
import com.wordnik.client.ApiException;
|
||||
import com.wordnik.client.ApiInvoker;
|
||||
import com.wordnik.petstore.model.User;
|
||||
import java.util.*;
|
||||
|
||||
public class UserApi {
|
||||
String basePath = "http://petstore.swagger.wordnik.com/api";
|
||||
ApiInvoker apiInvoker = ApiInvoker.getInstance();
|
||||
|
||||
public void addHeader(String key, String value) {
|
||||
getInvoker().addDefaultHeader(key, value);
|
||||
}
|
||||
|
||||
public ApiInvoker getInvoker() {
|
||||
return apiInvoker;
|
||||
}
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public void createUser (User body) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/user".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(body == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
|
||||
if(response != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void createUsersWithArrayInput (List<User> body) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/user/createWithArray".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(body == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
|
||||
if(response != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void createUsersWithListInput (List<User> body) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/user/createWithList".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(body == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
|
||||
if(response != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void updateUser (String username, User body) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(username == null || body == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "PUT", queryParams, body, headerParams, contentType);
|
||||
if(response != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void deleteUser (String username) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(username == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "DELETE", queryParams, null, headerParams, contentType);
|
||||
if(response != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public User getUserByName (String username) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString()));
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(username == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
|
||||
if(response != null){
|
||||
return (User) ApiInvoker.deserialize(response, "", User.class);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public String loginUser (String username, String password) throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/user/login".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
// verify required params are set
|
||||
if(username == null || password == null ) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
if(!"null".equals(String.valueOf(username)))
|
||||
queryParams.put("username", String.valueOf(username));
|
||||
if(!"null".equals(String.valueOf(password)))
|
||||
queryParams.put("password", String.valueOf(password));
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
|
||||
if(response != null){
|
||||
return (String) ApiInvoker.deserialize(response, "", String.class);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void logoutUser () throws ApiException {
|
||||
// create path and map variables
|
||||
String path = "/user/logout".replaceAll("\\{format\\}","json");
|
||||
|
||||
// query params
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
|
||||
if(response != null){
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
return ;
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return ;
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.wordnik.petstore.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class Category {
|
||||
/* Category unique identifier */
|
||||
@JsonProperty("id")
|
||||
private Long id = null;
|
||||
/* Name of the category */
|
||||
@JsonProperty("name")
|
||||
private String name = null;
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class Category {\n");
|
||||
sb.append(" id: ").append(id).append("\n");
|
||||
sb.append(" name: ").append(name).append("\n");
|
||||
sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,70 @@
|
||||
package com.wordnik.petstore.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.Date;
|
||||
public class Order {
|
||||
/* Unique identifier for the order */
|
||||
@JsonProperty("id")
|
||||
private Long id = null;
|
||||
/* ID of pet being ordered */
|
||||
@JsonProperty("petId")
|
||||
private Long petId = null;
|
||||
/* Number of pets ordered */
|
||||
@JsonProperty("quantity")
|
||||
private Integer quantity = null;
|
||||
/* Status of the order */
|
||||
@JsonProperty("status")
|
||||
private String status = null;
|
||||
/* Date shipped, only if it has been */
|
||||
@JsonProperty("shipDate")
|
||||
private Date shipDate = null;
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getPetId() {
|
||||
return petId;
|
||||
}
|
||||
public void setPetId(Long petId) {
|
||||
this.petId = petId;
|
||||
}
|
||||
|
||||
public Integer getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
public void setQuantity(Integer quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Date getShipDate() {
|
||||
return shipDate;
|
||||
}
|
||||
public void setShipDate(Date shipDate) {
|
||||
this.shipDate = shipDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class Order {\n");
|
||||
sb.append(" id: ").append(id).append("\n");
|
||||
sb.append(" petId: ").append(petId).append("\n");
|
||||
sb.append(" quantity: ").append(quantity).append("\n");
|
||||
sb.append(" status: ").append(status).append("\n");
|
||||
sb.append(" shipDate: ").append(shipDate).append("\n");
|
||||
sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,83 @@
|
||||
package com.wordnik.petstore.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.*;
|
||||
import com.wordnik.petstore.model.Category;
|
||||
import com.wordnik.petstore.model.Tag;
|
||||
public class Pet {
|
||||
/* Unique identifier for the Pet */
|
||||
@JsonProperty("id")
|
||||
private Long id = null;
|
||||
/* Category the pet is in */
|
||||
@JsonProperty("category")
|
||||
private Category category = null;
|
||||
/* Friendly name of the pet */
|
||||
@JsonProperty("name")
|
||||
private String name = null;
|
||||
/* Image URLs */
|
||||
@JsonProperty("photoUrls")
|
||||
private List<String> photoUrls = new ArrayList<String>();
|
||||
/* Tags assigned to this pet */
|
||||
@JsonProperty("tags")
|
||||
private List<Tag> tags = new ArrayList<Tag>();
|
||||
/* pet status in the store */
|
||||
@JsonProperty("status")
|
||||
private String status = null;
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Category getCategory() {
|
||||
return category;
|
||||
}
|
||||
public void setCategory(Category category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<String> getPhotoUrls() {
|
||||
return photoUrls;
|
||||
}
|
||||
public void setPhotoUrls(List<String> photoUrls) {
|
||||
this.photoUrls = photoUrls;
|
||||
}
|
||||
|
||||
public List<Tag> getTags() {
|
||||
return tags;
|
||||
}
|
||||
public void setTags(List<Tag> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class Pet {\n");
|
||||
sb.append(" id: ").append(id).append("\n");
|
||||
sb.append(" category: ").append(category).append("\n");
|
||||
sb.append(" name: ").append(name).append("\n");
|
||||
sb.append(" photoUrls: ").append(photoUrls).append("\n");
|
||||
sb.append(" tags: ").append(tags).append("\n");
|
||||
sb.append(" status: ").append(status).append("\n");
|
||||
sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.wordnik.petstore.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class Tag {
|
||||
/* Unique identifier for the tag */
|
||||
@JsonProperty("id")
|
||||
private Long id = null;
|
||||
/* Friendly name for the tag */
|
||||
@JsonProperty("name")
|
||||
private String name = null;
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class Tag {\n");
|
||||
sb.append(" id: ").append(id).append("\n");
|
||||
sb.append(" name: ").append(name).append("\n");
|
||||
sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,102 @@
|
||||
package com.wordnik.petstore.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class User {
|
||||
/* Unique identifier for the user */
|
||||
@JsonProperty("id")
|
||||
private Long id = null;
|
||||
/* Unique username */
|
||||
@JsonProperty("username")
|
||||
private String username = null;
|
||||
/* First name of the user */
|
||||
@JsonProperty("firstName")
|
||||
private String firstName = null;
|
||||
/* Last name of the user */
|
||||
@JsonProperty("lastName")
|
||||
private String lastName = null;
|
||||
/* Email address of the user */
|
||||
@JsonProperty("email")
|
||||
private String email = null;
|
||||
/* Password name of the user */
|
||||
@JsonProperty("password")
|
||||
private String password = null;
|
||||
/* Phone number of the user */
|
||||
@JsonProperty("phone")
|
||||
private String phone = null;
|
||||
/* User Status */
|
||||
@JsonProperty("userStatus")
|
||||
private Integer userStatus = null;
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public Integer getUserStatus() {
|
||||
return userStatus;
|
||||
}
|
||||
public void setUserStatus(Integer userStatus) {
|
||||
this.userStatus = userStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class User {\n");
|
||||
sb.append(" id: ").append(id).append("\n");
|
||||
sb.append(" username: ").append(username).append("\n");
|
||||
sb.append(" firstName: ").append(firstName).append("\n");
|
||||
sb.append(" lastName: ").append(lastName).append("\n");
|
||||
sb.append(" email: ").append(email).append("\n");
|
||||
sb.append(" password: ").append(password).append("\n");
|
||||
sb.append(" phone: ").append(phone).append("\n");
|
||||
sb.append(" userStatus: ").append(userStatus).append("\n");
|
||||
sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
import com.wordnik.swagger.client._
|
||||
import com.wordnik.samples.petstore._
|
||||
import akka.dispatch._
|
||||
import akka.util.duration._
|
||||
|
||||
val cfg = SwaggerConfig("http://petstore.swagger.wordnik.com/api")
|
||||
val client = new Petstore(cfg)
|
||||
try { Await.result(client.pet.findPetsByStatus(), 3 seconds) } finally { client.close() }
|
75
src/main/resources/android-java/api.mustache
Normal file
75
src/main/resources/android-java/api.mustache
Normal file
@ -0,0 +1,75 @@
|
||||
package {{package}};
|
||||
|
||||
import {{invokerPackage}}.ApiException;
|
||||
import {{invokerPackage}}.ApiInvoker;
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
import java.util.*;
|
||||
|
||||
{{#operations}}
|
||||
public class {{classname}} {
|
||||
String basePath = "{{basePath}}";
|
||||
ApiInvoker apiInvoker = ApiInvoker.getInstance();
|
||||
|
||||
public void addHeader(String key, String value) {
|
||||
getInvoker().addDefaultHeader(key, value);
|
||||
}
|
||||
|
||||
public ApiInvoker getInvoker() {
|
||||
return apiInvoker;
|
||||
}
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
{{#operation}}
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||
// 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>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
|
||||
{{#requiredParamCount}}
|
||||
// verify required params are set
|
||||
if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) {
|
||||
throw new ApiException(400, "missing required params");
|
||||
}
|
||||
{{/requiredParamCount}}
|
||||
|
||||
{{#queryParams}}if(!"null".equals(String.valueOf({{paramName}})))
|
||||
queryParams.put("{{paramName}}", String.valueOf({{paramName}}));
|
||||
{{/queryParams}}
|
||||
|
||||
{{#headerParams}}headerParams.put("{{paramName}}", {{paramName}});
|
||||
{{/headerParams}}
|
||||
|
||||
String contentType = "application/json";
|
||||
|
||||
try {
|
||||
String response = apiInvoker.invokeAPI(basePath, path, "{{httpMethod}}", queryParams, {{#bodyParam}}{{bodyParam}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}, headerParams, contentType);
|
||||
if(response != null){
|
||||
return {{#returnType}}({{{returnType}}}) ApiInvoker.deserialize(response, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}};
|
||||
}
|
||||
else {
|
||||
return {{#returnType}}null{{/returnType}};
|
||||
}
|
||||
} catch (ApiException ex) {
|
||||
if(ex.getCode() == 404) {
|
||||
return {{#returnType}} null{{/returnType}};
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
29
src/main/resources/android-java/apiException.mustache
Normal file
29
src/main/resources/android-java/apiException.mustache
Normal file
@ -0,0 +1,29 @@
|
||||
package {{invokerPackage}};
|
||||
|
||||
public class ApiException extends Exception {
|
||||
int code = 0;
|
||||
String message = null;
|
||||
|
||||
public ApiException() {}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
174
src/main/resources/android-java/apiInvoker.mustache
Normal file
174
src/main/resources/android-java/apiInvoker.mustache
Normal file
@ -0,0 +1,174 @@
|
||||
package {{invokerPackage}};
|
||||
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator.Feature;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
import org.apache.http.*;
|
||||
import org.apache.http.client.*;
|
||||
import org.apache.http.client.methods.*;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.*;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class ApiInvoker {
|
||||
private static ApiInvoker INSTANCE = new ApiInvoker();
|
||||
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
|
||||
private HttpClient client = null;
|
||||
public static ApiInvoker getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void addDefaultHeader(String key, String value) {
|
||||
defaultHeaderMap.put(key, value);
|
||||
}
|
||||
|
||||
public String escapeString(String str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
||||
try{
|
||||
if("List".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());
|
||||
}
|
||||
}
|
||||
|
||||
public static 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());
|
||||
}
|
||||
}
|
||||
|
||||
public String invokeAPI(String host, String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, 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();
|
||||
|
||||
HashMap<String, String> headers = new HashMap<String, String>();
|
||||
|
||||
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");
|
||||
|
||||
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);
|
||||
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(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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(response.getEntity() != null) {
|
||||
HttpEntity resEntity = response.getEntity();
|
||||
responseString = EntityUtils.toString(resEntity);
|
||||
}
|
||||
else
|
||||
responseString = "no data";
|
||||
throw new ApiException(code, responseString);
|
||||
}
|
||||
return responseString;
|
||||
}
|
||||
catch(IOException e) {
|
||||
throw new ApiException(500, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private HttpClient getClient(String host) {
|
||||
if(client == null)
|
||||
client = new DefaultHttpClient();
|
||||
return client;
|
||||
}
|
||||
}
|
20
src/main/resources/android-java/jsonUtil.mustache
Normal file
20
src/main/resources/android-java/jsonUtil.mustache
Normal file
@ -0,0 +1,20 @@
|
||||
package {{invokerPackage}};
|
||||
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.core.JsonGenerator.Feature;
|
||||
|
||||
public class JsonUtil {
|
||||
public static ObjectMapper mapper;
|
||||
|
||||
static {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
}
|
||||
|
||||
public static ObjectMapper getJsonMapper() {
|
||||
return mapper;
|
||||
}
|
||||
}
|
40
src/main/resources/android-java/model.mustache
Normal file
40
src/main/resources/android-java/model.mustache
Normal file
@ -0,0 +1,40 @@
|
||||
package {{package}};
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
public class {{classname}} {
|
||||
{{#vars}}
|
||||
|
||||
{{#description}}/* {{{description}}} */
|
||||
{{/description}}
|
||||
@JsonProperty("{{name}}")
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};
|
||||
{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
public {{{datatype}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatype}}} {{name}}) {
|
||||
this.{{name}} = {{name}};
|
||||
}
|
||||
|
||||
{{/vars}}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class {{classname}} {\n");
|
||||
{{#vars}}
|
||||
sb.append(" {{name}}: ").append({{name}}).append("\n");
|
||||
{{/vars}}
|
||||
sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
213
src/main/resources/android-java/pom.mustache
Normal file
213
src/main/resources/android-java/pom.mustache
Normal file
@ -0,0 +1,213 @@
|
||||
<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>com.wordnik</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>1.0.0</version>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:wordnik/swagger-mustache.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:wordnik/swagger-codegen.git</developerConnection>
|
||||
<url>https://github.com/wordnik/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>
|
||||
|
||||
<!-- 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>
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<version>${scala-maven-plugin-version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<configuration>
|
||||
<recompileMode>incremental</recompileMode>
|
||||
</configuration>
|
||||
<jvmArgs>
|
||||
<jvmArg>-Xmx384m</jvmArg>
|
||||
</jvmArgs>
|
||||
<args>
|
||||
<arg>-target:jvm-1.5</arg>
|
||||
<arg>-deprecation</arg>
|
||||
</args>
|
||||
<launchers>
|
||||
<launcher>
|
||||
<id>run-scalatest</id>
|
||||
<mainClass>org.scalatest.tools.Runner</mainClass>
|
||||
<args>
|
||||
<arg>-p</arg>
|
||||
<arg>${project.build.testOutputDirectory}</arg>
|
||||
</args>
|
||||
<jvmArgs>
|
||||
<jvmArg>-Xmx512m</jvmArg>
|
||||
</jvmArgs>
|
||||
</launcher>
|
||||
</launchers>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<version>${scala-maven-plugin-version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.scala-lang</groupId>
|
||||
<artifactId>scala-library</artifactId>
|
||||
<version>${scala-version}</version>
|
||||
<scope>test</scope>
|
||||
</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>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<jackson-version>2.1.4</jackson-version>
|
||||
<scala-version>2.9.1-1</scala-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<scala-test-version>1.6.1</scala-test-version>
|
||||
<httpclient-version>4.2.3</httpclient-version>
|
||||
<scala-maven-plugin-version>3.1.5</scala-maven-plugin-version>
|
||||
</properties>
|
||||
</project>
|
@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Copyright 2012 Wordnik, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import com.wordnik.swagger.codegen.BasicJavaGenerator
|
||||
|
||||
import com.wordnik.swagger.model._
|
||||
|
||||
object BasicAndroidJavaClient extends BasicJavaGenerator {
|
||||
def main(args: Array[String]) = generateClient(args)
|
||||
|
||||
override def templateDir = "src/main/resources/android-java"
|
||||
|
||||
override def typeMapping = super.typeMapping ++ Map(
|
||||
"file" -> "File")
|
||||
|
||||
override def importMapping = super.importMapping ++ Map(
|
||||
"Set" -> "java.util.Set")
|
||||
|
||||
override def defaultIncludes = Set(
|
||||
"Integer",
|
||||
"String",
|
||||
"Long",
|
||||
"Short",
|
||||
"Char",
|
||||
"Byte",
|
||||
"Float",
|
||||
"Double",
|
||||
"Boolean",
|
||||
"AnyRef",
|
||||
"Any")
|
||||
|
||||
additionalParams ++= Map(
|
||||
"artifactId" -> "swagger-android-client",
|
||||
"artifactVersion" -> "1.0.0",
|
||||
"groupId" -> "com.wordnik"
|
||||
)
|
||||
|
||||
// package for api invoker, error files
|
||||
override def invokerPackage = Some("com.wordnik.client")
|
||||
|
||||
// where to write generated code
|
||||
override def destinationDir = "generated-code/android-java/src/main/java"
|
||||
|
||||
// package for models
|
||||
override def modelPackage = Some("com.wordnik.client.model")
|
||||
|
||||
// package for api classes
|
||||
override def apiPackage = Some("com.wordnik.client.api")
|
||||
|
||||
|
||||
// supporting classes
|
||||
override def supportingFiles = List(
|
||||
("apiInvoker.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiInvoker.java"),
|
||||
("jsonUtil.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "JsonUtil.java"),
|
||||
("ApiException.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiException.java"),
|
||||
("pom.mustache", "android-java", "pom.xml")
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user