From b373e4312e89c8334a868381b5bb36e3da0f351a Mon Sep 17 00:00:00 2001 From: SimonKaluza Date: Tue, 12 Nov 2013 23:26:09 -0500 Subject: [PATCH 01/97] Fixed SWGApiClient.m's run-type type checking to allow NSArrays to be passed (for Swagger-generated methods that rely on List parameters in the HTTP body) --- src/main/resources/objc/SWGApiClient.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/objc/SWGApiClient.m b/src/main/resources/objc/SWGApiClient.m index 669fd4d570b..1c48412bc5a 100644 --- a/src/main/resources/objc/SWGApiClient.m +++ b/src/main/resources/objc/SWGApiClient.m @@ -280,7 +280,7 @@ static bool loggingEnabled = false; } if(body != nil) { - if([body isKindOfClass:[NSDictionary class]]){ + if([body isKindOfClass:[NSDictionary class]] || [body isKindOfClass:[NSArray class]]){ [request setValue:requestContentType forHTTPHeaderField:@"Content-Type"]; } else if ([body isKindOfClass:[SWGFile class]]) {} From 87c12c155da291fbac5f847186a275679101d76a Mon Sep 17 00:00:00 2001 From: George Shakhnazaryan Date: Tue, 19 Nov 2013 13:18:18 -0600 Subject: [PATCH 02/97] Extract actual work from generateClient so that we can call it without killing the JVM. --- .../com/wordnik/swagger/codegen/BasicGenerator.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/scala/com/wordnik/swagger/codegen/BasicGenerator.scala b/src/main/scala/com/wordnik/swagger/codegen/BasicGenerator.scala index e426d90d687..8caf35de450 100644 --- a/src/main/scala/com/wordnik/swagger/codegen/BasicGenerator.scala +++ b/src/main/scala/com/wordnik/swagger/codegen/BasicGenerator.scala @@ -44,12 +44,17 @@ abstract class BasicGenerator extends CodegenConfig with PathUtil { var codegen = new Codegen(this) def generateClient(args: Array[String]) = { + generateClientWithoutExit(args) + System.exit(0) + } + + def generateClientWithoutExit(args: Array[String]) { if (args.length == 0) { throw new RuntimeException("Need url to resource listing as argument. You can also specify VM Argument -DfileMap=/path/to/folder/containing.resources.json/") } val host = args(0) val authorization = { - Option (System.getProperty("header")) match { + Option(System.getProperty("header")) match { case Some(e) => { // this is ugly and will be replaced with proper arg parsing like in ScalaAsyncClientGenerator soon val authInfo = e.split(":") @@ -129,7 +134,6 @@ abstract class BasicGenerator extends CodegenConfig with PathUtil { }) codegen.writeSupportingClasses(operationMap, allModels.toMap) - System.exit(0) } def extractApiOperations(apiListings: List[ApiListing], allModels: HashMap[String, Model] )(implicit basePath:String) = { From 0ee6531fcd60f6c0202f6a092f7aaeafa050f032 Mon Sep 17 00:00:00 2001 From: Robert Blair Date: Wed, 27 Nov 2013 01:02:04 -0800 Subject: [PATCH 03/97] Version mapping for scala 2.10.* should be consistent. --- bin/Version.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/Version.scala b/bin/Version.scala index 8607187f845..d25fe6f9bb7 100644 --- a/bin/Version.scala +++ b/bin/Version.scala @@ -1,5 +1,7 @@ val version = scala.util.Properties.scalaPropOrElse("version.number", "unknown").toString match { case "2.10.0" => "2.10" + case "2.10.2" => "2.10" + case "2.10.3" => "2.10" case e: String => e } -println(version) \ No newline at end of file +println(version) From 17c38115e60e86436faa29f645919133dc4299d9 Mon Sep 17 00:00:00 2001 From: Robert Blair Date: Wed, 27 Nov 2013 01:05:13 -0800 Subject: [PATCH 04/97] rebuild java files before changes to template --- .../java/src/main/java/com/wordnik/client/ApiInvoker.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java b/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java index 955ffe39f6e..781e7da6981 100644 --- a/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java +++ b/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java @@ -12,6 +12,7 @@ import com.sun.jersey.api.client.config.DefaultClientConfig; import com.sun.jersey.api.client.filter.LoggingFilter; import com.sun.jersey.api.client.WebResource.Builder; +import javax.ws.rs.core.Response.Status.Family; import javax.ws.rs.core.MediaType; import java.util.Map; @@ -123,7 +124,7 @@ public class ApiInvoker { else { throw new ApiException(500, "unknown method type " + method); } - if(response.getClientResponseStatus() == ClientResponse.Status.OK) { + if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) { return (String) response.getEntity(String.class); } else { From 1e2f7cb1f8697a396a641ae3aa0282ff0fcb525f Mon Sep 17 00:00:00 2001 From: Robert Blair Date: Wed, 27 Nov 2013 01:13:51 -0800 Subject: [PATCH 05/97] To throw expected ApiException instead of NullPointerException, check required parameters before use --- src/main/resources/Java/api.mustache | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/resources/Java/api.mustache b/src/main/resources/Java/api.mustache index de2248f8930..5ae03eca407 100644 --- a/src/main/resources/Java/api.mustache +++ b/src/main/resources/Java/api.mustache @@ -26,13 +26,6 @@ public class {{classname}} { {{#operation}} public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { - // create path and map variables - String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{paramName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}}; - - // query params - Map queryParams = new HashMap(); - Map headerParams = new HashMap(); - {{#requiredParamCount}} // verify required params are set if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) { @@ -40,6 +33,13 @@ public class {{classname}} { } {{/requiredParamCount}} + // create path and map variables + String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{paramName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}}; + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + {{#queryParams}}if(!"null".equals(String.valueOf({{paramName}}))) queryParams.put("{{baseName}}", String.valueOf({{paramName}})); {{/queryParams}} From 08a3e9e881c0558b642cb48d62b5d8713dcd0761 Mon Sep 17 00:00:00 2001 From: Robert Blair Date: Wed, 27 Nov 2013 01:16:21 -0800 Subject: [PATCH 06/97] Rebuild generated java samples with ApiException checking properly located --- .../java/com/wordnik/petstore/api/PetApi.java | 64 ++++++------- .../com/wordnik/petstore/api/StoreApi.java | 24 ++--- .../com/wordnik/petstore/api/UserApi.java | 56 +++++------ .../com/wordnik/client/api/AccountApi.java | 32 +++---- .../java/com/wordnik/client/api/WordApi.java | 96 +++++++++---------- .../com/wordnik/client/api/WordListApi.java | 48 +++++----- .../com/wordnik/client/api/WordListsApi.java | 8 +- .../java/com/wordnik/client/api/WordsApi.java | 16 ++-- 8 files changed, 172 insertions(+), 172 deletions(-) diff --git a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/api/PetApi.java b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/api/PetApi.java index 8b460e98cfa..4abd43de856 100644 --- a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/api/PetApi.java +++ b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/api/PetApi.java @@ -23,6 +23,10 @@ public class PetApi { } public Pet getPetById (Long petId) throws ApiException { + // verify required params are set + if(petId == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString())); @@ -30,10 +34,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(petId == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -54,6 +54,10 @@ public class PetApi { } } public void deletePet (String petId) throws ApiException { + // verify required params are set + if(petId == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString())); @@ -61,10 +65,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(petId == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -85,6 +85,10 @@ public class PetApi { } } public List partialUpdate (String petId, Pet body) throws ApiException { + // verify required params are set + if(petId == null || body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString())); @@ -92,10 +96,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(petId == null || body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -116,6 +116,10 @@ public class PetApi { } } public void updatePetWithForm (String petId, String name, String status) throws ApiException { + // verify required params are set + if(petId == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString())); @@ -123,10 +127,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(petId == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -174,6 +174,10 @@ public class PetApi { } } public void addPet (Pet body) throws ApiException { + // verify required params are set + if(body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet".replaceAll("\\{format\\}","json"); @@ -181,10 +185,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -205,6 +205,10 @@ public class PetApi { } } public void updatePet (Pet body) throws ApiException { + // verify required params are set + if(body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet".replaceAll("\\{format\\}","json"); @@ -212,10 +216,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -236,6 +236,10 @@ public class PetApi { } } public List findPetsByStatus (String status) throws ApiException { + // verify required params are set + if(status == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet/findByStatus".replaceAll("\\{format\\}","json"); @@ -243,10 +247,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(status == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(status))) queryParams.put("status", String.valueOf(status)); String contentType = "application/json"; @@ -269,6 +269,10 @@ public class PetApi { } } public List findPetsByTags (String tags) throws ApiException { + // verify required params are set + if(tags == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet/findByTags".replaceAll("\\{format\\}","json"); @@ -276,10 +280,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(tags == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(tags))) queryParams.put("tags", String.valueOf(tags)); String contentType = "application/json"; diff --git a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/api/StoreApi.java b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/api/StoreApi.java index dc57a7956dc..9be137cd79f 100644 --- a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/api/StoreApi.java +++ b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/api/StoreApi.java @@ -22,6 +22,10 @@ public class StoreApi { } public Order getOrderById (String orderId) throws ApiException { + // verify required params are set + if(orderId == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}", apiInvoker.escapeString(orderId.toString())); @@ -29,10 +33,6 @@ public class StoreApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(orderId == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -53,6 +53,10 @@ public class StoreApi { } } public void deleteOrder (String orderId) throws ApiException { + // verify required params are set + if(orderId == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}", apiInvoker.escapeString(orderId.toString())); @@ -60,10 +64,6 @@ public class StoreApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(orderId == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -84,6 +84,10 @@ public class StoreApi { } } public void placeOrder (Order body) throws ApiException { + // verify required params are set + if(body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/store/order".replaceAll("\\{format\\}","json"); @@ -91,10 +95,6 @@ public class StoreApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { diff --git a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/api/UserApi.java b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/api/UserApi.java index c5c7d3affae..0527a5a49ca 100644 --- a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/api/UserApi.java +++ b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/api/UserApi.java @@ -22,6 +22,10 @@ public class UserApi { } public void createUser (User body) throws ApiException { + // verify required params are set + if(body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/user".replaceAll("\\{format\\}","json"); @@ -29,10 +33,6 @@ public class UserApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -53,6 +53,10 @@ public class UserApi { } } public void createUsersWithArrayInput (List body) throws ApiException { + // verify required params are set + if(body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/user/createWithArray".replaceAll("\\{format\\}","json"); @@ -60,10 +64,6 @@ public class UserApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -84,6 +84,10 @@ public class UserApi { } } public void createUsersWithListInput (List body) throws ApiException { + // verify required params are set + if(body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/user/createWithList".replaceAll("\\{format\\}","json"); @@ -91,10 +95,6 @@ public class UserApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -115,6 +115,10 @@ public class UserApi { } } public void updateUser (String username, User body) throws ApiException { + // verify required params are set + if(username == null || body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); @@ -122,10 +126,6 @@ public class UserApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(username == null || body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -146,6 +146,10 @@ public class UserApi { } } public void deleteUser (String username) throws ApiException { + // verify required params are set + if(username == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); @@ -153,10 +157,6 @@ public class UserApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(username == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -177,6 +177,10 @@ public class UserApi { } } public User getUserByName (String username) throws ApiException { + // verify required params are set + if(username == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); @@ -184,10 +188,6 @@ public class UserApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(username == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -208,6 +208,10 @@ public class UserApi { } } public String loginUser (String username, String password) throws ApiException { + // verify required params are set + if(username == null || password == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/user/login".replaceAll("\\{format\\}","json"); @@ -215,10 +219,6 @@ public class UserApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(username == null || password == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(username))) queryParams.put("username", String.valueOf(username)); if(!"null".equals(String.valueOf(password))) diff --git a/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/AccountApi.java b/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/AccountApi.java index 51448d9cfd1..33a1d5da0c6 100644 --- a/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/AccountApi.java +++ b/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/AccountApi.java @@ -25,6 +25,10 @@ public class AccountApi { } public AuthenticationToken authenticate (String username, String password) throws ApiException { + // verify required params are set + if(username == null || password == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/account.{format}/authenticate/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); @@ -32,10 +36,6 @@ public class AccountApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(username == null || password == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(password))) queryParams.put("password", String.valueOf(password)); String contentType = "application/json"; @@ -58,6 +58,10 @@ public class AccountApi { } } public AuthenticationToken authenticatePost (String username, String body) throws ApiException { + // verify required params are set + if(username == null || body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/account.{format}/authenticate/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); @@ -65,10 +69,6 @@ public class AccountApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(username == null || body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -89,6 +89,10 @@ public class AccountApi { } } public List getWordListsForLoggedInUser (String auth_token, Integer skip, Integer limit) throws ApiException { + // verify required params are set + if(auth_token == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/account.{format}/wordLists".replaceAll("\\{format\\}","json"); @@ -96,10 +100,6 @@ public class AccountApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(auth_token == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(skip))) queryParams.put("skip", String.valueOf(skip)); if(!"null".equals(String.valueOf(limit))) @@ -153,6 +153,10 @@ public class AccountApi { } } public User getLoggedInUser (String auth_token) throws ApiException { + // verify required params are set + if(auth_token == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/account.{format}/user".replaceAll("\\{format\\}","json"); @@ -160,10 +164,6 @@ public class AccountApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(auth_token == null ) { - throw new ApiException(400, "missing required params"); - } headerParams.put("auth_token", auth_token); String contentType = "application/json"; diff --git a/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordApi.java b/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordApi.java index 6d11ad99c7b..8ab25e31c50 100644 --- a/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordApi.java +++ b/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordApi.java @@ -32,6 +32,10 @@ public class WordApi { } public ExampleSearchResults getExamples (String word, String includeDuplicates, String useCanonical, Integer skip, Integer limit) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/word.{format}/{word}/examples".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); @@ -39,10 +43,6 @@ public class WordApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(word == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(includeDuplicates))) queryParams.put("includeDuplicates", String.valueOf(includeDuplicates)); if(!"null".equals(String.valueOf(useCanonical))) @@ -71,6 +71,10 @@ public class WordApi { } } public WordObject getWord (String word, String useCanonical, String includeSuggestions) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/word.{format}/{word}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); @@ -78,10 +82,6 @@ public class WordApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(word == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(useCanonical))) queryParams.put("useCanonical", String.valueOf(useCanonical)); if(!"null".equals(String.valueOf(includeSuggestions))) @@ -106,6 +106,10 @@ public class WordApi { } } public List getDefinitions (String word, String partOfSpeech, String sourceDictionaries, Integer limit, String includeRelated, String useCanonical, String includeTags) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/word.{format}/{word}/definitions".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); @@ -113,10 +117,6 @@ public class WordApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(word == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(limit))) queryParams.put("limit", String.valueOf(limit)); if(!"null".equals(String.valueOf(partOfSpeech))) @@ -149,6 +149,10 @@ public class WordApi { } } public Example getTopExample (String word, String useCanonical) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/word.{format}/{word}/topExample".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); @@ -156,10 +160,6 @@ public class WordApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(word == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(useCanonical))) queryParams.put("useCanonical", String.valueOf(useCanonical)); String contentType = "application/json"; @@ -182,6 +182,10 @@ public class WordApi { } } public List getRelatedWords (String word, String relationshipTypes, String useCanonical, Integer limitPerRelationshipType) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/word.{format}/{word}/relatedWords".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); @@ -189,10 +193,6 @@ public class WordApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(word == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(useCanonical))) queryParams.put("useCanonical", String.valueOf(useCanonical)); if(!"null".equals(String.valueOf(relationshipTypes))) @@ -219,6 +219,10 @@ public class WordApi { } } public List getTextPronunciations (String word, String sourceDictionary, String typeFormat, String useCanonical, Integer limit) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/word.{format}/{word}/pronunciations".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); @@ -226,10 +230,6 @@ public class WordApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(word == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(useCanonical))) queryParams.put("useCanonical", String.valueOf(useCanonical)); if(!"null".equals(String.valueOf(sourceDictionary))) @@ -258,6 +258,10 @@ public class WordApi { } } public List getHyphenation (String word, String sourceDictionary, String useCanonical, Integer limit) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/word.{format}/{word}/hyphenation".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); @@ -265,10 +269,6 @@ public class WordApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(word == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(useCanonical))) queryParams.put("useCanonical", String.valueOf(useCanonical)); if(!"null".equals(String.valueOf(sourceDictionary))) @@ -295,6 +295,10 @@ public class WordApi { } } public FrequencySummary getWordFrequency (String word, String useCanonical, Integer startYear, Integer endYear) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/word.{format}/{word}/frequency".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); @@ -302,10 +306,6 @@ public class WordApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(word == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(useCanonical))) queryParams.put("useCanonical", String.valueOf(useCanonical)); if(!"null".equals(String.valueOf(startYear))) @@ -332,6 +332,10 @@ public class WordApi { } } public List getPhrases (String word, Integer limit, Integer wlmi, String useCanonical) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/word.{format}/{word}/phrases".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); @@ -339,10 +343,6 @@ public class WordApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(word == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(limit))) queryParams.put("limit", String.valueOf(limit)); if(!"null".equals(String.valueOf(wlmi))) @@ -369,6 +369,10 @@ public class WordApi { } } public List getEtymologies (String word, String useCanonical) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/word.{format}/{word}/etymologies".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); @@ -376,10 +380,6 @@ public class WordApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(word == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(useCanonical))) queryParams.put("useCanonical", String.valueOf(useCanonical)); String contentType = "application/json"; @@ -402,6 +402,10 @@ public class WordApi { } } public List getAudio (String word, String useCanonical, Integer limit) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/word.{format}/{word}/audio".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); @@ -409,10 +413,6 @@ public class WordApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(word == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(useCanonical))) queryParams.put("useCanonical", String.valueOf(useCanonical)); if(!"null".equals(String.valueOf(limit))) @@ -437,6 +437,10 @@ public class WordApi { } } public ScrabbleScoreResult getScrabbleScore (String word) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/word.{format}/{word}/scrabbleScore".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); @@ -444,10 +448,6 @@ public class WordApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(word == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { diff --git a/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordListApi.java b/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordListApi.java index b75aa46004c..bb434b11a88 100644 --- a/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordListApi.java +++ b/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordListApi.java @@ -24,6 +24,10 @@ public class WordListApi { } public void updateWordList (String permalink, WordList body, String auth_token) throws ApiException { + // verify required params are set + if(permalink == null || auth_token == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/wordList.{format}/{permalink}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}", apiInvoker.escapeString(permalink.toString())); @@ -31,10 +35,6 @@ public class WordListApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(permalink == null || auth_token == null ) { - throw new ApiException(400, "missing required params"); - } headerParams.put("auth_token", auth_token); String contentType = "application/json"; @@ -56,6 +56,10 @@ public class WordListApi { } } public void deleteWordList (String permalink, String auth_token) throws ApiException { + // verify required params are set + if(permalink == null || auth_token == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/wordList.{format}/{permalink}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}", apiInvoker.escapeString(permalink.toString())); @@ -63,10 +67,6 @@ public class WordListApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(permalink == null || auth_token == null ) { - throw new ApiException(400, "missing required params"); - } headerParams.put("auth_token", auth_token); String contentType = "application/json"; @@ -88,6 +88,10 @@ public class WordListApi { } } public WordList getWordListByPermalink (String permalink, String auth_token) throws ApiException { + // verify required params are set + if(permalink == null || auth_token == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/wordList.{format}/{permalink}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}", apiInvoker.escapeString(permalink.toString())); @@ -95,10 +99,6 @@ public class WordListApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(permalink == null || auth_token == null ) { - throw new ApiException(400, "missing required params"); - } headerParams.put("auth_token", auth_token); String contentType = "application/json"; @@ -120,6 +120,10 @@ public class WordListApi { } } public void addWordsToWordList (String permalink, List body, String auth_token) throws ApiException { + // verify required params are set + if(permalink == null || auth_token == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/wordList.{format}/{permalink}/words".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}", apiInvoker.escapeString(permalink.toString())); @@ -127,10 +131,6 @@ public class WordListApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(permalink == null || auth_token == null ) { - throw new ApiException(400, "missing required params"); - } headerParams.put("auth_token", auth_token); String contentType = "application/json"; @@ -152,6 +152,10 @@ public class WordListApi { } } public List getWordListWords (String permalink, String auth_token, String sortBy, String sortOrder, Integer skip, Integer limit) throws ApiException { + // verify required params are set + if(permalink == null || auth_token == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/wordList.{format}/{permalink}/words".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}", apiInvoker.escapeString(permalink.toString())); @@ -159,10 +163,6 @@ public class WordListApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(permalink == null || auth_token == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(sortBy))) queryParams.put("sortBy", String.valueOf(sortBy)); if(!"null".equals(String.valueOf(sortOrder))) @@ -192,6 +192,10 @@ public class WordListApi { } } public void deleteWordsFromWordList (String permalink, List body, String auth_token) throws ApiException { + // verify required params are set + if(permalink == null || auth_token == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/wordList.{format}/{permalink}/deleteWords".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}", apiInvoker.escapeString(permalink.toString())); @@ -199,10 +203,6 @@ public class WordListApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(permalink == null || auth_token == null ) { - throw new ApiException(400, "missing required params"); - } headerParams.put("auth_token", auth_token); String contentType = "application/json"; diff --git a/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordListsApi.java b/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordListsApi.java index c8d669e48d3..5a8836a067a 100644 --- a/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordListsApi.java +++ b/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordListsApi.java @@ -22,6 +22,10 @@ public class WordListsApi { } public WordList createWordList (WordList body, String auth_token) throws ApiException { + // verify required params are set + if(auth_token == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/wordLists.{format}".replaceAll("\\{format\\}","json"); @@ -29,10 +33,6 @@ public class WordListsApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(auth_token == null ) { - throw new ApiException(400, "missing required params"); - } headerParams.put("auth_token", auth_token); String contentType = "application/json"; diff --git a/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordsApi.java b/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordsApi.java index a543bf2c70a..a7e2d8b70da 100644 --- a/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordsApi.java +++ b/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/api/WordsApi.java @@ -25,6 +25,10 @@ public class WordsApi { } public WordSearchResults searchWords (String query, String includePartOfSpeech, String excludePartOfSpeech, String caseSensitive, Integer minCorpusCount, Integer maxCorpusCount, Integer minDictionaryCount, Integer maxDictionaryCount, Integer minLength, Integer maxLength, Integer skip, Integer limit) throws ApiException { + // verify required params are set + if(query == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/words.{format}/search/{query}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "query" + "\\}", apiInvoker.escapeString(query.toString())); @@ -32,10 +36,6 @@ public class WordsApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(query == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(caseSensitive))) queryParams.put("caseSensitive", String.valueOf(caseSensitive)); if(!"null".equals(String.valueOf(includePartOfSpeech))) @@ -107,6 +107,10 @@ public class WordsApi { } } public DefinitionSearchResults reverseDictionary (String query, String findSenseForWord, String includeSourceDictionaries, String excludeSourceDictionaries, String includePartOfSpeech, String excludePartOfSpeech, String expandTerms, String sortBy, String sortOrder, Integer minCorpusCount, Integer maxCorpusCount, Integer minLength, Integer maxLength, String includeTags, String skip, Integer limit) throws ApiException { + // verify required params are set + if(query == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/words.{format}/reverseDictionary".replaceAll("\\{format\\}","json"); @@ -114,10 +118,6 @@ public class WordsApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(query == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(query))) queryParams.put("query", String.valueOf(query)); if(!"null".equals(String.valueOf(findSenseForWord))) From 59897c19a9965e944b2f4c26eac8db9d052f8ee1 Mon Sep 17 00:00:00 2001 From: Robert Blair Date: Wed, 27 Nov 2013 01:16:58 -0800 Subject: [PATCH 07/97] Rebuild wording sample ApiInvoker from latest. --- .../src/main/java/com/wordnik/client/common/ApiInvoker.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/common/ApiInvoker.java b/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/common/ApiInvoker.java index 8344a2ab37f..04f65f0ea94 100644 --- a/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/common/ApiInvoker.java +++ b/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/common/ApiInvoker.java @@ -12,6 +12,7 @@ import com.sun.jersey.api.client.config.DefaultClientConfig; import com.sun.jersey.api.client.filter.LoggingFilter; import com.sun.jersey.api.client.WebResource.Builder; +import javax.ws.rs.core.Response.Status.Family; import javax.ws.rs.core.MediaType; import java.util.Map; @@ -123,7 +124,7 @@ public class ApiInvoker { else { throw new ApiException(500, "unknown method type " + method); } - if(response.getClientResponseStatus() == ClientResponse.Status.OK) { + if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) { return (String) response.getEntity(String.class); } else { From 800312361fa417accd417d7b2ff3ee5140cf0acd Mon Sep 17 00:00:00 2001 From: Robert Blair Date: Wed, 27 Nov 2013 08:02:03 -0800 Subject: [PATCH 08/97] Also android-java templates: Rebuild wording sample ApiInvoker from latest.To throw expected ApiException instead of NullPointerException, check required parameters before use --- src/main/resources/android-java/api.mustache | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/resources/android-java/api.mustache b/src/main/resources/android-java/api.mustache index 925e9b9d711..afd6297c451 100644 --- a/src/main/resources/android-java/api.mustache +++ b/src/main/resources/android-java/api.mustache @@ -30,13 +30,6 @@ public class {{classname}} { {{#operation}} public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { - // create path and map variables - String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{paramName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}}; - - // query params - Map queryParams = new HashMap(); - Map headerParams = new HashMap(); - {{#requiredParamCount}} // verify required params are set if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) { @@ -44,6 +37,13 @@ public class {{classname}} { } {{/requiredParamCount}} + // create path and map variables + String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{paramName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}}; + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + {{#queryParams}}if(!"null".equals(String.valueOf({{paramName}}))) queryParams.put("{{paramName}}", String.valueOf({{paramName}})); {{/queryParams}} From 2c73efa53668e745dbdaf7590c51bd9e90af164d Mon Sep 17 00:00:00 2001 From: Robert Blair Date: Wed, 27 Nov 2013 08:02:42 -0800 Subject: [PATCH 09/97] And rebuild the samples for android-java --- .../java/com/wordnik/petstore/api/PetApi.java | 64 +++++++++---------- .../com/wordnik/petstore/api/StoreApi.java | 24 +++---- .../com/wordnik/petstore/api/UserApi.java | 56 ++++++++-------- 3 files changed, 72 insertions(+), 72 deletions(-) diff --git a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/PetApi.java b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/PetApi.java index c620cd42599..c9e33d53512 100644 --- a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/PetApi.java +++ b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/PetApi.java @@ -27,6 +27,10 @@ public class PetApi { } public Pet getPetById (Long petId) throws ApiException { + // verify required params are set + if(petId == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString())); @@ -34,10 +38,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(petId == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -58,6 +58,10 @@ public class PetApi { } } public void deletePet (String petId) throws ApiException { + // verify required params are set + if(petId == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString())); @@ -65,10 +69,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(petId == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -89,6 +89,10 @@ public class PetApi { } } public List partialUpdate (String petId, Pet body) throws ApiException { + // verify required params are set + if(petId == null || body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString())); @@ -96,10 +100,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(petId == null || body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -120,6 +120,10 @@ public class PetApi { } } public void updatePetWithForm (String petId, String name, String status) throws ApiException { + // verify required params are set + if(petId == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}", apiInvoker.escapeString(petId.toString())); @@ -127,10 +131,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(petId == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -178,6 +178,10 @@ public class PetApi { } } public void addPet (Pet body) throws ApiException { + // verify required params are set + if(body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet".replaceAll("\\{format\\}","json"); @@ -185,10 +189,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -209,6 +209,10 @@ public class PetApi { } } public void updatePet (Pet body) throws ApiException { + // verify required params are set + if(body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet".replaceAll("\\{format\\}","json"); @@ -216,10 +220,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -240,6 +240,10 @@ public class PetApi { } } public List findPetsByStatus (String status) throws ApiException { + // verify required params are set + if(status == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet/findByStatus".replaceAll("\\{format\\}","json"); @@ -247,10 +251,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(status == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(status))) queryParams.put("status", String.valueOf(status)); String contentType = "application/json"; @@ -273,6 +273,10 @@ public class PetApi { } } public List findPetsByTags (String tags) throws ApiException { + // verify required params are set + if(tags == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/pet/findByTags".replaceAll("\\{format\\}","json"); @@ -280,10 +284,6 @@ public class PetApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(tags == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(tags))) queryParams.put("tags", String.valueOf(tags)); String contentType = "application/json"; diff --git a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/StoreApi.java b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/StoreApi.java index ea2fd613818..12076bf43dd 100644 --- a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/StoreApi.java +++ b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/StoreApi.java @@ -26,6 +26,10 @@ public class StoreApi { } public Order getOrderById (String orderId) throws ApiException { + // verify required params are set + if(orderId == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}", apiInvoker.escapeString(orderId.toString())); @@ -33,10 +37,6 @@ public class StoreApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(orderId == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -57,6 +57,10 @@ public class StoreApi { } } public void deleteOrder (String orderId) throws ApiException { + // verify required params are set + if(orderId == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}", apiInvoker.escapeString(orderId.toString())); @@ -64,10 +68,6 @@ public class StoreApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(orderId == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -88,6 +88,10 @@ public class StoreApi { } } public void placeOrder (Order body) throws ApiException { + // verify required params are set + if(body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/store/order".replaceAll("\\{format\\}","json"); @@ -95,10 +99,6 @@ public class StoreApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { diff --git a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/UserApi.java b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/UserApi.java index 505f1245ce1..56ed2a8e038 100644 --- a/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/UserApi.java +++ b/samples/client/petstore/android-java/src/main/java/com/wordnik/petstore/api/UserApi.java @@ -26,6 +26,10 @@ public class UserApi { } public void createUser (User body) throws ApiException { + // verify required params are set + if(body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/user".replaceAll("\\{format\\}","json"); @@ -33,10 +37,6 @@ public class UserApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -57,6 +57,10 @@ public class UserApi { } } public void createUsersWithArrayInput (List body) throws ApiException { + // verify required params are set + if(body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/user/createWithArray".replaceAll("\\{format\\}","json"); @@ -64,10 +68,6 @@ public class UserApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -88,6 +88,10 @@ public class UserApi { } } public void createUsersWithListInput (List body) throws ApiException { + // verify required params are set + if(body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/user/createWithList".replaceAll("\\{format\\}","json"); @@ -95,10 +99,6 @@ public class UserApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -119,6 +119,10 @@ public class UserApi { } } public void updateUser (String username, User body) throws ApiException { + // verify required params are set + if(username == null || body == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); @@ -126,10 +130,6 @@ public class UserApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(username == null || body == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -150,6 +150,10 @@ public class UserApi { } } public void deleteUser (String username) throws ApiException { + // verify required params are set + if(username == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); @@ -157,10 +161,6 @@ public class UserApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(username == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -181,6 +181,10 @@ public class UserApi { } } public User getUserByName (String username) throws ApiException { + // verify required params are set + if(username == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); @@ -188,10 +192,6 @@ public class UserApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(username == null ) { - throw new ApiException(400, "missing required params"); - } String contentType = "application/json"; try { @@ -212,6 +212,10 @@ public class UserApi { } } public String loginUser (String username, String password) throws ApiException { + // verify required params are set + if(username == null || password == null ) { + throw new ApiException(400, "missing required params"); + } // create path and map variables String path = "/user/login".replaceAll("\\{format\\}","json"); @@ -219,10 +223,6 @@ public class UserApi { Map queryParams = new HashMap(); Map headerParams = new HashMap(); - // verify required params are set - if(username == null || password == null ) { - throw new ApiException(400, "missing required params"); - } if(!"null".equals(String.valueOf(username))) queryParams.put("username", String.valueOf(username)); if(!"null".equals(String.valueOf(password))) From 9686ceed2d9bf7c06ddd18d5bcd5f64d93bb0c5c Mon Sep 17 00:00:00 2001 From: Andrew Young Date: Wed, 27 Nov 2013 12:49:04 -0800 Subject: [PATCH 10/97] Updated sample code to reflect changes. --- .../java/com/wordnik/client/ApiInvoker.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java b/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java index 955ffe39f6e..2e1dff71027 100644 --- a/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java +++ b/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java @@ -12,6 +12,7 @@ import com.sun.jersey.api.client.config.DefaultClientConfig; import com.sun.jersey.api.client.filter.LoggingFilter; import com.sun.jersey.api.client.WebResource.Builder; +import javax.ws.rs.core.Response.Status.Family; import javax.ws.rs.core.MediaType; import java.util.Map; @@ -27,7 +28,7 @@ public class ApiInvoker { public static ApiInvoker getInstance() { return INSTANCE; } - + public void addDefaultHeader(String key, String value) { defaultHeaderMap.put(key, value); } @@ -46,7 +47,7 @@ public class ApiInvoker { else if(String.class.equals(cls)) { if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1) return json.substring(1, json.length() - 2); - else + else return json; } else { @@ -60,9 +61,9 @@ public class ApiInvoker { public static String serialize(Object obj) throws ApiException { try { - if (obj != null) + if (obj != null) return JsonUtil.getJsonMapper().writeValueAsString(obj); - else + else return null; } catch (Exception e) { @@ -74,7 +75,7 @@ public class ApiInvoker { Client client = getClient(host); StringBuilder b = new StringBuilder(); - + for(String key : queryParams.keySet()) { String value = queryParams.get(key); if (value != null){ @@ -91,7 +92,7 @@ public class ApiInvoker { for(String key : headerParams.keySet()) { builder.header(key, headerParams.get(key)); } - + for(String key : defaultHeaderMap.keySet()) { if(!headerParams.containsKey(key)) { builder.header(key, defaultHeaderMap.get(key)); @@ -123,13 +124,16 @@ public class ApiInvoker { else { throw new ApiException(500, "unknown method type " + method); } - if(response.getClientResponseStatus() == ClientResponse.Status.OK) { + if(response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) { + return null; + } + else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) { return (String) response.getEntity(String.class); } else { throw new ApiException( response.getClientResponseStatus().getStatusCode(), - response.getEntity(String.class)); + response.getEntity(String.class)); } } From 65cc529ec669414d4e0023c8ab093a745e09e3a6 Mon Sep 17 00:00:00 2001 From: Andrew Young Date: Wed, 27 Nov 2013 12:32:07 -0800 Subject: [PATCH 11/97] Updated to handle the case of a NO_CONTENT response. --- src/main/resources/Java/apiInvoker.mustache | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/resources/Java/apiInvoker.mustache b/src/main/resources/Java/apiInvoker.mustache index 30dc876a809..f755728ffa5 100644 --- a/src/main/resources/Java/apiInvoker.mustache +++ b/src/main/resources/Java/apiInvoker.mustache @@ -28,7 +28,7 @@ public class ApiInvoker { public static ApiInvoker getInstance() { return INSTANCE; } - + public void addDefaultHeader(String key, String value) { defaultHeaderMap.put(key, value); } @@ -47,7 +47,7 @@ public class ApiInvoker { else if(String.class.equals(cls)) { if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1) return json.substring(1, json.length() - 2); - else + else return json; } else { @@ -61,9 +61,9 @@ public class ApiInvoker { public static String serialize(Object obj) throws ApiException { try { - if (obj != null) + if (obj != null) return JsonUtil.getJsonMapper().writeValueAsString(obj); - else + else return null; } catch (Exception e) { @@ -75,7 +75,7 @@ public class ApiInvoker { Client client = getClient(host); StringBuilder b = new StringBuilder(); - + for(String key : queryParams.keySet()) { String value = queryParams.get(key); if (value != null){ @@ -92,7 +92,7 @@ public class ApiInvoker { for(String key : headerParams.keySet()) { builder.header(key, headerParams.get(key)); } - + for(String key : defaultHeaderMap.keySet()) { if(!headerParams.containsKey(key)) { builder.header(key, defaultHeaderMap.get(key)); @@ -124,13 +124,16 @@ public class ApiInvoker { else { throw new ApiException(500, "unknown method type " + method); } - if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) { + if(response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) { + return null; + } + else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) { return (String) response.getEntity(String.class); } else { throw new ApiException( response.getClientResponseStatus().getStatusCode(), - response.getEntity(String.class)); + response.getEntity(String.class)); } } From 8cc83d180d3345e65f4e7713081ebf2058ae63d0 Mon Sep 17 00:00:00 2001 From: Andrew Young Date: Wed, 27 Nov 2013 12:58:58 -0800 Subject: [PATCH 12/97] Fixed spacing issue. --- .../java/src/main/java/com/wordnik/client/ApiInvoker.java | 2 +- src/main/resources/Java/apiInvoker.mustache | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java b/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java index 2e1dff71027..de64ba9f1e7 100644 --- a/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java +++ b/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java @@ -125,7 +125,7 @@ public class ApiInvoker { throw new ApiException(500, "unknown method type " + method); } if(response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) { - return null; + return null; } else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) { return (String) response.getEntity(String.class); diff --git a/src/main/resources/Java/apiInvoker.mustache b/src/main/resources/Java/apiInvoker.mustache index f755728ffa5..bdeb632f740 100644 --- a/src/main/resources/Java/apiInvoker.mustache +++ b/src/main/resources/Java/apiInvoker.mustache @@ -125,7 +125,7 @@ public class ApiInvoker { throw new ApiException(500, "unknown method type " + method); } if(response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) { - return null; + return null; } else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) { return (String) response.getEntity(String.class); From f883c5e77c1d96be25c3f7c526c8067e13aa5414 Mon Sep 17 00:00:00 2001 From: Rob Blair Date: Wed, 27 Nov 2013 14:18:35 -0800 Subject: [PATCH 13/97] issues/91 - allow enum and min/max to be used in templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * parse numeric min / max values, include in parameters * pass along the allowable values in the model used by templates * ensure ‘hasMore’ is set for more parameter lists used by templates * java model now includes min / max in comment, and allowed enum values as model children * note: enums in spec can contain non-java characters, so the User.java in examples does not compile presently. --- src/main/resources/Java/model.mustache | 6 ++++++ .../com/wordnik/swagger/codegen/Codegen.scala | 19 +++++++++++++++++++ .../model/SwaggerModelSerializer.scala | 6 ++++++ 3 files changed, 31 insertions(+) diff --git a/src/main/resources/Java/model.mustache b/src/main/resources/Java/model.mustache index f4472d46897..f900853c264 100644 --- a/src/main/resources/Java/model.mustache +++ b/src/main/resources/Java/model.mustache @@ -10,6 +10,12 @@ public class {{classname}} { {{#description}}/* {{{description}}} */ {{/description}} private {{{datatype}}} {{name}} = {{{defaultValue}}}; + {{#allowableValues}}{{#min}} // range from {{min}} to {{max}} + {{/min}} + {{^min}}public enum {{name}}Enum { {{#values}} {{.}}, {{/values}} }; + {{/min}} + {{/allowableValues}} + {{/vars}} {{#vars}} diff --git a/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala b/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala index d78bae95110..fb72f1e4a9a 100644 --- a/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala +++ b/src/main/scala/com/wordnik/swagger/codegen/Codegen.scala @@ -188,6 +188,19 @@ class Codegen(config: CodegenConfig) { (srcName, engine -> template) } + def rawAllowableValuesToString(v: AllowableValues) = { + v match { + case av: AllowableListValues => { + av + } + case av: AllowableRangeValues => { + av + } + case _ => None + } + } + + def allowableValuesToString(v: AllowableValues) = { v match { case av: AllowableListValues => { @@ -306,6 +319,11 @@ class Codegen(config: CodegenConfig) { case _ => requiredParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore" } + headerParams.size match { + case 0 => + case _ => headerParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore" + } + queryParams.size match { case 0 => case _ => queryParams.last.asInstanceOf[HashMap[String, String]] -= "hasMore" @@ -466,6 +484,7 @@ class Codegen(config: CodegenConfig) { "defaultValue" -> config.toDeclaration(propertyDocSchema)._2, "description" -> propertyDocSchema.description, "notes" -> propertyDocSchema.description, + "allowableValues" -> rawAllowableValuesToString(propertyDocSchema.allowableValues), (if(propertyDocSchema.required) "required" else "isNotRequired") -> "true", "getter" -> config.toGetter(prop._1, config.toDeclaration(propertyDocSchema)._1), "setter" -> config.toSetter(prop._1, config.toDeclaration(propertyDocSchema)._1), diff --git a/src/main/scala/com/wordnik/swagger/model/SwaggerModelSerializer.scala b/src/main/scala/com/wordnik/swagger/model/SwaggerModelSerializer.scala index 8b63333f07d..a4cf37632a3 100644 --- a/src/main/scala/com/wordnik/swagger/model/SwaggerModelSerializer.scala +++ b/src/main/scala/com/wordnik/swagger/model/SwaggerModelSerializer.scala @@ -347,10 +347,16 @@ object SwaggerSerializers { else { val min = (json \ "min") match { case e: JObject => e.extract[String] + case e: JString => e.s + case e: JInt => e.num.toString + case e: JDouble => e.num.toString case _ => "" } val max = (json \ "max") match { case e: JObject => e.extract[String] + case e: JString => e.s + case e: JInt => e.num.toString + case e: JDouble => e.num.toString case _ => "" } if(min != "" && max != "") From 3a8928f8697d378eb76eedec72dfe8e9a306ef38 Mon Sep 17 00:00:00 2001 From: Rob Blair Date: Wed, 27 Nov 2013 14:19:56 -0800 Subject: [PATCH 14/97] issues/91 - regenerate petstore java files --- .../java/src/main/java/com/wordnik/petstore/model/Order.java | 1 + .../java/src/main/java/com/wordnik/petstore/model/Pet.java | 1 + .../java/src/main/java/com/wordnik/petstore/model/User.java | 1 + 3 files changed, 3 insertions(+) diff --git a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Order.java b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Order.java index 6b6c23d79ae..159ad1b155e 100644 --- a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Order.java +++ b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Order.java @@ -10,6 +10,7 @@ public class Order { private Integer quantity = null; /* Status of the order */ private String status = null; + public enum statusEnum { placed, approved, delivered, }; /* Date shipped, only if it has been */ private Date shipDate = null; public Long getId() { diff --git a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Pet.java b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Pet.java index 7220a93d98a..9101260b268 100644 --- a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Pet.java +++ b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Pet.java @@ -16,6 +16,7 @@ public class Pet { private List tags = new ArrayList(); /* pet status in the store */ private String status = null; + public enum statusEnum { available, pending, sold, }; public Long getId() { return id; } diff --git a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/User.java b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/User.java index d2e09da239b..17a3665fd7a 100644 --- a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/User.java +++ b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/User.java @@ -17,6 +17,7 @@ public class User { private String phone = null; /* User Status */ private Integer userStatus = null; + public enum userStatusEnum { 1-registered, 2-active, 3-closed, }; public Long getId() { return id; } From 830ad87fcb9ea73fa5e0de15e5554a2094e9a581 Mon Sep 17 00:00:00 2001 From: Robert Blair Date: Wed, 27 Nov 2013 18:03:57 -0800 Subject: [PATCH 15/97] issues/91 - enum in model commented out by default --- src/main/resources/Java/model.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/Java/model.mustache b/src/main/resources/Java/model.mustache index f900853c264..d3b7b4b5247 100644 --- a/src/main/resources/Java/model.mustache +++ b/src/main/resources/Java/model.mustache @@ -12,7 +12,7 @@ public class {{classname}} { private {{{datatype}}} {{name}} = {{{defaultValue}}}; {{#allowableValues}}{{#min}} // range from {{min}} to {{max}} {{/min}} - {{^min}}public enum {{name}}Enum { {{#values}} {{.}}, {{/values}} }; + //{{^min}}public enum {{name}}Enum { {{#values}} {{.}}, {{/values}} }; {{/min}} {{/allowableValues}} From 90c14fd116bab0c1516a46a5c1ef22647e57d372 Mon Sep 17 00:00:00 2001 From: Robert Blair Date: Wed, 27 Nov 2013 20:04:57 -0800 Subject: [PATCH 16/97] issue/91 - and also check in the generated fils --- .../java/src/main/java/com/wordnik/client/ApiInvoker.java | 3 ++- .../java/src/main/java/com/wordnik/petstore/model/Order.java | 2 +- .../java/src/main/java/com/wordnik/petstore/model/Pet.java | 2 +- .../java/src/main/java/com/wordnik/petstore/model/User.java | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java b/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java index 955ffe39f6e..781e7da6981 100644 --- a/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java +++ b/samples/client/petstore/java/src/main/java/com/wordnik/client/ApiInvoker.java @@ -12,6 +12,7 @@ import com.sun.jersey.api.client.config.DefaultClientConfig; import com.sun.jersey.api.client.filter.LoggingFilter; import com.sun.jersey.api.client.WebResource.Builder; +import javax.ws.rs.core.Response.Status.Family; import javax.ws.rs.core.MediaType; import java.util.Map; @@ -123,7 +124,7 @@ public class ApiInvoker { else { throw new ApiException(500, "unknown method type " + method); } - if(response.getClientResponseStatus() == ClientResponse.Status.OK) { + if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) { return (String) response.getEntity(String.class); } else { diff --git a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Order.java b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Order.java index 159ad1b155e..cc462a953ae 100644 --- a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Order.java +++ b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Order.java @@ -10,7 +10,7 @@ public class Order { private Integer quantity = null; /* Status of the order */ private String status = null; - public enum statusEnum { placed, approved, delivered, }; + //public enum statusEnum { placed, approved, delivered, }; /* Date shipped, only if it has been */ private Date shipDate = null; public Long getId() { diff --git a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Pet.java b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Pet.java index 9101260b268..99f0c088fb4 100644 --- a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Pet.java +++ b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/Pet.java @@ -16,7 +16,7 @@ public class Pet { private List tags = new ArrayList(); /* pet status in the store */ private String status = null; - public enum statusEnum { available, pending, sold, }; + //public enum statusEnum { available, pending, sold, }; public Long getId() { return id; } diff --git a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/User.java b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/User.java index 17a3665fd7a..23535b05cd3 100644 --- a/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/User.java +++ b/samples/client/petstore/java/src/main/java/com/wordnik/petstore/model/User.java @@ -17,7 +17,7 @@ public class User { private String phone = null; /* User Status */ private Integer userStatus = null; - public enum userStatusEnum { 1-registered, 2-active, 3-closed, }; + //public enum userStatusEnum { 1-registered, 2-active, 3-closed, }; public Long getId() { return id; } From a7b78a6210259246b19c3e7bf8f3fec21e246a2f Mon Sep 17 00:00:00 2001 From: Robert Blair Date: Wed, 27 Nov 2013 20:30:31 -0800 Subject: [PATCH 17/97] add script to run all the sample build scripts --- bin/all-petstore.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 bin/all-petstore.sh diff --git a/bin/all-petstore.sh b/bin/all-petstore.sh new file mode 100755 index 00000000000..716db5bae15 --- /dev/null +++ b/bin/all-petstore.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +SCRIPT="$0" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +cd $APP_DIR +./bin/java-wordnik-api.sh +./bin/php-wordnik-api.sh +./bin/python3-wordnik-api.sh +./bin/objc-wordnik-api.sh +./bin/python-wordnik-api.sh +./bin/scala-wordnik-api.sh + +./bin/android-java-petstore.sh +./bin/csharp-petstore.sh +./bin/flash-petstore.sh +./bin/java-petstore.sh +./bin/objc-petstore.sh +./bin/php-petstore.sh +./bin/python-petstore.sh +./bin/python3-petstore.sh +./bin/ruby-petstore.sh +./bin/scala-petstore.sh From 1b8bb4a0a6d46dbd1e072dbb0a75f11e02ae193a Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Thu, 28 Nov 2013 13:28:26 -1000 Subject: [PATCH 18/97] rebuilt client --- build.sbt | 2 +- .../java/com/wordnik/client/common/ApiInvoker.java | 3 ++- .../scala/com/wordnik/client/api/AccountApi.scala | 4 ++-- .../scala/com/wordnik/client/api/WordApi.scala | 14 +++++++------- .../scala/com/wordnik/client/api/WordListApi.scala | 2 +- .../scala/com/wordnik/client/api/WordsApi.scala | 2 +- .../com/wordnik/client/model/Definition.scala | 8 ++++---- .../scala/com/wordnik/client/model/Example.scala | 2 +- .../com/wordnik/client/model/WordOfTheDay.scala | 2 +- 9 files changed, 20 insertions(+), 19 deletions(-) diff --git a/build.sbt b/build.sbt index 8ce46eac954..70b80d23b1a 100644 --- a/build.sbt +++ b/build.sbt @@ -7,7 +7,7 @@ name := "swagger-codegen" version := "2.0.11" -scalaVersion := "2.9.1" +scalaVersion := "2.10.0" javacOptions ++= Seq("-target", "1.6", "-source", "1.6", "-Xlint:unchecked", "-Xlint:deprecation") diff --git a/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/common/ApiInvoker.java b/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/common/ApiInvoker.java index 8344a2ab37f..04f65f0ea94 100644 --- a/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/common/ApiInvoker.java +++ b/samples/client/wordnik-api/java/src/main/java/com/wordnik/client/common/ApiInvoker.java @@ -12,6 +12,7 @@ import com.sun.jersey.api.client.config.DefaultClientConfig; import com.sun.jersey.api.client.filter.LoggingFilter; import com.sun.jersey.api.client.WebResource.Builder; +import javax.ws.rs.core.Response.Status.Family; import javax.ws.rs.core.MediaType; import java.util.Map; @@ -123,7 +124,7 @@ public class ApiInvoker { else { throw new ApiException(500, "unknown method type " + method); } - if(response.getClientResponseStatus() == ClientResponse.Status.OK) { + if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) { return (String) response.getEntity(String.class); } else { diff --git a/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/AccountApi.scala b/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/AccountApi.scala index ca4e6e9fe08..a5dd0901880 100644 --- a/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/AccountApi.scala +++ b/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/AccountApi.scala @@ -1,8 +1,8 @@ package com.wordnik.client.api -import com.wordnik.client.model.ApiTokenStatus -import com.wordnik.client.model.WordList import com.wordnik.client.model.User +import com.wordnik.client.model.WordList +import com.wordnik.client.model.ApiTokenStatus import com.wordnik.client.model.AuthenticationToken import com.wordnik.client.common.ApiInvoker import com.wordnik.client.common.ApiException diff --git a/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/WordApi.scala b/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/WordApi.scala index de8f3d0348c..cab9db7e07a 100644 --- a/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/WordApi.scala +++ b/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/WordApi.scala @@ -1,16 +1,16 @@ package com.wordnik.client.api -import com.wordnik.client.model.Definition +import com.wordnik.client.model.FrequencySummary +import com.wordnik.client.model.Bigram +import com.wordnik.client.model.WordObject +import com.wordnik.client.model.ExampleSearchResults +import com.wordnik.client.model.Example import com.wordnik.client.model.ScrabbleScoreResult import com.wordnik.client.model.TextPron -import com.wordnik.client.model.Example import com.wordnik.client.model.Syllable -import com.wordnik.client.model.AudioFile -import com.wordnik.client.model.ExampleSearchResults -import com.wordnik.client.model.WordObject -import com.wordnik.client.model.Bigram import com.wordnik.client.model.Related -import com.wordnik.client.model.FrequencySummary +import com.wordnik.client.model.Definition +import com.wordnik.client.model.AudioFile import com.wordnik.client.common.ApiInvoker import com.wordnik.client.common.ApiException diff --git a/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/WordListApi.scala b/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/WordListApi.scala index 3b51e692c24..bc4124f6c2a 100644 --- a/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/WordListApi.scala +++ b/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/WordListApi.scala @@ -1,8 +1,8 @@ package com.wordnik.client.api +import com.wordnik.client.model.WordListWord import com.wordnik.client.model.WordList import com.wordnik.client.model.StringValue -import com.wordnik.client.model.WordListWord import com.wordnik.client.common.ApiInvoker import com.wordnik.client.common.ApiException diff --git a/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/WordsApi.scala b/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/WordsApi.scala index 92e9fac23b7..a5b96d4f3f2 100644 --- a/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/WordsApi.scala +++ b/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/api/WordsApi.scala @@ -1,7 +1,7 @@ package com.wordnik.client.api -import com.wordnik.client.model.WordObject import com.wordnik.client.model.DefinitionSearchResults +import com.wordnik.client.model.WordObject import com.wordnik.client.model.WordOfTheDay import com.wordnik.client.model.WordSearchResults import com.wordnik.client.common.ApiInvoker diff --git a/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/model/Definition.scala b/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/model/Definition.scala index 67d29195bf3..9f2996d793c 100644 --- a/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/model/Definition.scala +++ b/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/model/Definition.scala @@ -1,11 +1,11 @@ package com.wordnik.client.model -import com.wordnik.client.model.ExampleUsage -import com.wordnik.client.model.Note -import com.wordnik.client.model.Citation -import com.wordnik.client.model.TextPron import com.wordnik.client.model.Label +import com.wordnik.client.model.ExampleUsage +import com.wordnik.client.model.TextPron +import com.wordnik.client.model.Citation import com.wordnik.client.model.Related +import com.wordnik.client.model.Note case class Definition ( extendedText: String, text: String, diff --git a/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/model/Example.scala b/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/model/Example.scala index 3d3e45996a2..349ec7e70a5 100644 --- a/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/model/Example.scala +++ b/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/model/Example.scala @@ -1,8 +1,8 @@ package com.wordnik.client.model import com.wordnik.client.model.Sentence -import com.wordnik.client.model.ScoredWord import com.wordnik.client.model.ContentProvider +import com.wordnik.client.model.ScoredWord case class Example ( id: Long, exampleId: Long, diff --git a/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/model/WordOfTheDay.scala b/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/model/WordOfTheDay.scala index 3c64a66571b..dccf9403f2d 100644 --- a/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/model/WordOfTheDay.scala +++ b/samples/client/wordnik-api/scala/src/main/scala/com/wordnik/client/model/WordOfTheDay.scala @@ -1,8 +1,8 @@ package com.wordnik.client.model import java.util.Date -import com.wordnik.client.model.SimpleDefinition import com.wordnik.client.model.SimpleExample +import com.wordnik.client.model.SimpleDefinition import com.wordnik.client.model.ContentProvider case class WordOfTheDay ( id: Long, From 890b1ee3c24f99722f5cff0ba2599354d6356dcd Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Tue, 3 Dec 2013 12:15:20 -0800 Subject: [PATCH 19/97] updated package --- .../AndroidJavaPetstoreCodegen.scala | 6 +++--- .../codegen/BasicAndroidJavaClient.scala | 17 +++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/samples/client/petstore/android-java/AndroidJavaPetstoreCodegen.scala b/samples/client/petstore/android-java/AndroidJavaPetstoreCodegen.scala index 2be7f229b84..bc441275a6f 100644 --- a/samples/client/petstore/android-java/AndroidJavaPetstoreCodegen.scala +++ b/samples/client/petstore/android-java/AndroidJavaPetstoreCodegen.scala @@ -14,13 +14,13 @@ * limitations under the License. */ -import com.wordnik.swagger.codegen.BasicJavaGenerator +import com.wordnik.swagger.codegen.BasicAndroidJavaGenerator -object AndroidJavaPetstoreCodegen extends BasicJavaGenerator { +object AndroidJavaPetstoreCodegen extends BasicAndroidJavaGenerator { def main(args: Array[String]) = generateClient(args) // location of templates - override def templateDir = "android-java" + override def templateDir = "src/main/resources/android-java" // where to write generated code override def destinationDir = "samples/client/petstore/android-java/src/main/java" diff --git a/src/main/scala/com/wordnik/swagger/codegen/BasicAndroidJavaClient.scala b/src/main/scala/com/wordnik/swagger/codegen/BasicAndroidJavaClient.scala index e34f3ae5356..779aa22627d 100644 --- a/src/main/scala/com/wordnik/swagger/codegen/BasicAndroidJavaClient.scala +++ b/src/main/scala/com/wordnik/swagger/codegen/BasicAndroidJavaClient.scala @@ -14,15 +14,17 @@ * limitations under the License. */ +package com.wordnik.swagger.codegen + import com.wordnik.swagger.codegen.BasicJavaGenerator import com.wordnik.swagger.model._ -object BasicAndroidJavaClient extends BasicJavaGenerator { +object BasicAndroidJavaClient extends BasicAndroidJavaGenerator { def main(args: Array[String]) = generateClient(args) +} - override def templateDir = "src/main/resources/android-java" - +class BasicAndroidJavaGenerator extends BasicJavaGenerator { override def typeMapping = super.typeMapping ++ Map( "file" -> "File") @@ -42,15 +44,11 @@ object BasicAndroidJavaClient extends BasicJavaGenerator { "AnyRef", "Any") - additionalParams ++= Map( - "artifactId" -> "swagger-android-client", - "artifactVersion" -> "1.0.0", - "groupId" -> "com.wordnik" - ) - // package for api invoker, error files override def invokerPackage = Some("com.wordnik.client") + override def templateDir = "android-java" + // where to write generated code override def destinationDir = "generated-code/android-java/src/main/java" @@ -60,7 +58,6 @@ object BasicAndroidJavaClient extends BasicJavaGenerator { // package for api classes override def apiPackage = Some("com.wordnik.client.api") - // supporting classes override def supportingFiles = List( ("apiInvoker.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiInvoker.java"), From 569f77b5120fe6df59f4cf9a923a146ee91d1067 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Fri, 20 Dec 2013 16:42:59 -0800 Subject: [PATCH 20/97] added yml2swagger --- bin/yml2swagger.js | 56 ++++++++++++ package.json | 16 ++++ samples/yaml/api-docs.yml | 37 ++++++++ samples/yaml/pet.yml | 181 ++++++++++++++++++++++++++++++++++++++ samples/yaml/store.yml | 87 ++++++++++++++++++ samples/yaml/user.yml | 178 +++++++++++++++++++++++++++++++++++++ 6 files changed, 555 insertions(+) create mode 100644 bin/yml2swagger.js create mode 100644 package.json create mode 100644 samples/yaml/api-docs.yml create mode 100644 samples/yaml/pet.yml create mode 100644 samples/yaml/store.yml create mode 100644 samples/yaml/user.yml diff --git a/bin/yml2swagger.js b/bin/yml2swagger.js new file mode 100644 index 00000000000..c3ce403e3f2 --- /dev/null +++ b/bin/yml2swagger.js @@ -0,0 +1,56 @@ +fs = require('fs') +yaml = require('js-yaml') + +var args = process.argv.splice(2); + +if(args.length == 0) { + process.exit(1); +} + +var arg0 = args[0]; +var outputdir = "."; + +if(args.length > 1) { + outputdir = args[1]; +} + +var file = fs.lstatSync(arg0); + +if(file.isFile()) { + convert(arg0, outputdir); +} +else if (file.isDirectory()) { + var files = fs.readdirSync(arg0); + files.map(function(item) { + var filename = arg0 + "/" + item; + var file = fs.lstatSync(filename); + if(file.isFile()) { + convert(filename, outputdir); + } + }); +} + +function convert(filename, outputdir) { + console.log("converting " + filename); + fs.readFile(filename, "utf8", function (err, data) { + if(err) { + console.log(err); + } + else { + try { + var js = yaml.load(data); + var prettyJs = JSON.stringify(js, undefined, 2); + var outputFilename = outputdir + "/" + filename.split("/").pop() + ".json"; + console.log("writing to " + outputFilename); + fs.writeFile(outputFilename, prettyJs, function(err) { + if(err) { + console.log(err); + } + }); + } + catch (err) { + console.log(err); + } + } + }); +} diff --git a/package.json b/package.json new file mode 100644 index 00000000000..ea21c211095 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "swagger-yaml", + "version": "2.0.1", + "description": "Converts yaml to swagger json", + "author": { + "name": "Tony Tam", + "email": "fehguy@gmail.com", + "url": "http://developer.wordnik.com" + }, + "license": "Apache", + "readmeFilename": "README.md", + "dependencies": { + "json2yaml": "~1.0", + "js-yaml": "~3.0" + } +} \ No newline at end of file diff --git a/samples/yaml/api-docs.yml b/samples/yaml/api-docs.yml new file mode 100644 index 00000000000..8ce50cd44b8 --- /dev/null +++ b/samples/yaml/api-docs.yml @@ -0,0 +1,37 @@ +apiVersion: 1.0.0 +swaggerVersion: "1.2" +apis: + - path: /pet + description: Operations about pets + - path: /store + description: Operations about store + - path: /user + description: Operations about user +authorizations: + oauth2: + type: oauth2 + scopes: + - PUBLIC + grantTypes: + implicit: + loginEndpoint: + url: "http://localhost:8002/oauth/dialog" + tokenName: access_code + authorization_code: + tokenRequestEndpoint: + url: "http://localhost:8002/oauth/requestToken" + clientIdName: client_id + clientSecretName: client_secret + tokenEndpoint: + url: "http://localhost:8002/oauth/token" + tokenName: access_code + apiKey: + type: apiKey + passAs: header +info: + title: Swagger Sample App + description: "This is a sample server Petstore server. You can find out more about Swagger \n at http://swagger.wordnik.com or on irc.freenode.net, #swagger." + termsOfServiceUrl: "http://helloreverb.com/terms/" + contact: "apiteam@wordnik.com" + license: Apache 2.0 + licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0.html" \ No newline at end of file diff --git a/samples/yaml/pet.yml b/samples/yaml/pet.yml new file mode 100644 index 00000000000..2d0891d3032 --- /dev/null +++ b/samples/yaml/pet.yml @@ -0,0 +1,181 @@ +apiVersion: 1.0.0 +swaggerVersion: "1.2" +basePath: "http://localhost:8002/api" +resourcePath: /pet +produces: + - application/json + - application/xml + - text/plain + - text/html +apis: + - path: "/pet/{petId}" + operations: + - method: GET + summary: Find pet by ID + notes: Returns a pet based on ID + type: Pet + nickname: getPetById + produces: + - application/json + - application/xml + authorizations: + - oauth2 + parameters: + - name: petId + description: ID of pet that needs to be fetched + required: true + allowMultiple: false + type: string + paramType: path + responseMessages: + - code: 400 + message: Invalid ID supplied + - code: 404 + message: Pet not found + - method: DELETE + summary: Deletes a pet + notes: "" + type: void + nickname: deletePet + parameters: + - name: petId + description: Pet id to delete + required: true + allowMultiple: false + type: string + paramType: path + responseMessages: + - code: 400 + message: Invalid pet value + - path: /pet + operations: + - method: POST + summary: Add a new pet to the store + notes: "" + type: void + nickname: addPet + parameters: + - name: body + description: Pet object that needs to be added to the store + required: true + allowMultiple: false + type: Pet + paramType: body + responseMessages: + - code: 405 + message: Invalid input + - method: PUT + summary: Update an existing pet + notes: "" + type: void + nickname: updatePet + parameters: + - name: body + description: Pet object that needs to be updated in the store + required: true + allowMultiple: false + type: Pet + paramType: body + responseMessages: + - code: 400 + message: Invalid ID supplied + - code: 404 + message: Pet not found + - code: 405 + message: Validation exception + - path: /pet/findByStatus + operations: + - method: GET + summary: Finds Pets by status + notes: Multiple status values can be provided with comma seperated strings + type: array + items: + $ref: Pet + nickname: findPetsByStatus + produces: + - application/json + - application/xml + parameters: + - name: status + description: Status values that need to be considered for filter + defaultValue: available + required: true + allowMultiple: true + type: string + paramType: query + enum: + - available + - pending + - sold + responseMessages: + - code: 400 + message: Invalid status value + - path: /pet/findByTags + operations: + - method: GET + summary: Finds Pets by tags + notes: "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing." + type: array + items: + $ref: Pet + nickname: findPetsByTags + produces: + - application/json + - application/xml + parameters: + - name: tags + description: Tags to filter by + required: true + allowMultiple: true + type: string + paramType: query + responseMessages: + - code: 400 + message: Invalid tag value + deprecated: "true" +models: + Tag: + id: Tag + properties: + name: + type: string + id: + type: integer + format: int64 + Pet: + id: Pet + description: "A pet is a person's best friend" + required: + - id + - name + properties: + id: + type: integer + format: int64 + tags: + type: array + items: + $ref: Tag + name: + type: string + status: + type: string + description: pet status in the store + enum: + - available + - pending + - sold + category: + $ref: Category + photoUrls: + type: array + items: + type: string + Category: + id: Category + properties: + name: + type: string + id: + type: integer + format: int64 \ No newline at end of file diff --git a/samples/yaml/store.yml b/samples/yaml/store.yml new file mode 100644 index 00000000000..7ccd338714e --- /dev/null +++ b/samples/yaml/store.yml @@ -0,0 +1,87 @@ +apiVersion: 1.0.0 +swaggerVersion: "1.2" +basePath: "http://localhost:8002/api" +resourcePath: /store +produces: + - application/json + - application/xml +apis: + - path: "/store/order/{orderId}" + operations: + - method: GET + summary: Find purchase order by ID + notes: For valid response try integer IDs with value <= 5. Anything above 5 or nonintegers will generate API errors + type: Order + nickname: getOrderById + produces: + - application/json + - application/xml + parameters: + - name: orderId + description: ID of pet that needs to be fetched + required: true + allowMultiple: false + type: string + paramType: path + responseMessages: + - code: 400 + message: Invalid ID supplied + - code: 404 + message: Order not found + - method: DELETE + summary: Delete purchase order by ID + notes: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + type: void + nickname: deleteOrder + parameters: + - name: orderId + description: ID of the order that needs to be deleted + required: true + allowMultiple: false + type: string + paramType: path + responseMessages: + - code: 400 + message: Invalid ID supplied + - code: 404 + message: Order not found + - path: /store/order + operations: + - method: POST + summary: Place an order for a pet + notes: "" + type: void + nickname: placeOrder + parameters: + - name: body + description: order placed for purchasing the pet + required: true + allowMultiple: false + type: Order + paramType: body + responseMessages: + - code: 400 + message: Invalid order +models: + Order: + id: Order + properties: + id: + type: integer + format: int64 + status: + type: string + description: Order Status + enum: + - placed + - approved + - delivered + petId: + type: integer + format: int64 + quantity: + type: integer + format: int32 + shipDate: + type: string + format: date-time diff --git a/samples/yaml/user.yml b/samples/yaml/user.yml new file mode 100644 index 00000000000..914b8b7778b --- /dev/null +++ b/samples/yaml/user.yml @@ -0,0 +1,178 @@ +apiVersion: 1.0.0 +swaggerVersion: "1.2" +basePath: "http://localhost:8002/api" +resourcePath: /user +produces: + - application/json + - application/xml +apis: + - path: /user + operations: + - method: POST + summary: Create user + notes: This can only be done by the logged in user. + type: void + nickname: createUser + parameters: + - name: body + description: Created user object + required: true + allowMultiple: false + type: User + paramType: body + - path: /user/createWithArray + operations: + - method: POST + summary: Creates list of users with given input array + notes: "" + type: void + nickname: createUsersWithArrayInput + parameters: + - name: body + description: List of user object + required: true + allowMultiple: false + type: array + items: + $ref: User + paramType: body + - path: /user/createWithList + operations: + - method: POST + summary: Creates list of users with given list input + notes: "" + type: void + nickname: createUsersWithListInput + parameters: + - name: body + description: List of user object + required: true + allowMultiple: false + type: array + items: + $ref: User + paramType: body + - path: "/user/{username}" + operations: + - method: PUT + summary: Updated user + notes: This can only be done by the logged in user. + type: void + nickname: updateUser + parameters: + - name: username + description: name that need to be deleted + required: true + allowMultiple: false + type: string + paramType: path + - name: body + description: Updated user object + required: true + allowMultiple: false + type: User + paramType: body + responseMessages: + - code: 400 + message: Invalid username supplied + - code: 404 + message: User not found + - method: DELETE + summary: Delete user + notes: This can only be done by the logged in user. + type: void + nickname: deleteUser + parameters: + - name: username + description: The name that needs to be deleted + required: true + allowMultiple: false + type: string + paramType: path + responseMessages: + - code: 400 + message: Invalid username supplied + - code: 404 + message: User not found + - method: GET + summary: Get user by user name + notes: "" + type: User + nickname: getUserByName + produces: + - application/json + - application/xml + parameters: + - name: username + description: The name that needs to be fetched. Use user1 for testing. + required: true + allowMultiple: false + type: string + paramType: path + responseMessages: + - code: 400 + message: Invalid username supplied + - code: 404 + message: User not found + - path: /user/login + operations: + - method: GET + summary: Logs user into the system + notes: "" + type: string + nickname: loginUser + produces: + - text/plain + parameters: + - name: username + description: The user name for login + required: true + allowMultiple: false + type: string + paramType: query + - name: password + description: The password for login in clear text + required: true + allowMultiple: false + type: string + paramType: query + responseMessages: + - code: 400 + message: Invalid username and password combination + - path: /user/logout + operations: + - method: GET + summary: Logs out current logged in user session + notes: "" + type: void + nickname: logoutUser + produces: + - text/plain + parameters: [] +models: + User: + id: User + properties: + id: + type: integer + format: int64 + username: + type: string + password: + type: string + email: + type: string + firstName: + type: string + lastName: + type: string + phone: + type: string + userStatus: + type: integer + format: int32 + description: User Status + enum: + - 1-registered + - 2-active + - 3-closed \ No newline at end of file From b5039945779907a0d1fe44bffdcb81274c1edc16 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Mon, 6 Jan 2014 12:27:31 -0800 Subject: [PATCH 21/97] added android sample --- .../android/AndroidWordnikApiCodegen.scala | 51 ++ samples/client/wordnik-api/android/pom.xml | 214 ++++++++ .../com/wordnik/client/api/AccountApi.java | 192 +++++++ .../java/com/wordnik/client/api/WordApi.java | 475 ++++++++++++++++++ .../com/wordnik/client/api/WordListApi.java | 231 +++++++++ .../com/wordnik/client/api/WordListsApi.java | 61 +++ .../java/com/wordnik/client/api/WordsApi.java | 273 ++++++++++ .../wordnik/client/common/ApiException.java | 29 ++ .../com/wordnik/client/common/ApiInvoker.java | 174 +++++++ .../com/wordnik/client/common/JsonUtil.java | 21 + .../wordnik/client/model/ApiTokenStatus.java | 74 +++ .../com/wordnik/client/model/AudioFile.java | 155 ++++++ .../client/model/AuthenticationToken.java | 44 ++ .../java/com/wordnik/client/model/Bigram.java | 64 +++ .../com/wordnik/client/model/Citation.java | 34 ++ .../wordnik/client/model/ContentProvider.java | 34 ++ .../com/wordnik/client/model/Definition.java | 181 +++++++ .../client/model/DefinitionSearchResults.java | 36 ++ .../com/wordnik/client/model/Example.java | 137 +++++ .../client/model/ExampleSearchResults.java | 37 ++ .../wordnik/client/model/ExampleUsage.java | 24 + .../java/com/wordnik/client/model/Facet.java | 36 ++ .../com/wordnik/client/model/FacetValue.java | 34 ++ .../com/wordnik/client/model/Frequency.java | 34 ++ .../client/model/FrequencySummary.java | 66 +++ .../java/com/wordnik/client/model/Label.java | 34 ++ .../java/com/wordnik/client/model/Note.java | 55 ++ .../com/wordnik/client/model/Related.java | 85 ++++ .../com/wordnik/client/model/ScoredWord.java | 124 +++++ .../client/model/ScrabbleScoreResult.java | 24 + .../com/wordnik/client/model/Sentence.java | 76 +++ .../client/model/SimpleDefinition.java | 54 ++ .../wordnik/client/model/SimpleExample.java | 54 ++ .../com/wordnik/client/model/StringValue.java | 24 + .../com/wordnik/client/model/Syllable.java | 44 ++ .../com/wordnik/client/model/TextPron.java | 44 ++ .../java/com/wordnik/client/model/User.java | 94 ++++ .../com/wordnik/client/model/WordList.java | 125 +++++ .../wordnik/client/model/WordListWord.java | 85 ++++ .../com/wordnik/client/model/WordObject.java | 75 +++ .../wordnik/client/model/WordOfTheDay.java | 139 +++++ .../client/model/WordSearchResult.java | 44 ++ .../client/model/WordSearchResults.java | 36 ++ 43 files changed, 3927 insertions(+) create mode 100644 samples/client/wordnik-api/android/AndroidWordnikApiCodegen.scala create mode 100644 samples/client/wordnik-api/android/pom.xml create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/AccountApi.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordApi.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordListApi.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordListsApi.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordsApi.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/common/ApiException.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/common/ApiInvoker.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/common/JsonUtil.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/ApiTokenStatus.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/AudioFile.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/AuthenticationToken.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Bigram.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Citation.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/ContentProvider.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Definition.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/DefinitionSearchResults.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Example.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/ExampleSearchResults.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/ExampleUsage.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Facet.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/FacetValue.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Frequency.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/FrequencySummary.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Label.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Note.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Related.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/ScoredWord.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/ScrabbleScoreResult.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Sentence.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/SimpleDefinition.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/SimpleExample.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/StringValue.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Syllable.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/TextPron.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/User.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/WordList.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/WordListWord.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/WordObject.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/WordOfTheDay.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/WordSearchResult.java create mode 100644 samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/WordSearchResults.java diff --git a/samples/client/wordnik-api/android/AndroidWordnikApiCodegen.scala b/samples/client/wordnik-api/android/AndroidWordnikApiCodegen.scala new file mode 100644 index 00000000000..c1a1f7aee15 --- /dev/null +++ b/samples/client/wordnik-api/android/AndroidWordnikApiCodegen.scala @@ -0,0 +1,51 @@ +/** + * Copyright 2012 Wordnik, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import com.wordnik.swagger.codegen.BasicAndroidJavaGenerator + +object AndroidWordnikApiCodegen extends BasicAndroidJavaGenerator { + def main(args: Array[String]) = generateClient(args) + + // location of templates + override def templateDir = "src/main/resources/android-java" + + def destinationRoot = "samples/client/wordnik-api/android" + + // where to write generated code + override def destinationDir = destinationRoot + "/src/main/java" + + // package for api invoker, error files + override def invokerPackage = Some("com.wordnik.client.common") + + // package for models + override def modelPackage = Some("com.wordnik.client.model") + + // package for api classes + override def apiPackage = Some("com.wordnik.client.api") + + additionalParams ++= Map( + "artifactId" -> "wordnik-android-client", + "artifactVersion" -> "1.0.0", + "groupId" -> "com.wordnik") + + // supporting classes + override def supportingFiles = + List( + ("apiInvoker.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiInvoker.java"), + ("JsonUtil.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "JsonUtil.java"), + ("apiException.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiException.java"), + ("pom.mustache", destinationRoot, "pom.xml")) +} diff --git a/samples/client/wordnik-api/android/pom.xml b/samples/client/wordnik-api/android/pom.xml new file mode 100644 index 00000000000..674f50f0109 --- /dev/null +++ b/samples/client/wordnik-api/android/pom.xml @@ -0,0 +1,214 @@ + + 4.0.0 + com.wordnik + wordnik-android-client + jar + wordnik-android-client + 1.0.0 + + scm:git:git@github.com:wordnik/swagger-mustache.git + scm:git:git@github.com:wordnik/swagger-codegen.git + https://github.com/wordnik/swagger-codegen + + + 2.2.0 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12 + + + + loggerPath + conf/log4j.properties + + + -Xms512m -Xmx1500m + methods + pertest + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory}/lib + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.2 + + + + jar + test-jar + + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + add_sources + generate-sources + + add-source + + + + src/main/java + + + + + add_test_sources + generate-test-sources + + add-test-source + + + + src/test/java + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + net.alchim31.maven + scala-maven-plugin + ${scala-maven-plugin-version} + + + + compile + testCompile + + + + + + incremental + + + -Xmx384m + + + -target:jvm-1.5 + -deprecation + + + + run-scalatest + org.scalatest.tools.Runner + + -p + ${project.build.testOutputDirectory} + + + -Xmx512m + + + + + + + + + + + net.alchim31.maven + scala-maven-plugin + ${scala-maven-plugin-version} + + + + + + com.fasterxml.jackson.core + jackson-core + ${jackson-version} + compile + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson-version} + compile + + + com.fasterxml.jackson.core + jackson-databind + ${jackson-version} + compile + + + org.apache.httpcomponents + httpclient + ${httpclient-version} + compile + + + + + org.scala-lang + scala-library + ${scala-version} + test + + + org.scalatest + scalatest_2.9.1 + ${scala-test-version} + test + + + junit + junit + ${junit-version} + test + + + + + 2.1.4 + 2.9.1-1 + 4.8.1 + 1.0.0 + 4.8.1 + 1.6.1 + 4.2.3 + 3.1.5 + + + diff --git a/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/AccountApi.java b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/AccountApi.java new file mode 100644 index 00000000000..69a503efddf --- /dev/null +++ b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/AccountApi.java @@ -0,0 +1,192 @@ +package com.wordnik.client.api; + +import com.wordnik.client.common.ApiException; +import com.wordnik.client.common.ApiInvoker; +import com.wordnik.client.model.User; +import com.wordnik.client.model.WordList; +import com.wordnik.client.model.ApiTokenStatus; +import com.wordnik.client.model.AuthenticationToken; +import java.util.*; + +public class AccountApi { + String basePath = "http://api.wordnik.com/v4"; + ApiInvoker apiInvoker = ApiInvoker.getInstance(); + + public void addHeader(String key, String value) { + getInvoker().addDefaultHeader(key, value); + } + + public ApiInvoker getInvoker() { + return apiInvoker; + } + + public void setBasePath(String basePath) { + this.basePath = basePath; + } + + public String getBasePath() { + return basePath; + } + + public AuthenticationToken authenticate (String username, String password) throws ApiException { + // verify required params are set + if(username == null || password == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/account.{format}/authenticate/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(password))) + queryParams.put("password", String.valueOf(password)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (AuthenticationToken) ApiInvoker.deserialize(response, "", AuthenticationToken.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public AuthenticationToken authenticatePost (String username, String body) throws ApiException { + // verify required params are set + if(username == null || body == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/account.{format}/authenticate/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}", apiInvoker.escapeString(username.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType); + if(response != null){ + return (AuthenticationToken) ApiInvoker.deserialize(response, "", AuthenticationToken.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public List getWordListsForLoggedInUser (String auth_token, Integer skip, Integer limit) throws ApiException { + // verify required params are set + if(auth_token == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/account.{format}/wordLists".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(skip))) + queryParams.put("skip", String.valueOf(skip)); + if(!"null".equals(String.valueOf(limit))) + queryParams.put("limit", String.valueOf(limit)); + headerParams.put("auth_token", auth_token); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (List) ApiInvoker.deserialize(response, "List", WordList.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public ApiTokenStatus getApiTokenStatus (String api_key) throws ApiException { + // create path and map variables + String path = "/account.{format}/apiTokenStatus".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + headerParams.put("api_key", api_key); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (ApiTokenStatus) ApiInvoker.deserialize(response, "", ApiTokenStatus.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public User getLoggedInUser (String auth_token) throws ApiException { + // verify required params are set + if(auth_token == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/account.{format}/user".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + headerParams.put("auth_token", auth_token); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (User) ApiInvoker.deserialize(response, "", User.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + } + diff --git a/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordApi.java b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordApi.java new file mode 100644 index 00000000000..b52be2e1e4e --- /dev/null +++ b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordApi.java @@ -0,0 +1,475 @@ +package com.wordnik.client.api; + +import com.wordnik.client.common.ApiException; +import com.wordnik.client.common.ApiInvoker; +import com.wordnik.client.model.FrequencySummary; +import com.wordnik.client.model.Bigram; +import com.wordnik.client.model.WordObject; +import com.wordnik.client.model.ExampleSearchResults; +import com.wordnik.client.model.Example; +import com.wordnik.client.model.ScrabbleScoreResult; +import com.wordnik.client.model.TextPron; +import com.wordnik.client.model.Syllable; +import com.wordnik.client.model.Related; +import com.wordnik.client.model.Definition; +import com.wordnik.client.model.AudioFile; +import java.util.*; + +public class WordApi { + String basePath = "http://api.wordnik.com/v4"; + ApiInvoker apiInvoker = ApiInvoker.getInstance(); + + public void addHeader(String key, String value) { + getInvoker().addDefaultHeader(key, value); + } + + public ApiInvoker getInvoker() { + return apiInvoker; + } + + public void setBasePath(String basePath) { + this.basePath = basePath; + } + + public String getBasePath() { + return basePath; + } + + public ExampleSearchResults getExamples (String word, String includeDuplicates, String useCanonical, Integer skip, Integer limit) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/word.{format}/{word}/examples".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(includeDuplicates))) + queryParams.put("includeDuplicates", String.valueOf(includeDuplicates)); + if(!"null".equals(String.valueOf(useCanonical))) + queryParams.put("useCanonical", String.valueOf(useCanonical)); + if(!"null".equals(String.valueOf(skip))) + queryParams.put("skip", String.valueOf(skip)); + if(!"null".equals(String.valueOf(limit))) + queryParams.put("limit", String.valueOf(limit)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (ExampleSearchResults) ApiInvoker.deserialize(response, "", ExampleSearchResults.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public WordObject getWord (String word, String useCanonical, String includeSuggestions) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/word.{format}/{word}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(useCanonical))) + queryParams.put("useCanonical", String.valueOf(useCanonical)); + if(!"null".equals(String.valueOf(includeSuggestions))) + queryParams.put("includeSuggestions", String.valueOf(includeSuggestions)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (WordObject) ApiInvoker.deserialize(response, "", WordObject.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public List getDefinitions (String word, String partOfSpeech, String sourceDictionaries, Integer limit, String includeRelated, String useCanonical, String includeTags) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/word.{format}/{word}/definitions".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(limit))) + queryParams.put("limit", String.valueOf(limit)); + if(!"null".equals(String.valueOf(partOfSpeech))) + queryParams.put("partOfSpeech", String.valueOf(partOfSpeech)); + if(!"null".equals(String.valueOf(includeRelated))) + queryParams.put("includeRelated", String.valueOf(includeRelated)); + if(!"null".equals(String.valueOf(sourceDictionaries))) + queryParams.put("sourceDictionaries", String.valueOf(sourceDictionaries)); + if(!"null".equals(String.valueOf(useCanonical))) + queryParams.put("useCanonical", String.valueOf(useCanonical)); + if(!"null".equals(String.valueOf(includeTags))) + queryParams.put("includeTags", String.valueOf(includeTags)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (List) ApiInvoker.deserialize(response, "List", Definition.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public Example getTopExample (String word, String useCanonical) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/word.{format}/{word}/topExample".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(useCanonical))) + queryParams.put("useCanonical", String.valueOf(useCanonical)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (Example) ApiInvoker.deserialize(response, "", Example.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public List getRelatedWords (String word, String relationshipTypes, String useCanonical, Integer limitPerRelationshipType) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/word.{format}/{word}/relatedWords".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(useCanonical))) + queryParams.put("useCanonical", String.valueOf(useCanonical)); + if(!"null".equals(String.valueOf(relationshipTypes))) + queryParams.put("relationshipTypes", String.valueOf(relationshipTypes)); + if(!"null".equals(String.valueOf(limitPerRelationshipType))) + queryParams.put("limitPerRelationshipType", String.valueOf(limitPerRelationshipType)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (List) ApiInvoker.deserialize(response, "List", Related.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public List getTextPronunciations (String word, String sourceDictionary, String typeFormat, String useCanonical, Integer limit) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/word.{format}/{word}/pronunciations".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(useCanonical))) + queryParams.put("useCanonical", String.valueOf(useCanonical)); + if(!"null".equals(String.valueOf(sourceDictionary))) + queryParams.put("sourceDictionary", String.valueOf(sourceDictionary)); + if(!"null".equals(String.valueOf(typeFormat))) + queryParams.put("typeFormat", String.valueOf(typeFormat)); + if(!"null".equals(String.valueOf(limit))) + queryParams.put("limit", String.valueOf(limit)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (List) ApiInvoker.deserialize(response, "List", TextPron.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public List getHyphenation (String word, String sourceDictionary, String useCanonical, Integer limit) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/word.{format}/{word}/hyphenation".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(useCanonical))) + queryParams.put("useCanonical", String.valueOf(useCanonical)); + if(!"null".equals(String.valueOf(sourceDictionary))) + queryParams.put("sourceDictionary", String.valueOf(sourceDictionary)); + if(!"null".equals(String.valueOf(limit))) + queryParams.put("limit", String.valueOf(limit)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (List) ApiInvoker.deserialize(response, "List", Syllable.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public FrequencySummary getWordFrequency (String word, String useCanonical, Integer startYear, Integer endYear) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/word.{format}/{word}/frequency".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(useCanonical))) + queryParams.put("useCanonical", String.valueOf(useCanonical)); + if(!"null".equals(String.valueOf(startYear))) + queryParams.put("startYear", String.valueOf(startYear)); + if(!"null".equals(String.valueOf(endYear))) + queryParams.put("endYear", String.valueOf(endYear)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (FrequencySummary) ApiInvoker.deserialize(response, "", FrequencySummary.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public List getPhrases (String word, Integer limit, Integer wlmi, String useCanonical) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/word.{format}/{word}/phrases".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(limit))) + queryParams.put("limit", String.valueOf(limit)); + if(!"null".equals(String.valueOf(wlmi))) + queryParams.put("wlmi", String.valueOf(wlmi)); + if(!"null".equals(String.valueOf(useCanonical))) + queryParams.put("useCanonical", String.valueOf(useCanonical)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (List) ApiInvoker.deserialize(response, "List", Bigram.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public List getEtymologies (String word, String useCanonical) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/word.{format}/{word}/etymologies".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(useCanonical))) + queryParams.put("useCanonical", String.valueOf(useCanonical)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (List) ApiInvoker.deserialize(response, "List", String.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public List getAudio (String word, String useCanonical, Integer limit) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/word.{format}/{word}/audio".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(useCanonical))) + queryParams.put("useCanonical", String.valueOf(useCanonical)); + if(!"null".equals(String.valueOf(limit))) + queryParams.put("limit", String.valueOf(limit)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (List) ApiInvoker.deserialize(response, "List", AudioFile.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public ScrabbleScoreResult getScrabbleScore (String word) throws ApiException { + // verify required params are set + if(word == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/word.{format}/{word}/scrabbleScore".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escapeString(word.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (ScrabbleScoreResult) ApiInvoker.deserialize(response, "", ScrabbleScoreResult.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + } + diff --git a/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordListApi.java b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordListApi.java new file mode 100644 index 00000000000..3afae241b72 --- /dev/null +++ b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordListApi.java @@ -0,0 +1,231 @@ +package com.wordnik.client.api; + +import com.wordnik.client.common.ApiException; +import com.wordnik.client.common.ApiInvoker; +import com.wordnik.client.model.WordListWord; +import com.wordnik.client.model.WordList; +import com.wordnik.client.model.StringValue; +import java.util.*; + +public class WordListApi { + String basePath = "http://api.wordnik.com/v4"; + ApiInvoker apiInvoker = ApiInvoker.getInstance(); + + public void addHeader(String key, String value) { + getInvoker().addDefaultHeader(key, value); + } + + public ApiInvoker getInvoker() { + return apiInvoker; + } + + public void setBasePath(String basePath) { + this.basePath = basePath; + } + + public String getBasePath() { + return basePath; + } + + public void updateWordList (String permalink, WordList body, String auth_token) throws ApiException { + // verify required params are set + if(permalink == null || auth_token == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/wordList.{format}/{permalink}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}", apiInvoker.escapeString(permalink.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + headerParams.put("auth_token", auth_token); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "PUT", queryParams, body, headerParams, contentType); + if(response != null){ + return ; + } + else { + return ; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return ; + } + else { + throw ex; + } + } + } + public void deleteWordList (String permalink, String auth_token) throws ApiException { + // verify required params are set + if(permalink == null || auth_token == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/wordList.{format}/{permalink}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}", apiInvoker.escapeString(permalink.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + headerParams.put("auth_token", auth_token); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "DELETE", queryParams, null, headerParams, contentType); + if(response != null){ + return ; + } + else { + return ; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return ; + } + else { + throw ex; + } + } + } + public WordList getWordListByPermalink (String permalink, String auth_token) throws ApiException { + // verify required params are set + if(permalink == null || auth_token == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/wordList.{format}/{permalink}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}", apiInvoker.escapeString(permalink.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + headerParams.put("auth_token", auth_token); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (WordList) ApiInvoker.deserialize(response, "", WordList.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public void addWordsToWordList (String permalink, List body, String auth_token) throws ApiException { + // verify required params are set + if(permalink == null || auth_token == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/wordList.{format}/{permalink}/words".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}", apiInvoker.escapeString(permalink.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + headerParams.put("auth_token", auth_token); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType); + if(response != null){ + return ; + } + else { + return ; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return ; + } + else { + throw ex; + } + } + } + public List getWordListWords (String permalink, String auth_token, String sortBy, String sortOrder, Integer skip, Integer limit) throws ApiException { + // verify required params are set + if(permalink == null || auth_token == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/wordList.{format}/{permalink}/words".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}", apiInvoker.escapeString(permalink.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(sortBy))) + queryParams.put("sortBy", String.valueOf(sortBy)); + if(!"null".equals(String.valueOf(sortOrder))) + queryParams.put("sortOrder", String.valueOf(sortOrder)); + if(!"null".equals(String.valueOf(skip))) + queryParams.put("skip", String.valueOf(skip)); + if(!"null".equals(String.valueOf(limit))) + queryParams.put("limit", String.valueOf(limit)); + headerParams.put("auth_token", auth_token); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (List) ApiInvoker.deserialize(response, "List", WordListWord.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public void deleteWordsFromWordList (String permalink, List body, String auth_token) throws ApiException { + // verify required params are set + if(permalink == null || auth_token == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/wordList.{format}/{permalink}/deleteWords".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}", apiInvoker.escapeString(permalink.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + headerParams.put("auth_token", auth_token); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType); + if(response != null){ + return ; + } + else { + return ; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return ; + } + else { + throw ex; + } + } + } + } + diff --git a/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordListsApi.java b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordListsApi.java new file mode 100644 index 00000000000..1f9dae7abf5 --- /dev/null +++ b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordListsApi.java @@ -0,0 +1,61 @@ +package com.wordnik.client.api; + +import com.wordnik.client.common.ApiException; +import com.wordnik.client.common.ApiInvoker; +import com.wordnik.client.model.WordList; +import java.util.*; + +public class WordListsApi { + String basePath = "http://api.wordnik.com/v4"; + ApiInvoker apiInvoker = ApiInvoker.getInstance(); + + public void addHeader(String key, String value) { + getInvoker().addDefaultHeader(key, value); + } + + public ApiInvoker getInvoker() { + return apiInvoker; + } + + public void setBasePath(String basePath) { + this.basePath = basePath; + } + + public String getBasePath() { + return basePath; + } + + public WordList createWordList (WordList body, String auth_token) throws ApiException { + // verify required params are set + if(auth_token == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/wordLists.{format}".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + headerParams.put("auth_token", auth_token); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType); + if(response != null){ + return (WordList) ApiInvoker.deserialize(response, "", WordList.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + } + diff --git a/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordsApi.java b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordsApi.java new file mode 100644 index 00000000000..3674fb6ee3d --- /dev/null +++ b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/api/WordsApi.java @@ -0,0 +1,273 @@ +package com.wordnik.client.api; + +import com.wordnik.client.common.ApiException; +import com.wordnik.client.common.ApiInvoker; +import com.wordnik.client.model.DefinitionSearchResults; +import com.wordnik.client.model.WordObject; +import com.wordnik.client.model.WordOfTheDay; +import com.wordnik.client.model.WordSearchResults; +import java.util.*; + +public class WordsApi { + String basePath = "http://api.wordnik.com/v4"; + ApiInvoker apiInvoker = ApiInvoker.getInstance(); + + public void addHeader(String key, String value) { + getInvoker().addDefaultHeader(key, value); + } + + public ApiInvoker getInvoker() { + return apiInvoker; + } + + public void setBasePath(String basePath) { + this.basePath = basePath; + } + + public String getBasePath() { + return basePath; + } + + public WordSearchResults searchWords (String query, String includePartOfSpeech, String excludePartOfSpeech, String caseSensitive, Integer minCorpusCount, Integer maxCorpusCount, Integer minDictionaryCount, Integer maxDictionaryCount, Integer minLength, Integer maxLength, Integer skip, Integer limit) throws ApiException { + // verify required params are set + if(query == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/words.{format}/search/{query}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "query" + "\\}", apiInvoker.escapeString(query.toString())); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(caseSensitive))) + queryParams.put("caseSensitive", String.valueOf(caseSensitive)); + if(!"null".equals(String.valueOf(includePartOfSpeech))) + queryParams.put("includePartOfSpeech", String.valueOf(includePartOfSpeech)); + if(!"null".equals(String.valueOf(excludePartOfSpeech))) + queryParams.put("excludePartOfSpeech", String.valueOf(excludePartOfSpeech)); + if(!"null".equals(String.valueOf(minCorpusCount))) + queryParams.put("minCorpusCount", String.valueOf(minCorpusCount)); + if(!"null".equals(String.valueOf(maxCorpusCount))) + queryParams.put("maxCorpusCount", String.valueOf(maxCorpusCount)); + if(!"null".equals(String.valueOf(minDictionaryCount))) + queryParams.put("minDictionaryCount", String.valueOf(minDictionaryCount)); + if(!"null".equals(String.valueOf(maxDictionaryCount))) + queryParams.put("maxDictionaryCount", String.valueOf(maxDictionaryCount)); + if(!"null".equals(String.valueOf(minLength))) + queryParams.put("minLength", String.valueOf(minLength)); + if(!"null".equals(String.valueOf(maxLength))) + queryParams.put("maxLength", String.valueOf(maxLength)); + if(!"null".equals(String.valueOf(skip))) + queryParams.put("skip", String.valueOf(skip)); + if(!"null".equals(String.valueOf(limit))) + queryParams.put("limit", String.valueOf(limit)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (WordSearchResults) ApiInvoker.deserialize(response, "", WordSearchResults.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public WordOfTheDay getWordOfTheDay (String date) throws ApiException { + // create path and map variables + String path = "/words.{format}/wordOfTheDay".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(date))) + queryParams.put("date", String.valueOf(date)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (WordOfTheDay) ApiInvoker.deserialize(response, "", WordOfTheDay.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public DefinitionSearchResults reverseDictionary (String query, String findSenseForWord, String includeSourceDictionaries, String excludeSourceDictionaries, String includePartOfSpeech, String excludePartOfSpeech, String expandTerms, String sortBy, String sortOrder, Integer minCorpusCount, Integer maxCorpusCount, Integer minLength, Integer maxLength, String includeTags, String skip, Integer limit) throws ApiException { + // verify required params are set + if(query == null ) { + throw new ApiException(400, "missing required params"); + } + // create path and map variables + String path = "/words.{format}/reverseDictionary".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(query))) + queryParams.put("query", String.valueOf(query)); + if(!"null".equals(String.valueOf(findSenseForWord))) + queryParams.put("findSenseForWord", String.valueOf(findSenseForWord)); + if(!"null".equals(String.valueOf(includeSourceDictionaries))) + queryParams.put("includeSourceDictionaries", String.valueOf(includeSourceDictionaries)); + if(!"null".equals(String.valueOf(excludeSourceDictionaries))) + queryParams.put("excludeSourceDictionaries", String.valueOf(excludeSourceDictionaries)); + if(!"null".equals(String.valueOf(includePartOfSpeech))) + queryParams.put("includePartOfSpeech", String.valueOf(includePartOfSpeech)); + if(!"null".equals(String.valueOf(excludePartOfSpeech))) + queryParams.put("excludePartOfSpeech", String.valueOf(excludePartOfSpeech)); + if(!"null".equals(String.valueOf(minCorpusCount))) + queryParams.put("minCorpusCount", String.valueOf(minCorpusCount)); + if(!"null".equals(String.valueOf(maxCorpusCount))) + queryParams.put("maxCorpusCount", String.valueOf(maxCorpusCount)); + if(!"null".equals(String.valueOf(minLength))) + queryParams.put("minLength", String.valueOf(minLength)); + if(!"null".equals(String.valueOf(maxLength))) + queryParams.put("maxLength", String.valueOf(maxLength)); + if(!"null".equals(String.valueOf(expandTerms))) + queryParams.put("expandTerms", String.valueOf(expandTerms)); + if(!"null".equals(String.valueOf(includeTags))) + queryParams.put("includeTags", String.valueOf(includeTags)); + if(!"null".equals(String.valueOf(sortBy))) + queryParams.put("sortBy", String.valueOf(sortBy)); + if(!"null".equals(String.valueOf(sortOrder))) + queryParams.put("sortOrder", String.valueOf(sortOrder)); + if(!"null".equals(String.valueOf(skip))) + queryParams.put("skip", String.valueOf(skip)); + if(!"null".equals(String.valueOf(limit))) + queryParams.put("limit", String.valueOf(limit)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (DefinitionSearchResults) ApiInvoker.deserialize(response, "", DefinitionSearchResults.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public List getRandomWords (String includePartOfSpeech, String excludePartOfSpeech, String sortBy, String sortOrder, String hasDictionaryDef, Integer minCorpusCount, Integer maxCorpusCount, Integer minDictionaryCount, Integer maxDictionaryCount, Integer minLength, Integer maxLength, Integer limit) throws ApiException { + // create path and map variables + String path = "/words.{format}/randomWords".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(hasDictionaryDef))) + queryParams.put("hasDictionaryDef", String.valueOf(hasDictionaryDef)); + if(!"null".equals(String.valueOf(includePartOfSpeech))) + queryParams.put("includePartOfSpeech", String.valueOf(includePartOfSpeech)); + if(!"null".equals(String.valueOf(excludePartOfSpeech))) + queryParams.put("excludePartOfSpeech", String.valueOf(excludePartOfSpeech)); + if(!"null".equals(String.valueOf(minCorpusCount))) + queryParams.put("minCorpusCount", String.valueOf(minCorpusCount)); + if(!"null".equals(String.valueOf(maxCorpusCount))) + queryParams.put("maxCorpusCount", String.valueOf(maxCorpusCount)); + if(!"null".equals(String.valueOf(minDictionaryCount))) + queryParams.put("minDictionaryCount", String.valueOf(minDictionaryCount)); + if(!"null".equals(String.valueOf(maxDictionaryCount))) + queryParams.put("maxDictionaryCount", String.valueOf(maxDictionaryCount)); + if(!"null".equals(String.valueOf(minLength))) + queryParams.put("minLength", String.valueOf(minLength)); + if(!"null".equals(String.valueOf(maxLength))) + queryParams.put("maxLength", String.valueOf(maxLength)); + if(!"null".equals(String.valueOf(sortBy))) + queryParams.put("sortBy", String.valueOf(sortBy)); + if(!"null".equals(String.valueOf(sortOrder))) + queryParams.put("sortOrder", String.valueOf(sortOrder)); + if(!"null".equals(String.valueOf(limit))) + queryParams.put("limit", String.valueOf(limit)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (List) ApiInvoker.deserialize(response, "List", WordObject.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + public WordObject getRandomWord (String includePartOfSpeech, String excludePartOfSpeech, String hasDictionaryDef, Integer minCorpusCount, Integer maxCorpusCount, Integer minDictionaryCount, Integer maxDictionaryCount, Integer minLength, Integer maxLength) throws ApiException { + // create path and map variables + String path = "/words.{format}/randomWord".replaceAll("\\{format\\}","json"); + + // query params + Map queryParams = new HashMap(); + Map headerParams = new HashMap(); + + if(!"null".equals(String.valueOf(hasDictionaryDef))) + queryParams.put("hasDictionaryDef", String.valueOf(hasDictionaryDef)); + if(!"null".equals(String.valueOf(includePartOfSpeech))) + queryParams.put("includePartOfSpeech", String.valueOf(includePartOfSpeech)); + if(!"null".equals(String.valueOf(excludePartOfSpeech))) + queryParams.put("excludePartOfSpeech", String.valueOf(excludePartOfSpeech)); + if(!"null".equals(String.valueOf(minCorpusCount))) + queryParams.put("minCorpusCount", String.valueOf(minCorpusCount)); + if(!"null".equals(String.valueOf(maxCorpusCount))) + queryParams.put("maxCorpusCount", String.valueOf(maxCorpusCount)); + if(!"null".equals(String.valueOf(minDictionaryCount))) + queryParams.put("minDictionaryCount", String.valueOf(minDictionaryCount)); + if(!"null".equals(String.valueOf(maxDictionaryCount))) + queryParams.put("maxDictionaryCount", String.valueOf(maxDictionaryCount)); + if(!"null".equals(String.valueOf(minLength))) + queryParams.put("minLength", String.valueOf(minLength)); + if(!"null".equals(String.valueOf(maxLength))) + queryParams.put("maxLength", String.valueOf(maxLength)); + String contentType = "application/json"; + + try { + String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType); + if(response != null){ + return (WordObject) ApiInvoker.deserialize(response, "", WordObject.class); + } + else { + return null; + } + } catch (ApiException ex) { + if(ex.getCode() == 404) { + return null; + } + else { + throw ex; + } + } + } + } + diff --git a/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/common/ApiException.java b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/common/ApiException.java new file mode 100644 index 00000000000..8c96d599bb4 --- /dev/null +++ b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/common/ApiException.java @@ -0,0 +1,29 @@ +package com.wordnik.client.common; + +public class ApiException extends Exception { + int code = 0; + String message = null; + + public ApiException() {} + + public ApiException(int code, String message) { + this.code = code; + this.message = message; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/common/ApiInvoker.java b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/common/ApiInvoker.java new file mode 100644 index 00000000000..107a7aa77b8 --- /dev/null +++ b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/common/ApiInvoker.java @@ -0,0 +1,174 @@ +package com.wordnik.client.common; + + +import com.fasterxml.jackson.core.JsonGenerator.Feature; +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.annotation.*; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +import org.apache.http.*; +import org.apache.http.client.*; +import org.apache.http.client.methods.*; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.*; +import org.apache.http.util.EntityUtils; + +import java.io.File; +import java.net.URLEncoder; + +import java.util.Map; +import java.util.HashMap; +import java.util.List; +import java.io.IOException; +import java.io.UnsupportedEncodingException; + +public class ApiInvoker { + private static ApiInvoker INSTANCE = new ApiInvoker(); + private Map defaultHeaderMap = new HashMap(); + + private HttpClient client = null; + public static ApiInvoker getInstance() { + return INSTANCE; + } + + public void addDefaultHeader(String key, String value) { + defaultHeaderMap.put(key, value); + } + + public String escapeString(String str) { + return str; + } + + public static Object deserialize(String json, String containerType, Class cls) throws ApiException { + try{ + if("List".equals(containerType)) { + JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls); + List response = (List) JsonUtil.getJsonMapper().readValue(json, typeInfo); + return response; + } + else if(String.class.equals(cls)) { + if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1) + return json.substring(1, json.length() - 2); + else + return json; + } + else { + return JsonUtil.getJsonMapper().readValue(json, cls); + } + } + catch (IOException e) { + throw new ApiException(500, e.getMessage()); + } + } + + public static String serialize(Object obj) throws ApiException { + try { + if (obj != null) + return JsonUtil.getJsonMapper().writeValueAsString(obj); + else + return null; + } + catch (Exception e) { + throw new ApiException(500, e.getMessage()); + } + } + + public String invokeAPI(String host, String path, String method, Map queryParams, Object body, Map headerParams, String contentType) throws ApiException { + HttpClient client = getClient(host); + + StringBuilder b = new StringBuilder(); + for(String key : queryParams.keySet()) { + String value = queryParams.get(key); + if (value != null){ + if(b.toString().length() == 0) + b.append("?"); + else + b.append("&"); + b.append(escapeString(key)).append("=").append(escapeString(value)); + } + } + String url = host + path + b.toString(); + + HashMap headers = new HashMap(); + + for(String key : headerParams.keySet()) { + headers.put(key, headerParams.get(key)); + } + + for(String key : defaultHeaderMap.keySet()) { + if(!headerParams.containsKey(key)) { + headers.put(key, defaultHeaderMap.get(key)); + } + } + headers.put("Accept", "application/json"); + + HttpResponse response = null; + try{ + if("GET".equals(method)) { + HttpGet get = new HttpGet(url); + get.addHeader("Accept", "application/json"); + for(String key : headers.keySet()) { + get.setHeader(key, headers.get(key)); + } + response = client.execute(get); + } + else if ("POST".equals(method)) { + HttpPost post = new HttpPost(url); + post.setHeader("Content-Type", contentType); + post.setEntity(new StringEntity(serialize(body), "UTF-8")); + for(String key : headers.keySet()) { + post.setHeader(key, headers.get(key)); + } + response = client.execute(post); + } + else if ("PUT".equals(method)) { + HttpPut put = new HttpPut(url); + if(body != null) { + put.setHeader("Content-Type", contentType); + put.setEntity(new StringEntity(serialize(body), "UTF-8")); + } + for(String key : headers.keySet()) { + put.setHeader(key, headers.get(key)); + } + response = client.execute(put); + } + else if ("DELETE".equals(method)) { + HttpDelete delete = new HttpDelete(url); + for(String key : headers.keySet()) { + delete.setHeader(key, headers.get(key)); + } + response = client.execute(delete); + } + + int code = response.getStatusLine().getStatusCode(); + String responseString = null; + if(code == 204) + responseString = ""; + else if(code >= 200 && code < 300) { + if(response.getEntity() != null) { + HttpEntity resEntity = response.getEntity(); + responseString = EntityUtils.toString(resEntity); + } + } + else { + if(response.getEntity() != null) { + HttpEntity resEntity = response.getEntity(); + responseString = EntityUtils.toString(resEntity); + } + else + responseString = "no data"; + throw new ApiException(code, responseString); + } + return responseString; + } + catch(IOException e) { + throw new ApiException(500, e.getMessage()); + } + } + + private HttpClient getClient(String host) { + if(client == null) + client = new DefaultHttpClient(); + return client; + } +} diff --git a/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/common/JsonUtil.java b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/common/JsonUtil.java new file mode 100644 index 00000000000..3a3ceb7b326 --- /dev/null +++ b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/common/JsonUtil.java @@ -0,0 +1,21 @@ +package com.wordnik.client.common; + +import com.fasterxml.jackson.annotation.*; +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.core.JsonGenerator.Feature; + +public class JsonUtil { + public static ObjectMapper mapper; + + static { + mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + } + + public static ObjectMapper getJsonMapper() { + return mapper; + } +} + diff --git a/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/ApiTokenStatus.java b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/ApiTokenStatus.java new file mode 100644 index 00000000000..4f65a350537 --- /dev/null +++ b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/ApiTokenStatus.java @@ -0,0 +1,74 @@ +package com.wordnik.client.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ApiTokenStatus { + @JsonProperty("valid") + private Boolean valid = null; + @JsonProperty("token") + private String token = null; + @JsonProperty("resetsInMillis") + private Long resetsInMillis = null; + @JsonProperty("remainingCalls") + private Long remainingCalls = null; + @JsonProperty("expiresInMillis") + private Long expiresInMillis = null; + @JsonProperty("totalRequests") + private Long totalRequests = null; + public Boolean getValid() { + return valid; + } + public void setValid(Boolean valid) { + this.valid = valid; + } + + public String getToken() { + return token; + } + public void setToken(String token) { + this.token = token; + } + + public Long getResetsInMillis() { + return resetsInMillis; + } + public void setResetsInMillis(Long resetsInMillis) { + this.resetsInMillis = resetsInMillis; + } + + public Long getRemainingCalls() { + return remainingCalls; + } + public void setRemainingCalls(Long remainingCalls) { + this.remainingCalls = remainingCalls; + } + + public Long getExpiresInMillis() { + return expiresInMillis; + } + public void setExpiresInMillis(Long expiresInMillis) { + this.expiresInMillis = expiresInMillis; + } + + public Long getTotalRequests() { + return totalRequests; + } + public void setTotalRequests(Long totalRequests) { + this.totalRequests = totalRequests; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ApiTokenStatus {\n"); + sb.append(" valid: ").append(valid).append("\n"); + sb.append(" token: ").append(token).append("\n"); + sb.append(" resetsInMillis: ").append(resetsInMillis).append("\n"); + sb.append(" remainingCalls: ").append(remainingCalls).append("\n"); + sb.append(" expiresInMillis: ").append(expiresInMillis).append("\n"); + sb.append(" totalRequests: ").append(totalRequests).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} + diff --git a/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/AudioFile.java b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/AudioFile.java new file mode 100644 index 00000000000..d6d46ad2f8e --- /dev/null +++ b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/AudioFile.java @@ -0,0 +1,155 @@ +package com.wordnik.client.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Date; +public class AudioFile { + @JsonProperty("attributionUrl") + private String attributionUrl = null; + @JsonProperty("commentCount") + private Integer commentCount = null; + @JsonProperty("voteCount") + private Integer voteCount = null; + @JsonProperty("fileUrl") + private String fileUrl = null; + @JsonProperty("audioType") + private String audioType = null; + @JsonProperty("id") + private Long id = null; + @JsonProperty("duration") + private Double duration = null; + @JsonProperty("attributionText") + private String attributionText = null; + @JsonProperty("createdBy") + private String createdBy = null; + @JsonProperty("description") + private String description = null; + @JsonProperty("createdAt") + private Date createdAt = null; + @JsonProperty("voteWeightedAverage") + private Float voteWeightedAverage = null; + @JsonProperty("voteAverage") + private Float voteAverage = null; + @JsonProperty("word") + private String word = null; + public String getAttributionUrl() { + return attributionUrl; + } + public void setAttributionUrl(String attributionUrl) { + this.attributionUrl = attributionUrl; + } + + public Integer getCommentCount() { + return commentCount; + } + public void setCommentCount(Integer commentCount) { + this.commentCount = commentCount; + } + + public Integer getVoteCount() { + return voteCount; + } + public void setVoteCount(Integer voteCount) { + this.voteCount = voteCount; + } + + public String getFileUrl() { + return fileUrl; + } + public void setFileUrl(String fileUrl) { + this.fileUrl = fileUrl; + } + + public String getAudioType() { + return audioType; + } + public void setAudioType(String audioType) { + this.audioType = audioType; + } + + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + public Double getDuration() { + return duration; + } + public void setDuration(Double duration) { + this.duration = duration; + } + + public String getAttributionText() { + return attributionText; + } + public void setAttributionText(String attributionText) { + this.attributionText = attributionText; + } + + public String getCreatedBy() { + return createdBy; + } + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + public Date getCreatedAt() { + return createdAt; + } + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Float getVoteWeightedAverage() { + return voteWeightedAverage; + } + public void setVoteWeightedAverage(Float voteWeightedAverage) { + this.voteWeightedAverage = voteWeightedAverage; + } + + public Float getVoteAverage() { + return voteAverage; + } + public void setVoteAverage(Float voteAverage) { + this.voteAverage = voteAverage; + } + + public String getWord() { + return word; + } + public void setWord(String word) { + this.word = word; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class AudioFile {\n"); + sb.append(" attributionUrl: ").append(attributionUrl).append("\n"); + sb.append(" commentCount: ").append(commentCount).append("\n"); + sb.append(" voteCount: ").append(voteCount).append("\n"); + sb.append(" fileUrl: ").append(fileUrl).append("\n"); + sb.append(" audioType: ").append(audioType).append("\n"); + sb.append(" id: ").append(id).append("\n"); + sb.append(" duration: ").append(duration).append("\n"); + sb.append(" attributionText: ").append(attributionText).append("\n"); + sb.append(" createdBy: ").append(createdBy).append("\n"); + sb.append(" description: ").append(description).append("\n"); + sb.append(" createdAt: ").append(createdAt).append("\n"); + sb.append(" voteWeightedAverage: ").append(voteWeightedAverage).append("\n"); + sb.append(" voteAverage: ").append(voteAverage).append("\n"); + sb.append(" word: ").append(word).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} + diff --git a/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/AuthenticationToken.java b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/AuthenticationToken.java new file mode 100644 index 00000000000..03c6cc00dba --- /dev/null +++ b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/AuthenticationToken.java @@ -0,0 +1,44 @@ +package com.wordnik.client.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class AuthenticationToken { + @JsonProperty("token") + private String token = null; + @JsonProperty("userId") + private Long userId = null; + @JsonProperty("userSignature") + private String userSignature = null; + public String getToken() { + return token; + } + public void setToken(String token) { + this.token = token; + } + + public Long getUserId() { + return userId; + } + public void setUserId(Long userId) { + this.userId = userId; + } + + public String getUserSignature() { + return userSignature; + } + public void setUserSignature(String userSignature) { + this.userSignature = userSignature; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class AuthenticationToken {\n"); + sb.append(" token: ").append(token).append("\n"); + sb.append(" userId: ").append(userId).append("\n"); + sb.append(" userSignature: ").append(userSignature).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} + diff --git a/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Bigram.java b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Bigram.java new file mode 100644 index 00000000000..4be9f36cf56 --- /dev/null +++ b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Bigram.java @@ -0,0 +1,64 @@ +package com.wordnik.client.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Bigram { + @JsonProperty("count") + private Long count = null; + @JsonProperty("gram2") + private String gram2 = null; + @JsonProperty("gram1") + private String gram1 = null; + @JsonProperty("wlmi") + private Double wlmi = null; + @JsonProperty("mi") + private Double mi = null; + public Long getCount() { + return count; + } + public void setCount(Long count) { + this.count = count; + } + + public String getGram2() { + return gram2; + } + public void setGram2(String gram2) { + this.gram2 = gram2; + } + + public String getGram1() { + return gram1; + } + public void setGram1(String gram1) { + this.gram1 = gram1; + } + + public Double getWlmi() { + return wlmi; + } + public void setWlmi(Double wlmi) { + this.wlmi = wlmi; + } + + public Double getMi() { + return mi; + } + public void setMi(Double mi) { + this.mi = mi; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Bigram {\n"); + sb.append(" count: ").append(count).append("\n"); + sb.append(" gram2: ").append(gram2).append("\n"); + sb.append(" gram1: ").append(gram1).append("\n"); + sb.append(" wlmi: ").append(wlmi).append("\n"); + sb.append(" mi: ").append(mi).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} + diff --git a/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Citation.java b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Citation.java new file mode 100644 index 00000000000..5b2f45bc650 --- /dev/null +++ b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Citation.java @@ -0,0 +1,34 @@ +package com.wordnik.client.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Citation { + @JsonProperty("cite") + private String cite = null; + @JsonProperty("source") + private String source = null; + public String getCite() { + return cite; + } + public void setCite(String cite) { + this.cite = cite; + } + + public String getSource() { + return source; + } + public void setSource(String source) { + this.source = source; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Citation {\n"); + sb.append(" cite: ").append(cite).append("\n"); + sb.append(" source: ").append(source).append("\n"); + sb.append("}\n"); + return sb.toString(); + } +} + diff --git a/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/ContentProvider.java b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/ContentProvider.java new file mode 100644 index 00000000000..b0d994d3b0b --- /dev/null +++ b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/ContentProvider.java @@ -0,0 +1,34 @@ +package com.wordnik.client.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ContentProvider { + @JsonProperty("id") + private Integer id = null; + @JsonProperty("name") + private String name = null; + public Integer getId() { + return id; + } + public void setId(Integer 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 ContentProvider {\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/wordnik-api/android/src/main/java/com/wordnik/client/model/Definition.java b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Definition.java new file mode 100644 index 00000000000..f16273a415a --- /dev/null +++ b/samples/client/wordnik-api/android/src/main/java/com/wordnik/client/model/Definition.java @@ -0,0 +1,181 @@ +package com.wordnik.client.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.*; +import com.wordnik.client.model.Label; +import com.wordnik.client.model.ExampleUsage; +import com.wordnik.client.model.TextPron; +import com.wordnik.client.model.Citation; +import com.wordnik.client.model.Related; +import com.wordnik.client.model.Note; +public class Definition { + @JsonProperty("extendedText") + private String extendedText = null; + @JsonProperty("text") + private String text = null; + @JsonProperty("sourceDictionary") + private String sourceDictionary = null; + @JsonProperty("citations") + private List citations = new ArrayList(); + @JsonProperty("labels") + private List