Merge pull request #1256 from cbornet/java_retrofit_lib

Set retrofit as a java library
This commit is contained in:
wing328 2015-09-23 09:12:07 +08:00
commit 85f99934c8
49 changed files with 902 additions and 928 deletions

View File

@ -203,7 +203,6 @@ PhpClientCodegen.java
Python3ClientCodegen.java
PythonClientCodegen.java
Qt5CPPGenerator.java
RetrofitClientCodegen.java
RubyClientCodegen.java
ScalaClientCodegen.java
ScalatraServerCodegen.java
@ -265,6 +264,7 @@ CONFIG OPTIONS
<default> - HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2
jersey2 - HTTP client: Jersey client 2.6
okhttp-gson - HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1
retrofit - HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)
```
Your config file for java can look like

View File

@ -26,6 +26,7 @@ cd $APP_DIR
./bin/java-petstore.sh
./bin/java-petstore-jersey2.sh
./bin/java-petstore-okhttp-gson.sh
./bin/java-petstore-retrofit.sh
./bin/jaxrs-petstore-server.sh
./bin/nodejs-petstore-server.sh
./bin/objc-petstore.sh
@ -34,7 +35,6 @@ cd $APP_DIR
./bin/python-petstore.sh
./bin/python3-petstore.sh
./bin/qt5-petstore.sh
./bin/retrofit-petstore.sh
./bin/ruby-petstore.sh
./bin/scala-async-petstore.sh
./bin/scala-petstore.sh

View File

@ -0,0 +1,4 @@
{
"library": "retrofit",
"artifactId": "swagger-petstore-retrofit"
}

View File

@ -26,6 +26,6 @@ fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/retrofit -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l retrofit -o samples/client/petstore/retrofit"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l java -c bin/java-petstore-retrofit.json -o samples/client/petstore/java/retrofit"
java $JAVA_OPTS -jar $executable $ags

View File

@ -5,6 +5,7 @@ import io.swagger.codegen.CliOption;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.CodegenProperty;
import io.swagger.codegen.CodegenType;
import io.swagger.codegen.DefaultCodegen;
@ -84,6 +85,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
supportedLibraries.put("<default>", "HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2");
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.6");
supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1");
supportedLibraries.put("retrofit", "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)");
cliOptions.add(buildLibraryCliOption(supportedLibraries));
}
@ -155,12 +157,22 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
final String invokerFolder = (sourceFolder + File.separator + invokerPackage).replace(".", File.separator);
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
supportingFiles.add(new SupportingFile("ApiClient.mustache", invokerFolder, "ApiClient.java"));
supportingFiles.add(new SupportingFile("apiException.mustache", invokerFolder, "ApiException.java"));
supportingFiles.add(new SupportingFile("Configuration.mustache", invokerFolder, "Configuration.java"));
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
supportingFiles.add(new SupportingFile("Pair.mustache", invokerFolder, "Pair.java"));
supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java"));
final String authFolder = (sourceFolder + File.separator + invokerPackage + ".auth").replace(".", File.separator);
supportingFiles.add(new SupportingFile("auth/HttpBasicAuth.mustache", authFolder, "HttpBasicAuth.java"));
supportingFiles.add(new SupportingFile("auth/ApiKeyAuth.mustache", authFolder, "ApiKeyAuth.java"));
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
supportingFiles.add(new SupportingFile("auth/OAuthFlow.mustache", authFolder, "OAuthFlow.java"));
if (!"retrofit".equals(getLibrary())) {
supportingFiles.add(new SupportingFile("apiException.mustache", invokerFolder, "ApiException.java"));
supportingFiles.add(new SupportingFile("Configuration.mustache", invokerFolder, "Configuration.java"));
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
supportingFiles.add(new SupportingFile("Pair.mustache", invokerFolder, "Pair.java"));
supportingFiles.add(new SupportingFile("auth/Authentication.mustache", authFolder, "Authentication.java"));
}
// library-specific files
if ("okhttp-gson".equals(getLibrary())) {
// the "okhttp-gson" library template requires "ApiCallback.mustache" for async call
@ -169,16 +181,11 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle"));
// "build.sbt" is for development with SBT
supportingFiles.add(new SupportingFile("build.sbt.mustache", "", "build.sbt"));
// and does not require "TypeRef.mustache"
} else if ("retrofit".equals(getLibrary())) {
supportingFiles.add(new SupportingFile("auth/OAuthOkHttpClient.mustache", authFolder, "OAuthOkHttpClient.java"));
} else {
supportingFiles.add(new SupportingFile("TypeRef.mustache", invokerFolder, "TypeRef.java"));
}
final String authFolder = (sourceFolder + File.separator + invokerPackage + ".auth").replace(".", File.separator);
supportingFiles.add(new SupportingFile("auth/Authentication.mustache", authFolder, "Authentication.java"));
supportingFiles.add(new SupportingFile("auth/HttpBasicAuth.mustache", authFolder, "HttpBasicAuth.java"));
supportingFiles.add(new SupportingFile("auth/ApiKeyAuth.mustache", authFolder, "ApiKeyAuth.java"));
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
}
private void sanitizeConfig() {
@ -374,6 +381,29 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
return objs;
}
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
if("retrofit".equals(getLibrary())) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
if (operations != null) {
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
for (CodegenOperation operation : ops) {
if (operation.hasConsumes == Boolean.TRUE) {
Map<String, String> firstType = operation.consumes.get(0);
if (firstType != null) {
if ("multipart/form-data".equals(firstType.get("mediaType"))) {
operation.isMultipart = Boolean.TRUE;
}
}
}
if (operation.returnType == null) {
operation.returnType = "Void";
}
}
}
}
return objs;
}
private CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
// This generator uses inline classes to define enums, which breaks when
// dealing with models that have subTypes. To clean this up, we will analyze

View File

@ -1,220 +0,0 @@
package io.swagger.codegen.languages;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.CodegenType;
import io.swagger.codegen.DefaultCodegen;
import io.swagger.codegen.SupportingFile;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.MapProperty;
import io.swagger.models.properties.Property;
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
public class RetrofitClientCodegen extends DefaultCodegen implements CodegenConfig {
protected String invokerPackage = "io.swagger.client";
protected String groupId = "io.swagger";
protected String artifactId = "swagger-java-client";
protected String artifactVersion = "1.0.0";
protected String sourceFolder = "src/main/java";
public RetrofitClientCodegen() {
super();
outputFolder = "generated-code/java";
modelTemplateFiles.put("model.mustache", ".java");
apiTemplateFiles.put("api.mustache", ".java");
templateDir = "retrofit";
apiPackage = "io.swagger.client.api";
modelPackage = "io.swagger.client.model";
reservedWords = new HashSet<String>(
Arrays.asList(
"abstract", "continue", "for", "new", "switch", "assert",
"default", "if", "package", "synchronized", "boolean", "do", "goto", "private",
"this", "break", "double", "implements", "protected", "throw", "byte", "else",
"import", "public", "throws", "case", "enum", "instanceof", "return", "transient",
"catch", "extends", "int", "short", "try", "char", "final", "interface", "static",
"void", "class", "finally", "long", "strictfp", "volatile", "const", "float",
"native", "super", "while")
);
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
additionalProperties.put(CodegenConstants.GROUP_ID, groupId);
additionalProperties.put(CodegenConstants.ARTIFACT_ID, artifactId);
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
supportingFiles.add(new SupportingFile("service.mustache",
(sourceFolder + File.separator + invokerPackage).replace(".", java.io.File.separator), "ServiceGenerator.java"));
supportingFiles.add(new SupportingFile("auth/basic.mustache",
(sourceFolder + File.separator + invokerPackage + File.separator + "auth").replace(".", java.io.File.separator), "BasicAuthorization.java"));
supportingFiles.add(new SupportingFile("auth/apikey.mustache",
(sourceFolder + File.separator + invokerPackage + File.separator + "auth").replace(".", java.io.File.separator), "ApiKeyAuthorization.java"));
supportingFiles.add(new SupportingFile("auth/oauth.mustache",
(sourceFolder + File.separator + invokerPackage + File.separator + "auth").replace(".", java.io.File.separator), "OauthAuthorization.java"));
supportingFiles.add(new SupportingFile("auth/oauthflow.mustache",
(sourceFolder + File.separator + invokerPackage + File.separator + "auth").replace(".", java.io.File.separator), "OauthFlow.java"));
supportingFiles.add(new SupportingFile("auth/oauthokclient.mustache",
(sourceFolder + File.separator + invokerPackage + File.separator + "auth").replace(".", java.io.File.separator), "OauthOkHttpClient.java"));
languageSpecificPrimitives = new HashSet<String>(
Arrays.asList(
"String",
"boolean",
"Boolean",
"Double",
"Integer",
"Long",
"Float",
"Object")
);
instantiationTypes.put("array", "ArrayList");
instantiationTypes.put("map", "HashMap");
}
public CodegenType getTag() {
return CodegenType.CLIENT;
}
public String getName() {
return "retrofit";
}
public String getHelp() {
return "Generates a Retrofit client library.";
}
@Override
public String escapeReservedWord(String name) {
return "_" + name;
}
@Override
public String apiFileFolder() {
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replace('.', File.separatorChar);
}
public String modelFileFolder() {
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replace('.', File.separatorChar);
}
@Override
public String toVarName(String name) {
// replace - with _ e.g. created-at => created_at
name = name.replaceAll("-", "_");
// if it's all uppper case, do nothing
if (name.matches("^[A-Z_]*$")) {
return name;
}
// camelize (lower first character) the variable name
// pet_id => petId
name = camelize(name, true);
// for reserved word or word starting with number, append _
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
name = escapeReservedWord(name);
}
return name;
}
@Override
public String toParamName(String name) {
// should be the same as variable name
return toVarName(name);
}
@Override
public String toModelName(String name) {
// model name cannot use reserved keyword, e.g. return
if (reservedWords.contains(name)) {
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
}
// camelize the model name
// phone_number => PhoneNumber
return camelize(name);
}
@Override
public String toModelFilename(String name) {
// should be the same as the model name
return toModelName(name);
}
@Override
public String getTypeDeclaration(Property p) {
if (p instanceof ArrayProperty) {
ArrayProperty ap = (ArrayProperty) p;
Property inner = ap.getItems();
return getSwaggerType(p) + "<" + getTypeDeclaration(inner) + ">";
} else if (p instanceof MapProperty) {
MapProperty mp = (MapProperty) p;
Property inner = mp.getAdditionalProperties();
return getSwaggerType(p) + "<String, " + getTypeDeclaration(inner) + ">";
}
return super.getTypeDeclaration(p);
}
@Override
public String getSwaggerType(Property p) {
String swaggerType = super.getSwaggerType(p);
String type = null;
if (typeMapping.containsKey(swaggerType)) {
type = typeMapping.get(swaggerType);
if (languageSpecificPrimitives.contains(type)) {
return toModelName(type);
}
} else {
type = swaggerType;
}
return toModelName(type);
}
@Override
public String toOperationId(String operationId) {
// throw exception if method name is empty
if (StringUtils.isEmpty(operationId)) {
throw new RuntimeException("Empty method name (operationId) not allowed");
}
// method name cannot use reserved keyword, e.g. return
if (reservedWords.contains(operationId)) {
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
}
return camelize(operationId, true);
}
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
if (operations != null) {
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
for (CodegenOperation operation : ops) {
if (operation.hasConsumes == Boolean.TRUE) {
Map<String, String> firstType = operation.consumes.get(0);
if (firstType != null) {
if ("multipart/form-data".equals(firstType.get("mediaType"))) {
operation.isMultipart = Boolean.TRUE;
}
}
}
if (operation.returnType == null) {
operation.returnType = "Void";
}
}
}
return objs;
}
}

View File

@ -1,5 +1,5 @@
package {{invokerPackage}}.auth;
public enum OauthFlow {
public enum OAuthFlow {
accessCode, implicit, password, application
}

View File

@ -25,24 +25,24 @@ import com.google.gson.JsonParseException;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.OkHttpClient;
import {{invokerPackage}}.auth.BasicAuthorization;
import {{invokerPackage}}.auth.ApiKeyAuthorization;
import {{invokerPackage}}.auth.OauthAuthorization;
import {{invokerPackage}}.auth.OauthFlow;
import {{invokerPackage}}.auth.HttpBasicAuth;
import {{invokerPackage}}.auth.ApiKeyAuth;
import {{invokerPackage}}.auth.OAuth;
import {{invokerPackage}}.auth.OAuthFlow;
public class ServiceGenerator {
public class ApiClient {
private Map<String, Interceptor> apiAuthorizations;
private OkHttpClient okClient;
private RestAdapter.Builder adapterBuilder;
public ServiceGenerator() {
public ApiClient() {
apiAuthorizations = new LinkedHashMap<String, Interceptor>();
createDefaultAdapter();
}
public ServiceGenerator(String[] authNames) {
public ApiClient(String[] authNames) {
this();
okClient = new OkHttpClient();
adapterBuilder.setClient(new OkClient(okClient));
@ -52,9 +52,9 @@ public class ServiceGenerator {
}
Interceptor auth;{{#authMethods}}
if (authName == "{{name}}") { {{#isBasic}}
auth = new BasicAuthorization();{{/isBasic}}{{#isApiKey}}
auth = new ApiKeyAuthorization({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");{{/isApiKey}}{{#isOAuth}}
auth = new OauthAuthorization(OauthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{^-first}}, {{/-first}}{{this}}{{/scopes}}");{{/isOAuth}}
auth = new HttpBasicAuth();{{/isBasic}}{{#isApiKey}}
auth = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");{{/isApiKey}}{{#isOAuth}}
auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{^-first}}, {{/-first}}{{this}}{{/scopes}}");{{/isOAuth}}
} else {{/authMethods}}{
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
}
@ -67,7 +67,7 @@ public class ServiceGenerator {
* Basic constructor for single auth name
* @param authName
*/
public ServiceGenerator(String authName) {
public ApiClient(String authName) {
this(new String[]{authName});
}
@ -76,7 +76,7 @@ public class ServiceGenerator {
* @param authName
* @param apiKey
*/
public ServiceGenerator(String authName, String apiKey) {
public ApiClient(String authName, String apiKey) {
this(authName);
this.setApiKey(apiKey);
}
@ -87,7 +87,7 @@ public class ServiceGenerator {
* @param username
* @param password
*/
public ServiceGenerator(String authName, String username, String password) {
public ApiClient(String authName, String username, String password) {
this(authName);
this.setCredentials(username, password);
}
@ -100,7 +100,7 @@ public class ServiceGenerator {
* @param username
* @param password
*/
public ServiceGenerator(String authName, String clientId, String secret, String username, String password) {
public ApiClient(String authName, String clientId, String secret, String username, String password) {
this(authName);
this.getTokenEndPoint()
.setClientId(clientId)
@ -131,8 +131,8 @@ public class ServiceGenerator {
*/
private void setApiKey(String apiKey) {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof ApiKeyAuthorization) {
ApiKeyAuthorization keyAuth = (ApiKeyAuthorization) apiAuthorization;
if (apiAuthorization instanceof ApiKeyAuth) {
ApiKeyAuth keyAuth = (ApiKeyAuth) apiAuthorization;
keyAuth.setApiKey(apiKey);
return;
}
@ -146,13 +146,13 @@ public class ServiceGenerator {
*/
private void setCredentials(String username, String password) {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof BasicAuthorization) {
BasicAuthorization basicAuth = (BasicAuthorization) apiAuthorization;
if (apiAuthorization instanceof HttpBasicAuth) {
HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization;
basicAuth.setCredentials(username, password);
return;
}
if (apiAuthorization instanceof OauthAuthorization) {
OauthAuthorization oauth = (OauthAuthorization) apiAuthorization;
if (apiAuthorization instanceof OAuth) {
OAuth oauth = (OAuth) apiAuthorization;
oauth.getTokenRequestBuilder().setUsername(username).setPassword(password);
return;
}
@ -165,8 +165,8 @@ public class ServiceGenerator {
*/
public TokenRequestBuilder getTokenEndPoint() {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof OauthAuthorization) {
OauthAuthorization oauth = (OauthAuthorization) apiAuthorization;
if (apiAuthorization instanceof OAuth) {
OAuth oauth = (OAuth) apiAuthorization;
return oauth.getTokenRequestBuilder();
}
}
@ -179,8 +179,8 @@ public class ServiceGenerator {
*/
public AuthenticationRequestBuilder getAuthorizationEndPoint() {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof OauthAuthorization) {
OauthAuthorization oauth = (OauthAuthorization) apiAuthorization;
if (apiAuthorization instanceof OAuth) {
OAuth oauth = (OAuth) apiAuthorization;
return oauth.getAuthenticationRequestBuilder();
}
}
@ -193,8 +193,8 @@ public class ServiceGenerator {
*/
public void setAccessToken(String accessToken) {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof OauthAuthorization) {
OauthAuthorization oauth = (OauthAuthorization) apiAuthorization;
if (apiAuthorization instanceof OAuth) {
OAuth oauth = (OAuth) apiAuthorization;
oauth.setAccessToken(accessToken);
return;
}
@ -209,8 +209,8 @@ public class ServiceGenerator {
*/
public void configureAuthorizationFlow(String clientId, String clientSecret, String redirectURI) {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof OauthAuthorization) {
OauthAuthorization oauth = (OauthAuthorization) apiAuthorization;
if (apiAuthorization instanceof OAuth) {
OAuth oauth = (OAuth) apiAuthorization;
oauth.getTokenRequestBuilder()
.setClientId(clientId)
.setClientSecret(clientSecret)

View File

@ -24,7 +24,7 @@ public interface {{classname}} {
{{#isMultipart}}@Multipart{{/isMultipart}}{{^isMultipart}}@FormUrlEncoded{{/isMultipart}}{{/-first}}{{/formParams}}
@{{httpMethod}}("{{path}}")
{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}} {{nickname}}({{^allParams}});{{/allParams}}
{{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}
{{#allParams}}{{>libraries/retrofit/queryParams}}{{>libraries/retrofit/pathParams}}{{>libraries/retrofit/headerParams}}{{>libraries/retrofit/bodyParams}}{{>libraries/retrofit/formParams}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}
);{{/hasMore}}{{/allParams}}
/**
@ -38,7 +38,7 @@ public interface {{classname}} {
{{#isMultipart}}@Multipart{{/isMultipart}}{{^isMultipart}}@FormUrlEncoded{{/isMultipart}}{{/-first}}{{/formParams}}
@{{httpMethod}}("{{path}}")
void {{nickname}}(
{{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}, {{/allParams}}Callback<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}> cb
{{#allParams}}{{>libraries/retrofit/queryParams}}{{>libraries/retrofit/pathParams}}{{>libraries/retrofit/headerParams}}{{>libraries/retrofit/bodyParams}}{{>libraries/retrofit/formParams}}, {{/allParams}}Callback<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}> cb
);
{{/operation}}
}

View File

@ -8,13 +8,13 @@ import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
public class ApiKeyAuthorization implements Interceptor {
public class ApiKeyAuth implements Interceptor {
private final String location;
private final String paramName;
private String apiKey;
public ApiKeyAuthorization(String location, String paramName) {
public ApiKeyAuth(String location, String paramName) {
this.location = location;
this.paramName = paramName;
}

View File

@ -7,7 +7,7 @@ import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
public class BasicAuthorization implements Interceptor {
public class HttpBasicAuth implements Interceptor {
private String username;
private String password;

View File

@ -21,7 +21,7 @@ import com.squareup.okhttp.Request;
import com.squareup.okhttp.Request.Builder;
import com.squareup.okhttp.Response;
public class OauthAuthorization implements Interceptor {
public class OAuth implements Interceptor {
private volatile String accessToken;
private OAuthClient oauthClient;
@ -29,22 +29,22 @@ public class OauthAuthorization implements Interceptor {
private TokenRequestBuilder tokenRequestBuilder;
private AuthenticationRequestBuilder authenticationRequestBuilder;
public OauthAuthorization( OkHttpClient client, TokenRequestBuilder requestBuilder ) {
this.oauthClient = new OAuthClient(new OauthOkHttpClient(client));
public OAuth( OkHttpClient client, TokenRequestBuilder requestBuilder ) {
this.oauthClient = new OAuthClient(new OAuthOkHttpClient(client));
this.tokenRequestBuilder = requestBuilder;
}
public OauthAuthorization(TokenRequestBuilder requestBuilder ) {
public OAuth(TokenRequestBuilder requestBuilder ) {
this(new OkHttpClient(), requestBuilder);
}
public OauthAuthorization(OauthFlow flow, String authorizationUrl, String tokenUrl, String scopes) {
public OAuth(OAuthFlow flow, String authorizationUrl, String tokenUrl, String scopes) {
this(OAuthClientRequest.tokenLocation(tokenUrl).setScope(scopes));
setFlow(flow);
authenticationRequestBuilder = OAuthClientRequest.authorizationLocation(authorizationUrl);
}
public void setFlow(OauthFlow flow) {
public void setFlow(OAuthFlow flow) {
switch(flow) {
case accessCode:
case implicit:

View File

@ -18,15 +18,15 @@ import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
public class OauthOkHttpClient implements HttpClient {
public class OAuthOkHttpClient implements HttpClient {
private OkHttpClient client;
public OauthOkHttpClient() {
public OAuthOkHttpClient() {
this.client = new OkHttpClient();
}
public OauthOkHttpClient(OkHttpClient client) {
public OAuthOkHttpClient(OkHttpClient client) {
this.client = client;
}

View File

@ -0,0 +1,58 @@
package {{package}};
import {{invokerPackage}}.StringUtil;
{{#imports}}import {{import}};
{{/imports}}
import com.google.gson.annotations.SerializedName;
{{#serializableModel}}
import java.io.Serializable;{{/serializableModel}}
import io.swagger.annotations.*;
{{#models}}
{{#model}}{{#description}}
/**
* {{description}}
**/{{/description}}
@ApiModel(description = "{{{description}}}")
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#serializableModel}}implements Serializable{{/serializableModel}} {
{{#vars}}{{#isEnum}}
{{>libraries/okhttp-gson/enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}
{{>libraries/okhttp-gson/enumClass}}{{/items}}{{/items.isEnum}}
@SerializedName("{{baseName}}")
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};
{{/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}}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class {{classname}} {\n");
{{#parent}}sb.append(" ").append(StringUtil.toIndentedString(super.toString())).append("\n");{{/parent}}
{{#vars}}sb.append(" {{name}}: ").append(StringUtil.toIndentedString({{name}})).append("\n");
{{/vars}}sb.append("}");
return sb.toString();
}
}
{{/model}}
{{/models}}

View File

@ -13,7 +13,6 @@ io.swagger.codegen.languages.PhpClientCodegen
io.swagger.codegen.languages.PythonClientCodegen
io.swagger.codegen.languages.Python3ClientCodegen
io.swagger.codegen.languages.Qt5CPPGenerator
io.swagger.codegen.languages.RetrofitClientCodegen
io.swagger.codegen.languages.RubyClientCodegen
io.swagger.codegen.languages.ScalaClientCodegen
io.swagger.codegen.languages.ScalatraServerCodegen

View File

@ -1,50 +0,0 @@
package {{package}};
{{#imports}}import {{import}};
{{/imports}}
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}}
};{{/isEnum}}
/**{{#description}}
* {{{description}}}{{/description}}{{#minimum}}
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
* maximum: {{maximum}}{{/maximum}}
**/
@ApiModelProperty({{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
@SerializedName("{{baseName}}"){{#isEnum}}
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{^isEnum}}
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{/isEnum}}{{/vars}}
{{#vars}}
public {{{datatypeWithEnum}}} {{getter}}() {
return {{name}};
}
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
this.{{name}} = {{name}};
}
{{/vars}}
@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}}
{{/models}}

24
pom.xml
View File

@ -340,6 +340,18 @@
<module>samples/client/petstore/java/okhttp-gson</module>
</modules>
</profile>
<profile>
<id>java-client-retrofit</id>
<activation>
<property>
<name>env</name>
<value>java</value>
</property>
</activation>
<modules>
<module>samples/client/petstore/java/retrofit</module>
</modules>
</profile>
<profile>
<id>scala-client</id>
<activation>
@ -388,18 +400,6 @@
<module>samples/client/petstore/ruby</module>
</modules>
</profile>
<profile>
<id>retrofit-client</id>
<activation>
<property>
<name>env</name>
<value>java</value>
</property>
</activation>
<modules>
<module>samples/client/petstore/retrofit</module>
</modules>
</profile>
<profile>
<id>spring-mvc</id>
<activation>

View File

@ -2,9 +2,9 @@
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>swagger-java-client</artifactId>
<artifactId>swagger-petstore-retrofit</artifactId>
<packaging>jar</packaging>
<name>swagger-java-client</name>
<name>swagger-petstore-retrofit</name>
<version>1.0.0</version>
<scm>
<connection>scm:git:git@github.com:swagger-api/swagger-mustache.git</connection>

View File

@ -25,24 +25,24 @@ import com.google.gson.JsonParseException;
import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.OkHttpClient;
import io.swagger.client.auth.BasicAuthorization;
import io.swagger.client.auth.ApiKeyAuthorization;
import io.swagger.client.auth.OauthAuthorization;
import io.swagger.client.auth.OauthFlow;
import io.swagger.client.auth.HttpBasicAuth;
import io.swagger.client.auth.ApiKeyAuth;
import io.swagger.client.auth.OAuth;
import io.swagger.client.auth.OAuthFlow;
public class ServiceGenerator {
public class ApiClient {
private Map<String, Interceptor> apiAuthorizations;
private OkHttpClient okClient;
private RestAdapter.Builder adapterBuilder;
public ServiceGenerator() {
public ApiClient() {
apiAuthorizations = new LinkedHashMap<String, Interceptor>();
createDefaultAdapter();
}
public ServiceGenerator(String[] authNames) {
public ApiClient(String[] authNames) {
this();
okClient = new OkHttpClient();
adapterBuilder.setClient(new OkClient(okClient));
@ -51,11 +51,11 @@ public class ServiceGenerator {
throw new RuntimeException("auth name \"" + authName + "\" already in api authorizations");
}
Interceptor auth;
if (authName == "petstore_auth") {
auth = new OauthAuthorization(OauthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets");
} else
if (authName == "api_key") {
auth = new ApiKeyAuthorization("header", "api_key");
auth = new ApiKeyAuth("header", "api_key");
} else
if (authName == "petstore_auth") {
auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets");
} else {
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
}
@ -68,7 +68,7 @@ public class ServiceGenerator {
* Basic constructor for single auth name
* @param authName
*/
public ServiceGenerator(String authName) {
public ApiClient(String authName) {
this(new String[]{authName});
}
@ -77,7 +77,7 @@ public class ServiceGenerator {
* @param authName
* @param apiKey
*/
public ServiceGenerator(String authName, String apiKey) {
public ApiClient(String authName, String apiKey) {
this(authName);
this.setApiKey(apiKey);
}
@ -88,7 +88,7 @@ public class ServiceGenerator {
* @param username
* @param password
*/
public ServiceGenerator(String authName, String username, String password) {
public ApiClient(String authName, String username, String password) {
this(authName);
this.setCredentials(username, password);
}
@ -101,7 +101,7 @@ public class ServiceGenerator {
* @param username
* @param password
*/
public ServiceGenerator(String authName, String clientId, String secret, String username, String password) {
public ApiClient(String authName, String clientId, String secret, String username, String password) {
this(authName);
this.getTokenEndPoint()
.setClientId(clientId)
@ -132,8 +132,8 @@ public class ServiceGenerator {
*/
private void setApiKey(String apiKey) {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof ApiKeyAuthorization) {
ApiKeyAuthorization keyAuth = (ApiKeyAuthorization) apiAuthorization;
if (apiAuthorization instanceof ApiKeyAuth) {
ApiKeyAuth keyAuth = (ApiKeyAuth) apiAuthorization;
keyAuth.setApiKey(apiKey);
return;
}
@ -147,13 +147,13 @@ public class ServiceGenerator {
*/
private void setCredentials(String username, String password) {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof BasicAuthorization) {
BasicAuthorization basicAuth = (BasicAuthorization) apiAuthorization;
if (apiAuthorization instanceof HttpBasicAuth) {
HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization;
basicAuth.setCredentials(username, password);
return;
}
if (apiAuthorization instanceof OauthAuthorization) {
OauthAuthorization oauth = (OauthAuthorization) apiAuthorization;
if (apiAuthorization instanceof OAuth) {
OAuth oauth = (OAuth) apiAuthorization;
oauth.getTokenRequestBuilder().setUsername(username).setPassword(password);
return;
}
@ -166,8 +166,8 @@ public class ServiceGenerator {
*/
public TokenRequestBuilder getTokenEndPoint() {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof OauthAuthorization) {
OauthAuthorization oauth = (OauthAuthorization) apiAuthorization;
if (apiAuthorization instanceof OAuth) {
OAuth oauth = (OAuth) apiAuthorization;
return oauth.getTokenRequestBuilder();
}
}
@ -180,8 +180,8 @@ public class ServiceGenerator {
*/
public AuthenticationRequestBuilder getAuthorizationEndPoint() {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof OauthAuthorization) {
OauthAuthorization oauth = (OauthAuthorization) apiAuthorization;
if (apiAuthorization instanceof OAuth) {
OAuth oauth = (OAuth) apiAuthorization;
return oauth.getAuthenticationRequestBuilder();
}
}
@ -194,8 +194,8 @@ public class ServiceGenerator {
*/
public void setAccessToken(String accessToken) {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof OauthAuthorization) {
OauthAuthorization oauth = (OauthAuthorization) apiAuthorization;
if (apiAuthorization instanceof OAuth) {
OAuth oauth = (OAuth) apiAuthorization;
oauth.setAccessToken(accessToken);
return;
}
@ -210,8 +210,8 @@ public class ServiceGenerator {
*/
public void configureAuthorizationFlow(String clientId, String clientSecret, String redirectURI) {
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
if (apiAuthorization instanceof OauthAuthorization) {
OauthAuthorization oauth = (OauthAuthorization) apiAuthorization;
if (apiAuthorization instanceof OAuth) {
OAuth oauth = (OAuth) apiAuthorization;
oauth.getTokenRequestBuilder()
.setClientId(clientId)
.setClientSecret(clientSecret)

View File

@ -0,0 +1,51 @@
package io.swagger.client;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-18T14:07:38.326+02:00")
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;
}
/**
* 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();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
public static String toIndentedString(Object o) {
if (o == null) return "null";
return o.toString().replace("\n", "\n ");
}
}

View File

@ -9,7 +9,6 @@ import java.util.*;
import io.swagger.client.model.Pet;
import java.io.File;
import io.swagger.client.model.ApiResponse;
public interface PetApi {
@ -120,8 +119,8 @@ public interface PetApi {
/**
* Find pet by ID
* Sync method
* Returns a single pet
* @param petId ID of pet to return
* Returns a pet when ID &lt; 10. ID &gt; 10 or nonintegers will simulate API error conditions
* @param petId ID of pet that needs to be fetched
* @return Pet
*/
@ -133,7 +132,7 @@ public interface PetApi {
/**
* Find pet by ID
* Async method
* @param petId ID of pet to return
* @param petId ID of pet that needs to be fetched
* @param cb callback method
* @return void
*/
@ -156,7 +155,7 @@ public interface PetApi {
@FormUrlEncoded
@POST("/pet/{petId}")
Void updatePetWithForm(
@Path("petId") Long petId, @Field("name") String name, @Field("status") String status
@Path("petId") String petId, @Field("name") String name, @Field("status") String status
);
/**
@ -172,7 +171,7 @@ public interface PetApi {
@FormUrlEncoded
@POST("/pet/{petId}")
void updatePetWithForm(
@Path("petId") Long petId, @Field("name") String name, @Field("status") String status, Callback<Void> cb
@Path("petId") String petId, @Field("name") String name, @Field("status") String status, Callback<Void> cb
);
/**
@ -210,12 +209,12 @@ public interface PetApi {
* @param petId ID of pet to update
* @param additionalMetadata Additional data to pass to server
* @param file file to upload
* @return ApiResponse
* @return Void
*/
@Multipart
@POST("/pet/{petId}/uploadImage")
ApiResponse uploadFile(
Void uploadFile(
@Path("petId") Long petId, @Part("additionalMetadata") String additionalMetadata, @Part("file") TypedFile file
);
@ -232,7 +231,7 @@ public interface PetApi {
@Multipart
@POST("/pet/{petId}/uploadImage")
void uploadFile(
@Path("petId") Long petId, @Part("additionalMetadata") String additionalMetadata, @Part("file") TypedFile file, Callback<ApiResponse> cb
@Path("petId") Long petId, @Part("additionalMetadata") String additionalMetadata, @Part("file") TypedFile file, Callback<Void> cb
);
}

View File

@ -71,7 +71,7 @@ public interface StoreApi {
@GET("/store/order/{orderId}")
Order getOrderById(
@Path("orderId") Long orderId
@Path("orderId") String orderId
);
/**
@ -84,7 +84,7 @@ public interface StoreApi {
@GET("/store/order/{orderId}")
void getOrderById(
@Path("orderId") Long orderId, Callback<Order> cb
@Path("orderId") String orderId, Callback<Order> cb
);
/**

View File

@ -8,13 +8,13 @@ import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
public class ApiKeyAuthorization implements Interceptor {
public class ApiKeyAuth implements Interceptor {
private final String location;
private final String paramName;
private String apiKey;
public ApiKeyAuthorization(String location, String paramName) {
public ApiKeyAuth(String location, String paramName) {
this.location = location;
this.paramName = paramName;
}

View File

@ -7,7 +7,7 @@ import com.squareup.okhttp.Interceptor;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
public class BasicAuthorization implements Interceptor {
public class HttpBasicAuth implements Interceptor {
private String username;
private String password;

View File

@ -21,7 +21,7 @@ import com.squareup.okhttp.Request;
import com.squareup.okhttp.Request.Builder;
import com.squareup.okhttp.Response;
public class OauthAuthorization implements Interceptor {
public class OAuth implements Interceptor {
private volatile String accessToken;
private OAuthClient oauthClient;
@ -29,22 +29,22 @@ public class OauthAuthorization implements Interceptor {
private TokenRequestBuilder tokenRequestBuilder;
private AuthenticationRequestBuilder authenticationRequestBuilder;
public OauthAuthorization( OkHttpClient client, TokenRequestBuilder requestBuilder ) {
this.oauthClient = new OAuthClient(new OauthOkHttpClient(client));
public OAuth( OkHttpClient client, TokenRequestBuilder requestBuilder ) {
this.oauthClient = new OAuthClient(new OAuthOkHttpClient(client));
this.tokenRequestBuilder = requestBuilder;
}
public OauthAuthorization(TokenRequestBuilder requestBuilder ) {
public OAuth(TokenRequestBuilder requestBuilder ) {
this(new OkHttpClient(), requestBuilder);
}
public OauthAuthorization(OauthFlow flow, String authorizationUrl, String tokenUrl, String scopes) {
public OAuth(OAuthFlow flow, String authorizationUrl, String tokenUrl, String scopes) {
this(OAuthClientRequest.tokenLocation(tokenUrl).setScope(scopes));
setFlow(flow);
authenticationRequestBuilder = OAuthClientRequest.authorizationLocation(authorizationUrl);
}
public void setFlow(OauthFlow flow) {
public void setFlow(OAuthFlow flow) {
switch(flow) {
case accessCode:
case implicit:

View File

@ -1,5 +1,5 @@
package io.swagger.client.auth;
public enum OauthFlow {
public enum OAuthFlow {
accessCode, implicit, password, application
}

View File

@ -18,15 +18,15 @@ import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
public class OauthOkHttpClient implements HttpClient {
public class OAuthOkHttpClient implements HttpClient {
private OkHttpClient client;
public OauthOkHttpClient() {
public OAuthOkHttpClient() {
this.client = new OkHttpClient();
}
public OauthOkHttpClient(OkHttpClient client) {
public OAuthOkHttpClient(OkHttpClient client) {
this.client = client;
}

View File

@ -0,0 +1,72 @@
package io.swagger.client.model;
import io.swagger.client.StringUtil;
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.*;
@ApiModel(description = "")
public class ApiResponse {
@SerializedName("code")
private Integer code = null;
@SerializedName("type")
private String type = null;
@SerializedName("message")
private String message = null;
/**
**/
@ApiModelProperty(value = "")
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
/**
**/
@ApiModelProperty(value = "")
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
/**
**/
@ApiModelProperty(value = "")
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ApiResponse {\n");
sb.append(" code: ").append(StringUtil.toIndentedString(code)).append("\n");
sb.append(" type: ").append(StringUtil.toIndentedString(type)).append("\n");
sb.append(" message: ").append(StringUtil.toIndentedString(message)).append("\n");
sb.append("}");
return sb.toString();
}
}

View File

@ -0,0 +1,57 @@
package io.swagger.client.model;
import io.swagger.client.StringUtil;
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.*;
@ApiModel(description = "")
public class Category {
@SerializedName("id")
private Long id = null;
@SerializedName("name")
private String name = null;
/**
**/
@ApiModelProperty(value = "")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/**
**/
@ApiModelProperty(value = "")
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(StringUtil.toIndentedString(id)).append("\n");
sb.append(" name: ").append(StringUtil.toIndentedString(name)).append("\n");
sb.append("}");
return sb.toString();
}
}

View File

@ -0,0 +1,142 @@
package io.swagger.client.model;
import io.swagger.client.StringUtil;
import java.util.Date;
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.*;
@ApiModel(description = "")
public class Order {
@SerializedName("id")
private Long id = null;
@SerializedName("petId")
private Long petId = null;
@SerializedName("quantity")
private Integer quantity = null;
@SerializedName("shipDate")
private Date shipDate = null;
public enum StatusEnum {
@SerializedName("placed")
PLACED("placed"),
@SerializedName("approved")
APPROVED("approved"),
@SerializedName("delivered")
DELIVERED("delivered");
private String value;
StatusEnum(String value) {
this.value = value;
}
@Override
public String toString() {
return value;
}
}
@SerializedName("status")
private StatusEnum status = null;
@SerializedName("complete")
private Boolean complete = null;
/**
**/
@ApiModelProperty(value = "")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/**
**/
@ApiModelProperty(value = "")
public Long getPetId() {
return petId;
}
public void setPetId(Long petId) {
this.petId = petId;
}
/**
**/
@ApiModelProperty(value = "")
public Integer getQuantity() {
return quantity;
}
public void setQuantity(Integer quantity) {
this.quantity = quantity;
}
/**
**/
@ApiModelProperty(value = "")
public Date getShipDate() {
return shipDate;
}
public void setShipDate(Date shipDate) {
this.shipDate = shipDate;
}
/**
* Order Status
**/
@ApiModelProperty(value = "Order Status")
public StatusEnum getStatus() {
return status;
}
public void setStatus(StatusEnum status) {
this.status = status;
}
/**
**/
@ApiModelProperty(value = "")
public Boolean getComplete() {
return complete;
}
public void setComplete(Boolean complete) {
this.complete = complete;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Order {\n");
sb.append(" id: ").append(StringUtil.toIndentedString(id)).append("\n");
sb.append(" petId: ").append(StringUtil.toIndentedString(petId)).append("\n");
sb.append(" quantity: ").append(StringUtil.toIndentedString(quantity)).append("\n");
sb.append(" shipDate: ").append(StringUtil.toIndentedString(shipDate)).append("\n");
sb.append(" status: ").append(StringUtil.toIndentedString(status)).append("\n");
sb.append(" complete: ").append(StringUtil.toIndentedString(complete)).append("\n");
sb.append("}");
return sb.toString();
}
}

View File

@ -0,0 +1,144 @@
package io.swagger.client.model;
import io.swagger.client.StringUtil;
import io.swagger.client.model.Category;
import java.util.*;
import io.swagger.client.model.Tag;
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.*;
@ApiModel(description = "")
public class Pet {
@SerializedName("id")
private Long id = null;
@SerializedName("category")
private Category category = null;
@SerializedName("name")
private String name = null;
@SerializedName("photoUrls")
private List<String> photoUrls = new ArrayList<String>();
@SerializedName("tags")
private List<Tag> tags = new ArrayList<Tag>();
public enum StatusEnum {
@SerializedName("available")
AVAILABLE("available"),
@SerializedName("pending")
PENDING("pending"),
@SerializedName("sold")
SOLD("sold");
private String value;
StatusEnum(String value) {
this.value = value;
}
@Override
public String toString() {
return value;
}
}
@SerializedName("status")
private StatusEnum status = null;
/**
**/
@ApiModelProperty(value = "")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/**
**/
@ApiModelProperty(value = "")
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
/**
**/
@ApiModelProperty(required = true, value = "")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
**/
@ApiModelProperty(required = true, value = "")
public List<String> getPhotoUrls() {
return photoUrls;
}
public void setPhotoUrls(List<String> photoUrls) {
this.photoUrls = photoUrls;
}
/**
**/
@ApiModelProperty(value = "")
public List<Tag> getTags() {
return tags;
}
public void setTags(List<Tag> tags) {
this.tags = tags;
}
/**
* pet status in the store
**/
@ApiModelProperty(value = "pet status in the store")
public StatusEnum getStatus() {
return status;
}
public void setStatus(StatusEnum status) {
this.status = status;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class Pet {\n");
sb.append(" id: ").append(StringUtil.toIndentedString(id)).append("\n");
sb.append(" category: ").append(StringUtil.toIndentedString(category)).append("\n");
sb.append(" name: ").append(StringUtil.toIndentedString(name)).append("\n");
sb.append(" photoUrls: ").append(StringUtil.toIndentedString(photoUrls)).append("\n");
sb.append(" tags: ").append(StringUtil.toIndentedString(tags)).append("\n");
sb.append(" status: ").append(StringUtil.toIndentedString(status)).append("\n");
sb.append("}");
return sb.toString();
}
}

View File

@ -0,0 +1,57 @@
package io.swagger.client.model;
import io.swagger.client.StringUtil;
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.*;
@ApiModel(description = "")
public class Tag {
@SerializedName("id")
private Long id = null;
@SerializedName("name")
private String name = null;
/**
**/
@ApiModelProperty(value = "")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/**
**/
@ApiModelProperty(value = "")
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(StringUtil.toIndentedString(id)).append("\n");
sb.append(" name: ").append(StringUtil.toIndentedString(name)).append("\n");
sb.append("}");
return sb.toString();
}
}

View File

@ -0,0 +1,148 @@
package io.swagger.client.model;
import io.swagger.client.StringUtil;
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.*;
@ApiModel(description = "")
public class User {
@SerializedName("id")
private Long id = null;
@SerializedName("username")
private String username = null;
@SerializedName("firstName")
private String firstName = null;
@SerializedName("lastName")
private String lastName = null;
@SerializedName("email")
private String email = null;
@SerializedName("password")
private String password = null;
@SerializedName("phone")
private String phone = null;
@SerializedName("userStatus")
private Integer userStatus = null;
/**
**/
@ApiModelProperty(value = "")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
/**
**/
@ApiModelProperty(value = "")
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
/**
**/
@ApiModelProperty(value = "")
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
**/
@ApiModelProperty(value = "")
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
**/
@ApiModelProperty(value = "")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
/**
**/
@ApiModelProperty(value = "")
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
/**
**/
@ApiModelProperty(value = "")
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
/**
* User Status
**/
@ApiModelProperty(value = "User Status")
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(StringUtil.toIndentedString(id)).append("\n");
sb.append(" username: ").append(StringUtil.toIndentedString(username)).append("\n");
sb.append(" firstName: ").append(StringUtil.toIndentedString(firstName)).append("\n");
sb.append(" lastName: ").append(StringUtil.toIndentedString(lastName)).append("\n");
sb.append(" email: ").append(StringUtil.toIndentedString(email)).append("\n");
sb.append(" password: ").append(StringUtil.toIndentedString(password)).append("\n");
sb.append(" phone: ").append(StringUtil.toIndentedString(phone)).append("\n");
sb.append(" userStatus: ").append(StringUtil.toIndentedString(userStatus)).append("\n");
sb.append("}");
return sb.toString();
}
}

View File

@ -1,6 +1,6 @@
package io.swagger.petstore.test;
import io.swagger.client.ServiceGenerator;
import io.swagger.client.ApiClient;
import io.swagger.client.api.*;
import io.swagger.client.model.*;
@ -22,7 +22,7 @@ public class PetApiTest {
@Before
public void setup() {
api = new ServiceGenerator().createService(PetApi.class);
api = new ApiClient().createService(PetApi.class);
}
@Test
@ -55,7 +55,7 @@ public class PetApiTest {
public void testFindPetsByStatus() throws Exception {
Pet pet = createRandomPet();
pet.setName("programmer");
pet.setStatus(Pet.StatusEnum.available);
pet.setStatus(Pet.StatusEnum.AVAILABLE);
api.updatePet(pet);
@ -77,7 +77,7 @@ public class PetApiTest {
public void testFindPetsByTags() throws Exception {
Pet pet = createRandomPet();
pet.setName("monster");
pet.setStatus(Pet.StatusEnum.available);
pet.setStatus(Pet.StatusEnum.AVAILABLE);
List<Tag> tags = new ArrayList<Tag>();
Tag tag1 = new Tag();
@ -108,7 +108,7 @@ public class PetApiTest {
Pet fetched = api.getPetById(pet.getId());
api.updatePetWithForm(fetched.getId(), "furt", null);
api.updatePetWithForm(String.valueOf(fetched.getId()), "furt", null);
Pet updated = api.getPetById(fetched.getId());
assertEquals(updated.getName(), "furt");
@ -152,7 +152,7 @@ public class PetApiTest {
category.setName("really-happy");
pet.setCategory(category);
pet.setStatus(Pet.StatusEnum.available);
pet.setStatus(Pet.StatusEnum.AVAILABLE);
List<String> photos = Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"});
pet.setPhotoUrls(photos);

View File

@ -1,6 +1,6 @@
package io.swagger.petstore.test;
import io.swagger.client.ServiceGenerator;
import io.swagger.client.ApiClient;
import io.swagger.client.api.*;
import io.swagger.client.model.*;
@ -16,7 +16,7 @@ public class StoreApiTest {
@Before
public void setup() {
api = new ServiceGenerator().createService(StoreApi.class);
api = new ApiClient().createService(StoreApi.class);
}
@Test
@ -30,7 +30,7 @@ public class StoreApiTest {
Order order = createOrder();
api.placeOrder(order);
Order fetched = api.getOrderById(order.getId());
Order fetched = api.getOrderById(String.valueOf(order.getId()));
assertEquals(order.getId(), fetched.getId());
assertEquals(order.getPetId(), fetched.getPetId());
assertEquals(order.getQuantity(), fetched.getQuantity());
@ -41,13 +41,13 @@ public class StoreApiTest {
Order order = createOrder();
api.placeOrder(order);
Order fetched = api.getOrderById(order.getId());
Order fetched = api.getOrderById(String.valueOf(order.getId()));
assertEquals(fetched.getId(), order.getId());
api.deleteOrder(String.valueOf(order.getId()));
try {
api.getOrderById(order.getId());
api.getOrderById(String.valueOf(order.getId()));
// fail("expected an error");
} catch (RetrofitError e) {
// ok
@ -60,7 +60,7 @@ public class StoreApiTest {
order.setPetId(new Long(200));
order.setQuantity(new Integer(13));
order.setShipDate(new java.util.Date());
order.setStatus(Order.StatusEnum.placed);
order.setStatus(Order.StatusEnum.PLACED);
order.setComplete(true);
return order;

View File

@ -1,6 +1,6 @@
package io.swagger.petstore.test;
import io.swagger.client.ServiceGenerator;
import io.swagger.client.ApiClient;
import io.swagger.client.api.*;
import io.swagger.client.model.*;
@ -15,7 +15,7 @@ public class UserApiTest {
@Before
public void setup() {
api = new ServiceGenerator().createService(UserApi.class);
api = new ApiClient().createService(UserApi.class);
}
@Test

View File

@ -1,63 +0,0 @@
package io.swagger.client.model;
import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName;
@ApiModel(description = "")
public class ApiResponse {
/**
**/
@ApiModelProperty(value = "")
@SerializedName("code")
private Integer code = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("type")
private String type = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("message")
private String message = null;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ApiResponse {\n");
sb.append(" code: ").append(code).append("\n");
sb.append(" type: ").append(type).append("\n");
sb.append(" message: ").append(message).append("\n");
sb.append("}\n");
return sb.toString();
}
}

View File

@ -1,49 +0,0 @@
package io.swagger.client.model;
import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName;
@ApiModel(description = "")
public class Category {
/**
**/
@ApiModelProperty(value = "")
@SerializedName("id")
private Long id = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("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();
}
}

View File

@ -1,110 +0,0 @@
package io.swagger.client.model;
import java.util.Date;
import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName;
@ApiModel(description = "")
public class Order {
/**
**/
@ApiModelProperty(value = "")
@SerializedName("id")
private Long id = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("petId")
private Long petId = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("quantity")
private Integer quantity = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("shipDate")
private Date shipDate = null;
public enum StatusEnum {
placed, approved, delivered,
};
/**
* Order Status
**/
@ApiModelProperty(value = "Order Status")
@SerializedName("status")
private StatusEnum status = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("complete")
private Boolean complete = 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 Date getShipDate() {
return shipDate;
}
public void setShipDate(Date shipDate) {
this.shipDate = shipDate;
}
public StatusEnum getStatus() {
return status;
}
public void setStatus(StatusEnum status) {
this.status = status;
}
public Boolean getComplete() {
return complete;
}
public void setComplete(Boolean complete) {
this.complete = complete;
}
@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(" shipDate: ").append(shipDate).append("\n");
sb.append(" status: ").append(status).append("\n");
sb.append(" complete: ").append(complete).append("\n");
sb.append("}\n");
return sb.toString();
}
}

View File

@ -1,112 +0,0 @@
package io.swagger.client.model;
import io.swagger.client.model.Category;
import java.util.*;
import io.swagger.client.model.Tag;
import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName;
@ApiModel(description = "")
public class Pet {
/**
**/
@ApiModelProperty(value = "")
@SerializedName("id")
private Long id = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("category")
private Category category = null;
/**
**/
@ApiModelProperty(required = true, value = "")
@SerializedName("name")
private String name = null;
/**
**/
@ApiModelProperty(required = true, value = "")
@SerializedName("photoUrls")
private List<String> photoUrls = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("tags")
private List<Tag> tags = null;
public enum StatusEnum {
available, pending, sold,
};
/**
* pet status in the store
**/
@ApiModelProperty(value = "pet status in the store")
@SerializedName("status")
private StatusEnum 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 StatusEnum getStatus() {
return status;
}
public void setStatus(StatusEnum 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();
}
}

View File

@ -1,49 +0,0 @@
package io.swagger.client.model;
import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName;
@ApiModel(description = "")
public class Tag {
/**
**/
@ApiModelProperty(value = "")
@SerializedName("id")
private Long id = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("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();
}
}

View File

@ -1,134 +0,0 @@
package io.swagger.client.model;
import io.swagger.annotations.*;
import com.google.gson.annotations.SerializedName;
@ApiModel(description = "")
public class User {
/**
**/
@ApiModelProperty(value = "")
@SerializedName("id")
private Long id = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("username")
private String username = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("firstName")
private String firstName = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("lastName")
private String lastName = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("email")
private String email = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("password")
private String password = null;
/**
**/
@ApiModelProperty(value = "")
@SerializedName("phone")
private String phone = null;
/**
* User Status
**/
@ApiModelProperty(value = "User Status")
@SerializedName("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();
}
}