diff --git a/README.md b/README.md index f288e847b09..f7ee2b9667f 100644 --- a/README.md +++ b/README.md @@ -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 - 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 diff --git a/bin/all-petstore.sh b/bin/all-petstore.sh index 5b044167e7b..180e95590be 100755 --- a/bin/all-petstore.sh +++ b/bin/all-petstore.sh @@ -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 diff --git a/bin/java-petstore-retrofit.json b/bin/java-petstore-retrofit.json new file mode 100644 index 00000000000..86da9d17099 --- /dev/null +++ b/bin/java-petstore-retrofit.json @@ -0,0 +1,4 @@ +{ + "library": "retrofit", + "artifactId": "swagger-petstore-retrofit" +} diff --git a/bin/retrofit-petstore.sh b/bin/java-petstore-retrofit.sh similarity index 78% rename from bin/retrofit-petstore.sh rename to bin/java-petstore-retrofit.sh index 10b82e61963..d9228fb2eca 100755 --- a/bin/retrofit-petstore.sh +++ b/bin/java-petstore-retrofit.sh @@ -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 diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java index 1c911818938..07baa43b824 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java @@ -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("", "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() { @@ -373,6 +380,29 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig { } return objs; } + + public Map postProcessOperations(Map objs) { + if("retrofit".equals(getLibrary())) { + Map operations = (Map) objs.get("operations"); + if (operations != null) { + List ops = (List) operations.get("operation"); + for (CodegenOperation operation : ops) { + if (operation.hasConsumes == Boolean.TRUE) { + Map 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 diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RetrofitClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RetrofitClientCodegen.java deleted file mode 100644 index 2acacd88026..00000000000 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/RetrofitClientCodegen.java +++ /dev/null @@ -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( - 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( - 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) + ""; - } - 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 postProcessOperations(Map objs) { - Map operations = (Map) objs.get("operations"); - if (operations != null) { - List ops = (List) operations.get("operation"); - for (CodegenOperation operation : ops) { - if (operation.hasConsumes == Boolean.TRUE) { - Map 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; - } -} diff --git a/modules/swagger-codegen/src/main/resources/retrofit/auth/oauthflow.mustache b/modules/swagger-codegen/src/main/resources/Java/auth/OAuthFlow.mustache similarity index 77% rename from modules/swagger-codegen/src/main/resources/retrofit/auth/oauthflow.mustache rename to modules/swagger-codegen/src/main/resources/Java/auth/OAuthFlow.mustache index 6d18cb3aa84..7ab35f6d890 100644 --- a/modules/swagger-codegen/src/main/resources/retrofit/auth/oauthflow.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/auth/OAuthFlow.mustache @@ -1,5 +1,5 @@ package {{invokerPackage}}.auth; -public enum OauthFlow { +public enum OAuthFlow { accessCode, implicit, password, application } \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/retrofit/service.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/ApiClient.mustache similarity index 81% rename from modules/swagger-codegen/src/main/resources/retrofit/service.mustache rename to modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/ApiClient.mustache index aa7b73f2147..4046f9f107c 100644 --- a/modules/swagger-codegen/src/main/resources/retrofit/service.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/ApiClient.mustache @@ -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 apiAuthorizations; private OkHttpClient okClient; private RestAdapter.Builder adapterBuilder; - public ServiceGenerator() { + public ApiClient() { apiAuthorizations = new LinkedHashMap(); 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) diff --git a/modules/swagger-codegen/src/main/resources/retrofit/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/api.mustache similarity index 69% rename from modules/swagger-codegen/src/main/resources/retrofit/api.mustache rename to modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/api.mustache index db4a997196f..89850d92bdc 100644 --- a/modules/swagger-codegen/src/main/resources/retrofit/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/api.mustache @@ -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}} } diff --git a/modules/swagger-codegen/src/main/resources/retrofit/auth/apikey.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/ApiKeyAuth.mustache similarity index 93% rename from modules/swagger-codegen/src/main/resources/retrofit/auth/apikey.mustache rename to modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/ApiKeyAuth.mustache index 9f5eaef7fdc..fec45262e93 100644 --- a/modules/swagger-codegen/src/main/resources/retrofit/auth/apikey.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/ApiKeyAuth.mustache @@ -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; } diff --git a/modules/swagger-codegen/src/main/resources/retrofit/auth/basic.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/HttpBasicAuth.mustache similarity index 95% rename from modules/swagger-codegen/src/main/resources/retrofit/auth/basic.mustache rename to modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/HttpBasicAuth.mustache index f1c88fe9053..394592f64d9 100644 --- a/modules/swagger-codegen/src/main/resources/retrofit/auth/basic.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/HttpBasicAuth.mustache @@ -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; diff --git a/modules/swagger-codegen/src/main/resources/retrofit/auth/oauth.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/OAuth.mustache similarity index 91% rename from modules/swagger-codegen/src/main/resources/retrofit/auth/oauth.mustache rename to modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/OAuth.mustache index a1a2ecabfaa..e6179d6c690 100644 --- a/modules/swagger-codegen/src/main/resources/retrofit/auth/oauth.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/OAuth.mustache @@ -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: diff --git a/modules/swagger-codegen/src/main/resources/retrofit/auth/oauthokclient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/OAuthOkHttpClient.mustache similarity index 94% rename from modules/swagger-codegen/src/main/resources/retrofit/auth/oauthokclient.mustache rename to modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/OAuthOkHttpClient.mustache index 61f651f7696..ea195f7df04 100644 --- a/modules/swagger-codegen/src/main/resources/retrofit/auth/oauthokclient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/OAuthOkHttpClient.mustache @@ -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; } diff --git a/modules/swagger-codegen/src/main/resources/retrofit/bodyParams.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/bodyParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/retrofit/bodyParams.mustache rename to modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/bodyParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/retrofit/formParams.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/formParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/retrofit/formParams.mustache rename to modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/formParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/retrofit/headerParams.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/headerParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/retrofit/headerParams.mustache rename to modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/headerParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/model.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/model.mustache new file mode 100644 index 00000000000..0987aa68f34 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/model.mustache @@ -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}} diff --git a/modules/swagger-codegen/src/main/resources/retrofit/pathParams.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/pathParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/retrofit/pathParams.mustache rename to modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/pathParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/retrofit/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/pom.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/retrofit/pom.mustache rename to modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/pom.mustache diff --git a/modules/swagger-codegen/src/main/resources/retrofit/queryParams.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/queryParams.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/retrofit/queryParams.mustache rename to modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/queryParams.mustache diff --git a/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig b/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig index a73fe5f4388..489d81f411f 100644 --- a/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig +++ b/modules/swagger-codegen/src/main/resources/META-INF/services/io.swagger.codegen.CodegenConfig @@ -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 diff --git a/modules/swagger-codegen/src/main/resources/retrofit/model.mustache b/modules/swagger-codegen/src/main/resources/retrofit/model.mustache deleted file mode 100644 index 85213ed4c95..00000000000 --- a/modules/swagger-codegen/src/main/resources/retrofit/model.mustache +++ /dev/null @@ -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}} diff --git a/pom.xml b/pom.xml index 883d22257c8..f14e7b825cb 100644 --- a/pom.xml +++ b/pom.xml @@ -340,6 +340,18 @@ samples/client/petstore/java/okhttp-gson + + java-client-retrofit + + + env + java + + + + samples/client/petstore/java/retrofit + + scala-client @@ -388,18 +400,6 @@ samples/client/petstore/ruby - - retrofit-client - - - env - java - - - - samples/client/petstore/retrofit - - spring-mvc diff --git a/samples/client/petstore/retrofit/pom.xml b/samples/client/petstore/java/retrofit/pom.xml similarity index 97% rename from samples/client/petstore/retrofit/pom.xml rename to samples/client/petstore/java/retrofit/pom.xml index bcbfdbf797d..6e2a7b76ac2 100644 --- a/samples/client/petstore/retrofit/pom.xml +++ b/samples/client/petstore/java/retrofit/pom.xml @@ -2,9 +2,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 io.swagger - swagger-java-client + swagger-petstore-retrofit jar - swagger-java-client + swagger-petstore-retrofit 1.0.0 scm:git:git@github.com:swagger-api/swagger-mustache.git diff --git a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/ServiceGenerator.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/ApiClient.java similarity index 82% rename from samples/client/petstore/retrofit/src/main/java/io/swagger/client/ServiceGenerator.java rename to samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/ApiClient.java index 244b9f50f84..83ad22c4de8 100644 --- a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/ServiceGenerator.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/ApiClient.java @@ -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 apiAuthorizations; private OkHttpClient okClient; private RestAdapter.Builder adapterBuilder; - public ServiceGenerator() { + public ApiClient() { apiAuthorizations = new LinkedHashMap(); 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) diff --git a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/StringUtil.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/StringUtil.java new file mode 100644 index 00000000000..27a06a7cfc2 --- /dev/null +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/StringUtil.java @@ -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. + *

+ * Note: This might be replaced by utility method from commons-lang or guava someday + * if one of those libraries is added as dependency. + *

+ * + * @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 "); + } +} diff --git a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/PetApi.java similarity index 90% rename from samples/client/petstore/retrofit/src/main/java/io/swagger/client/api/PetApi.java rename to samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/PetApi.java index 5efddc75dc4..cd4dbe866a5 100644 --- a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/PetApi.java @@ -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 < 10. ID > 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 cb + @Path("petId") String petId, @Field("name") String name, @Field("status") String status, Callback 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 cb + @Path("petId") Long petId, @Part("additionalMetadata") String additionalMetadata, @Part("file") TypedFile file, Callback cb ); } diff --git a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/StoreApi.java similarity index 96% rename from samples/client/petstore/retrofit/src/main/java/io/swagger/client/api/StoreApi.java rename to samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/StoreApi.java index 9fecd5c98d0..1c0a8291d02 100644 --- a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/StoreApi.java @@ -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 cb + @Path("orderId") String orderId, Callback cb ); /** diff --git a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/UserApi.java similarity index 99% rename from samples/client/petstore/retrofit/src/main/java/io/swagger/client/api/UserApi.java rename to samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/UserApi.java index c74265f53fd..162222bc0f1 100644 --- a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/api/UserApi.java @@ -145,7 +145,7 @@ public interface UserApi { * Get user by user name * Sync method * - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. * @return User */ @@ -157,7 +157,7 @@ public interface UserApi { /** * Get user by user name * Async method - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. * @param cb callback method * @return void */ diff --git a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/auth/ApiKeyAuthorization.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/auth/ApiKeyAuth.java similarity index 93% rename from samples/client/petstore/retrofit/src/main/java/io/swagger/client/auth/ApiKeyAuthorization.java rename to samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/auth/ApiKeyAuth.java index a1292c1d7f1..59d01238796 100644 --- a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/auth/ApiKeyAuthorization.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/auth/ApiKeyAuth.java @@ -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; } diff --git a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/auth/BasicAuthorization.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/auth/HttpBasicAuth.java similarity index 95% rename from samples/client/petstore/retrofit/src/main/java/io/swagger/client/auth/BasicAuthorization.java rename to samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/auth/HttpBasicAuth.java index 80903d49a34..cb7c617767b 100644 --- a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/auth/BasicAuthorization.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/auth/HttpBasicAuth.java @@ -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; diff --git a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/auth/OauthAuthorization.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/auth/OAuth.java similarity index 91% rename from samples/client/petstore/retrofit/src/main/java/io/swagger/client/auth/OauthAuthorization.java rename to samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/auth/OAuth.java index 01c2d3e0916..f7e488e0499 100644 --- a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/auth/OauthAuthorization.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/auth/OAuth.java @@ -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: diff --git a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/auth/OauthFlow.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/auth/OAuthFlow.java similarity index 77% rename from samples/client/petstore/retrofit/src/main/java/io/swagger/client/auth/OauthFlow.java rename to samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/auth/OAuthFlow.java index ba0a8f39f35..597ec99b48b 100644 --- a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/auth/OauthFlow.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/auth/OAuthFlow.java @@ -1,5 +1,5 @@ package io.swagger.client.auth; -public enum OauthFlow { +public enum OAuthFlow { accessCode, implicit, password, application } \ No newline at end of file diff --git a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/auth/OauthOkHttpClient.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/auth/OAuthOkHttpClient.java similarity index 94% rename from samples/client/petstore/retrofit/src/main/java/io/swagger/client/auth/OauthOkHttpClient.java rename to samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/auth/OAuthOkHttpClient.java index a66bec0b158..c872901ba24 100644 --- a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/auth/OauthOkHttpClient.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/auth/OAuthOkHttpClient.java @@ -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; } diff --git a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/ApiResponse.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/ApiResponse.java new file mode 100644 index 00000000000..777de9a34e3 --- /dev/null +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/ApiResponse.java @@ -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(); + } +} diff --git a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/Category.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/Category.java new file mode 100644 index 00000000000..0a7023ac7a5 --- /dev/null +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/Category.java @@ -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(); + } +} diff --git a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/Order.java new file mode 100644 index 00000000000..df8e77b6fb3 --- /dev/null +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/Order.java @@ -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(); + } +} diff --git a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/Pet.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/Pet.java new file mode 100644 index 00000000000..9ab5457e26a --- /dev/null +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/Pet.java @@ -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 photoUrls = new ArrayList(); + + @SerializedName("tags") + private List tags = new ArrayList(); + + +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 getPhotoUrls() { + return photoUrls; + } + public void setPhotoUrls(List photoUrls) { + this.photoUrls = photoUrls; + } + + + /** + **/ + @ApiModelProperty(value = "") + public List getTags() { + return tags; + } + public void setTags(List 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(); + } +} diff --git a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/Tag.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/Tag.java new file mode 100644 index 00000000000..9935b744f2d --- /dev/null +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/Tag.java @@ -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(); + } +} diff --git a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/User.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/User.java new file mode 100644 index 00000000000..cba6abef8dd --- /dev/null +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/User.java @@ -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(); + } +} diff --git a/samples/client/petstore/retrofit/src/test/java/io/swagger/petstore/test/PetApiTest.java b/samples/client/petstore/java/retrofit/src/test/java/io/swagger/petstore/test/PetApiTest.java similarity index 92% rename from samples/client/petstore/retrofit/src/test/java/io/swagger/petstore/test/PetApiTest.java rename to samples/client/petstore/java/retrofit/src/test/java/io/swagger/petstore/test/PetApiTest.java index d015095b5c9..ec93912b1f6 100644 --- a/samples/client/petstore/retrofit/src/test/java/io/swagger/petstore/test/PetApiTest.java +++ b/samples/client/petstore/java/retrofit/src/test/java/io/swagger/petstore/test/PetApiTest.java @@ -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 tags = new ArrayList(); 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 photos = Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"}); pet.setPhotoUrls(photos); diff --git a/samples/client/petstore/retrofit/src/test/java/io/swagger/petstore/test/StoreApiTest.java b/samples/client/petstore/java/retrofit/src/test/java/io/swagger/petstore/test/StoreApiTest.java similarity index 80% rename from samples/client/petstore/retrofit/src/test/java/io/swagger/petstore/test/StoreApiTest.java rename to samples/client/petstore/java/retrofit/src/test/java/io/swagger/petstore/test/StoreApiTest.java index 629a24cc775..95079f71afa 100644 --- a/samples/client/petstore/retrofit/src/test/java/io/swagger/petstore/test/StoreApiTest.java +++ b/samples/client/petstore/java/retrofit/src/test/java/io/swagger/petstore/test/StoreApiTest.java @@ -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; diff --git a/samples/client/petstore/retrofit/src/test/java/io/swagger/petstore/test/UserApiTest.java b/samples/client/petstore/java/retrofit/src/test/java/io/swagger/petstore/test/UserApiTest.java similarity index 95% rename from samples/client/petstore/retrofit/src/test/java/io/swagger/petstore/test/UserApiTest.java rename to samples/client/petstore/java/retrofit/src/test/java/io/swagger/petstore/test/UserApiTest.java index 45a5f1160e1..373218465f0 100644 --- a/samples/client/petstore/retrofit/src/test/java/io/swagger/petstore/test/UserApiTest.java +++ b/samples/client/petstore/java/retrofit/src/test/java/io/swagger/petstore/test/UserApiTest.java @@ -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 diff --git a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/ApiResponse.java b/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/ApiResponse.java deleted file mode 100644 index a929a54dc81..00000000000 --- a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/ApiResponse.java +++ /dev/null @@ -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(); - } -} diff --git a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/Category.java b/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/Category.java deleted file mode 100644 index 7f89bcf57a0..00000000000 --- a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/Category.java +++ /dev/null @@ -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(); - } -} diff --git a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/Order.java deleted file mode 100644 index 6be69df18c9..00000000000 --- a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/Order.java +++ /dev/null @@ -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(); - } -} diff --git a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/Pet.java b/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/Pet.java deleted file mode 100644 index f74264708e3..00000000000 --- a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/Pet.java +++ /dev/null @@ -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 photoUrls = null; - - /** - **/ - @ApiModelProperty(value = "") - @SerializedName("tags") - private List 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 getPhotoUrls() { - return photoUrls; - } - public void setPhotoUrls(List photoUrls) { - this.photoUrls = photoUrls; - } - - public List getTags() { - return tags; - } - public void setTags(List 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(); - } -} diff --git a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/Tag.java b/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/Tag.java deleted file mode 100644 index c1a317bc45c..00000000000 --- a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/Tag.java +++ /dev/null @@ -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(); - } -} diff --git a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/User.java b/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/User.java deleted file mode 100644 index 3beca5c5e86..00000000000 --- a/samples/client/petstore/retrofit/src/main/java/io/swagger/client/model/User.java +++ /dev/null @@ -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(); - } -}