updated to 1.2

This commit is contained in:
Tony Tam 2013-08-16 17:43:02 -07:00
parent 01ff7be020
commit 701d4c15a9
13 changed files with 250 additions and 103 deletions

View File

@ -11,11 +11,6 @@
</prerequisites> </prerequisites>
<pluginRepositories> <pluginRepositories>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
<pluginRepository> <pluginRepository>
<id>maven-mongodb-plugin-repo</id> <id>maven-mongodb-plugin-repo</id>
<name>maven mongodb plugin repository</name> <name>maven mongodb plugin repository</name>
@ -114,9 +109,9 @@
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.scala-tools</groupId> <groupId>net.alchim31.maven</groupId>
<artifactId>maven-scala-plugin</artifactId> <artifactId>scala-maven-plugin</artifactId>
<version>2.15.2</version> <version>${scala-maven-plugin-version}</version>
<executions> <executions>
<execution> <execution>
<id>scala-compile-first</id> <id>scala-compile-first</id>
@ -161,6 +156,12 @@
<version>${jersey-version}</version> <version>${jersey-version}</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>${jersey-version}</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>org.scala-lang</groupId> <groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId> <artifactId>scala-library</artifactId>
@ -195,5 +196,7 @@
<scala-test-version>1.6.1</scala-test-version> <scala-test-version>1.6.1</scala-test-version>
<junit-version>4.8.1</junit-version> <junit-version>4.8.1</junit-version>
<scala-test-version>1.6.1</scala-test-version> <scala-test-version>1.6.1</scala-test-version>
<scala-maven-plugin-version>3.1.5</scala-maven-plugin-version>
</properties> </properties>
</project> </project>

View File

@ -6,6 +6,10 @@ import com.sun.jersey.api.client.config.ClientConfig
import com.sun.jersey.api.client.config.DefaultClientConfig import com.sun.jersey.api.client.config.DefaultClientConfig
import com.sun.jersey.api.client.filter.LoggingFilter import com.sun.jersey.api.client.filter.LoggingFilter
import com.sun.jersey.multipart.FormDataMultiPart
import com.sun.jersey.multipart.file.FileDataBodyPart
import java.io.File
import java.net.URLEncoder import java.net.URLEncoder
import javax.ws.rs.core.MediaType import javax.ws.rs.core.MediaType
@ -50,8 +54,13 @@ object ApiInvoker {
case _ => null case _ => null
} }
} else { } else {
containerType match { containerType.toLowerCase match {
case "List" => { case "list" => {
val typeInfo = mapper.getTypeFactory().constructCollectionType(classOf[java.util.List[_]], cls)
val response = mapper.readValue(json, typeInfo).asInstanceOf[java.util.List[_]]
response.asScala.toList
}
case "array" => {
val typeInfo = mapper.getTypeFactory().constructCollectionType(classOf[java.util.List[_]], cls) val typeInfo = mapper.getTypeFactory().constructCollectionType(classOf[java.util.List[_]], cls)
val response = mapper.readValue(json, typeInfo).asInstanceOf[java.util.List[_]] val response = mapper.readValue(json, typeInfo).asInstanceOf[java.util.List[_]]
response.asScala.toList response.asScala.toList
@ -75,11 +84,11 @@ object ApiInvoker {
} else null } else null
} }
def invokeApi(host: String, path: String, method: String, queryParams: Map[String, String], body: AnyRef, headerParams: Map[String, String]) = { def invokeApi(host: String, path: String, method: String, queryParams: Map[String, String], body: AnyRef, headerParams: Map[String, String], contentType: String) = {
val client = getClient(host) val client = getClient(host)
val querystring = queryParams.filter(k => k._2 != null).map(k => (escapeString(k._1) + "=" + escapeString(k._2))).mkString("?", "&", "") val querystring = queryParams.filter(k => k._2 != null).map(k => (escapeString(k._1) + "=" + escapeString(k._2))).mkString("?", "&", "")
val builder = client.resource(host + path + querystring).`type`("application/json") val builder = client.resource(host + path + querystring).accept(contentType)
headerParams.map(p => builder.header(p._1, p._2)) headerParams.map(p => builder.header(p._1, p._2))
defaultHeaders.map(p => { defaultHeaders.map(p => {
@ -94,10 +103,21 @@ object ApiInvoker {
builder.get(classOf[ClientResponse]).asInstanceOf[ClientResponse] builder.get(classOf[ClientResponse]).asInstanceOf[ClientResponse]
} }
case "POST" => { case "POST" => {
builder.post(classOf[ClientResponse], serialize(body)) if(body != null && body.isInstanceOf[File]) {
val file = body.asInstanceOf[File]
val form = new FormDataMultiPart()
form.field("filename", file.getName())
form.bodyPart(new FileDataBodyPart("file", file, MediaType.MULTIPART_FORM_DATA_TYPE))
builder.post(classOf[ClientResponse], form)
}
else {
if(body == null) builder.post(classOf[ClientResponse], serialize(body))
else builder.`type`(contentType).post(classOf[ClientResponse], serialize(body))
}
} }
case "PUT" => { case "PUT" => {
builder.put(classOf[ClientResponse], serialize(body)) if(body == null) builder.put(classOf[ClientResponse], null)
else builder.`type`(contentType).put(classOf[ClientResponse], serialize(body))
} }
case "DELETE" => { case "DELETE" => {
builder.delete(classOf[ClientResponse]) builder.delete(classOf[ClientResponse])
@ -135,3 +155,4 @@ class ApiException extends Exception {
} }
} }

View File

@ -3,6 +3,9 @@ package com.wordnik.petstore.api
import com.wordnik.petstore.model.Pet import com.wordnik.petstore.model.Pet
import com.wordnik.client.ApiInvoker import com.wordnik.client.ApiInvoker
import com.wordnik.client.ApiException import com.wordnik.client.ApiException
import java.io.File
import scala.collection.mutable.HashMap import scala.collection.mutable.HashMap
class PetApi { class PetApi {
@ -13,7 +16,11 @@ class PetApi {
def getPetById (petId: String) : Option[Pet]= { def getPetById (petId: String) : Option[Pet]= {
// create path and map variables // create path and map variables
val path = "/pet.{format}/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}",apiInvoker.escapeString(petId)) val path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}",apiInvoker.escapeString(petId))
val contentType = {
"application/json"}
// query params // query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
@ -25,7 +32,7 @@ class PetApi {
case _ => throw new Exception("missing required params") case _ => throw new Exception("missing required params")
} }
try { try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
case s: String => case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[Pet]).asInstanceOf[Pet]) Some(ApiInvoker.deserialize(s, "", classOf[Pet]).asInstanceOf[Pet])
case _ => None case _ => None
@ -35,9 +42,43 @@ class PetApi {
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
def deletePet (petId: String) = {
// create path and map variables
val path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}",apiInvoker.escapeString(petId))
val contentType = {
"application/json"}
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(petId) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
try {
apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, None, headerParams.toMap, contentType) match {
case s: String =>
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def addPet (body: Pet) = { def addPet (body: Pet) = {
// create path and map variables // create path and map variables
val path = "/pet.{format}".replaceAll("\\{format\\}","json")// query params val path = "/pet".replaceAll("\\{format\\}","json")
val contentType = {
if(body != null && body.isInstanceOf[File] )
"multipart/form-data"
else "application/json"
}
// query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
@ -47,7 +88,7 @@ class PetApi {
case _ => throw new Exception("missing required params") case _ => throw new Exception("missing required params")
} }
try { try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, body, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, body, headerParams.toMap, contentType) match {
case s: String => case s: String =>
case _ => None case _ => None
} }
@ -58,7 +99,14 @@ class PetApi {
} }
def updatePet (body: Pet) = { def updatePet (body: Pet) = {
// create path and map variables // create path and map variables
val path = "/pet.{format}".replaceAll("\\{format\\}","json")// query params val path = "/pet".replaceAll("\\{format\\}","json")
val contentType = {
if(body != null && body.isInstanceOf[File] )
"multipart/form-data"
else "application/json"
}
// query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
@ -68,7 +116,7 @@ class PetApi {
case _ => throw new Exception("missing required params") case _ => throw new Exception("missing required params")
} }
try { try {
apiInvoker.invokeApi(basePath, path, "PUT", queryParams.toMap, body, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "PUT", queryParams.toMap, body, headerParams.toMap, contentType) match {
case s: String => case s: String =>
case _ => None case _ => None
} }
@ -79,7 +127,11 @@ class PetApi {
} }
def findPetsByStatus (status: String= "available") : Option[List[Pet]]= { def findPetsByStatus (status: String= "available") : Option[List[Pet]]= {
// create path and map variables // create path and map variables
val path = "/pet.{format}/findByStatus".replaceAll("\\{format\\}","json")// query params val path = "/pet/findByStatus".replaceAll("\\{format\\}","json")
val contentType = {
"application/json"}
// query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
@ -90,9 +142,9 @@ class PetApi {
} }
if(String.valueOf(status) != "null") queryParams += "status" -> status.toString if(String.valueOf(status) != "null") queryParams += "status" -> status.toString
try { try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
case s: String => case s: String =>
Some(ApiInvoker.deserialize(s, "List", classOf[Pet]).asInstanceOf[List[Pet]]) Some(ApiInvoker.deserialize(s, "array", classOf[Pet]).asInstanceOf[List[Pet]])
case _ => None case _ => None
} }
} catch { } catch {
@ -102,7 +154,11 @@ class PetApi {
} }
def findPetsByTags (tags: String) : Option[List[Pet]]= { def findPetsByTags (tags: String) : Option[List[Pet]]= {
// create path and map variables // create path and map variables
val path = "/pet.{format}/findByTags".replaceAll("\\{format\\}","json")// query params val path = "/pet/findByTags".replaceAll("\\{format\\}","json")
val contentType = {
"application/json"}
// query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
@ -113,9 +169,9 @@ class PetApi {
} }
if(String.valueOf(tags) != "null") queryParams += "tags" -> tags.toString if(String.valueOf(tags) != "null") queryParams += "tags" -> tags.toString
try { try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
case s: String => case s: String =>
Some(ApiInvoker.deserialize(s, "List", classOf[Pet]).asInstanceOf[List[Pet]]) Some(ApiInvoker.deserialize(s, "array", classOf[Pet]).asInstanceOf[List[Pet]])
case _ => None case _ => None
} }
} catch { } catch {

View File

@ -3,6 +3,9 @@ package com.wordnik.petstore.api
import com.wordnik.petstore.model.Order import com.wordnik.petstore.model.Order
import com.wordnik.client.ApiInvoker import com.wordnik.client.ApiInvoker
import com.wordnik.client.ApiException import com.wordnik.client.ApiException
import java.io.File
import scala.collection.mutable.HashMap import scala.collection.mutable.HashMap
class StoreApi { class StoreApi {
@ -13,7 +16,11 @@ class StoreApi {
def getOrderById (orderId: String) : Option[Order]= { def getOrderById (orderId: String) : Option[Order]= {
// create path and map variables // create path and map variables
val path = "/store.{format}/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}",apiInvoker.escapeString(orderId)) val path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}",apiInvoker.escapeString(orderId))
val contentType = {
"application/json"}
// query params // query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
@ -25,7 +32,7 @@ class StoreApi {
case _ => throw new Exception("missing required params") case _ => throw new Exception("missing required params")
} }
try { try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
case s: String => case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[Order]).asInstanceOf[Order]) Some(ApiInvoker.deserialize(s, "", classOf[Order]).asInstanceOf[Order])
case _ => None case _ => None
@ -37,7 +44,11 @@ class StoreApi {
} }
def deleteOrder (orderId: String) = { def deleteOrder (orderId: String) = {
// create path and map variables // create path and map variables
val path = "/store.{format}/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}",apiInvoker.escapeString(orderId)) val path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}",apiInvoker.escapeString(orderId))
val contentType = {
"application/json"}
// query params // query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
@ -49,7 +60,7 @@ class StoreApi {
case _ => throw new Exception("missing required params") case _ => throw new Exception("missing required params")
} }
try { try {
apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, None, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, None, headerParams.toMap, contentType) match {
case s: String => case s: String =>
case _ => None case _ => None
} }
@ -60,7 +71,14 @@ class StoreApi {
} }
def placeOrder (body: Order) = { def placeOrder (body: Order) = {
// create path and map variables // create path and map variables
val path = "/store.{format}/order".replaceAll("\\{format\\}","json")// query params val path = "/store/order".replaceAll("\\{format\\}","json")
val contentType = {
if(body != null && body.isInstanceOf[File] )
"multipart/form-data"
else "application/json"
}
// query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
@ -70,7 +88,7 @@ class StoreApi {
case _ => throw new Exception("missing required params") case _ => throw new Exception("missing required params")
} }
try { try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, body, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, body, headerParams.toMap, contentType) match {
case s: String => case s: String =>
case _ => None case _ => None
} }

View File

@ -3,6 +3,9 @@ package com.wordnik.petstore.api
import com.wordnik.petstore.model.User import com.wordnik.petstore.model.User
import com.wordnik.client.ApiInvoker import com.wordnik.client.ApiInvoker
import com.wordnik.client.ApiException import com.wordnik.client.ApiException
import java.io.File
import scala.collection.mutable.HashMap import scala.collection.mutable.HashMap
class UserApi { class UserApi {
@ -11,9 +14,16 @@ class UserApi {
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
def createUsersWithArrayInput (body: Array[User]) = { def createUser (body: User) = {
// create path and map variables // create path and map variables
val path = "/user.{format}/createWithArray".replaceAll("\\{format\\}","json")// query params val path = "/user".replaceAll("\\{format\\}","json")
val contentType = {
if(body != null && body.isInstanceOf[File] )
"multipart/form-data"
else "application/json"
}
// query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
@ -23,7 +33,7 @@ class UserApi {
case _ => throw new Exception("missing required params") case _ => throw new Exception("missing required params")
} }
try { try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, body, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, body, headerParams.toMap, contentType) match {
case s: String => case s: String =>
case _ => None case _ => None
} }
@ -32,9 +42,16 @@ class UserApi {
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
def createUser (body: User) = { def createUsersWithArrayInput (body: List[User]) = {
// create path and map variables // create path and map variables
val path = "/user.{format}".replaceAll("\\{format\\}","json")// query params val path = "/user/createWithArray".replaceAll("\\{format\\}","json")
val contentType = {
if(body != null && body.isInstanceOf[File] )
"multipart/form-data"
else "application/json"
}
// query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
@ -44,7 +61,7 @@ class UserApi {
case _ => throw new Exception("missing required params") case _ => throw new Exception("missing required params")
} }
try { try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, body, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, body, headerParams.toMap, contentType) match {
case s: String => case s: String =>
case _ => None case _ => None
} }
@ -55,7 +72,14 @@ class UserApi {
} }
def createUsersWithListInput (body: List[User]) = { def createUsersWithListInput (body: List[User]) = {
// create path and map variables // create path and map variables
val path = "/user.{format}/createWithList".replaceAll("\\{format\\}","json")// query params val path = "/user/createWithList".replaceAll("\\{format\\}","json")
val contentType = {
if(body != null && body.isInstanceOf[File] )
"multipart/form-data"
else "application/json"
}
// query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
@ -65,7 +89,7 @@ class UserApi {
case _ => throw new Exception("missing required params") case _ => throw new Exception("missing required params")
} }
try { try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, body, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, body, headerParams.toMap, contentType) match {
case s: String => case s: String =>
case _ => None case _ => None
} }
@ -76,7 +100,14 @@ class UserApi {
} }
def updateUser (username: String, body: User) = { def updateUser (username: String, body: User) = {
// create path and map variables // create path and map variables
val path = "/user.{format}/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}",apiInvoker.escapeString(username)) val path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}",apiInvoker.escapeString(username))
val contentType = {
if(body != null && body.isInstanceOf[File] )
"multipart/form-data"
else "application/json"
}
// query params // query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
@ -88,7 +119,7 @@ class UserApi {
case _ => throw new Exception("missing required params") case _ => throw new Exception("missing required params")
} }
try { try {
apiInvoker.invokeApi(basePath, path, "PUT", queryParams.toMap, body, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "PUT", queryParams.toMap, body, headerParams.toMap, contentType) match {
case s: String => case s: String =>
case _ => None case _ => None
} }
@ -99,7 +130,11 @@ class UserApi {
} }
def deleteUser (username: String) = { def deleteUser (username: String) = {
// create path and map variables // create path and map variables
val path = "/user.{format}/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}",apiInvoker.escapeString(username)) val path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}",apiInvoker.escapeString(username))
val contentType = {
"application/json"}
// query params // query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
@ -111,7 +146,7 @@ class UserApi {
case _ => throw new Exception("missing required params") case _ => throw new Exception("missing required params")
} }
try { try {
apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, None, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, None, headerParams.toMap, contentType) match {
case s: String => case s: String =>
case _ => None case _ => None
} }
@ -122,7 +157,11 @@ class UserApi {
} }
def getUserByName (username: String) : Option[User]= { def getUserByName (username: String) : Option[User]= {
// create path and map variables // create path and map variables
val path = "/user.{format}/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}",apiInvoker.escapeString(username)) val path = "/user/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}",apiInvoker.escapeString(username))
val contentType = {
"application/json"}
// query params // query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
@ -134,7 +173,7 @@ class UserApi {
case _ => throw new Exception("missing required params") case _ => throw new Exception("missing required params")
} }
try { try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
case s: String => case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[User]).asInstanceOf[User]) Some(ApiInvoker.deserialize(s, "", classOf[User]).asInstanceOf[User])
case _ => None case _ => None
@ -146,7 +185,11 @@ class UserApi {
} }
def loginUser (username: String, password: String) : Option[String]= { def loginUser (username: String, password: String) : Option[String]= {
// create path and map variables // create path and map variables
val path = "/user.{format}/login".replaceAll("\\{format\\}","json")// query params val path = "/user/login".replaceAll("\\{format\\}","json")
val contentType = {
"application/json"}
// query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
@ -158,7 +201,7 @@ class UserApi {
if(String.valueOf(username) != "null") queryParams += "username" -> username.toString if(String.valueOf(username) != "null") queryParams += "username" -> username.toString
if(String.valueOf(password) != "null") queryParams += "password" -> password.toString if(String.valueOf(password) != "null") queryParams += "password" -> password.toString
try { try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
case s: String => case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[String]).asInstanceOf[String]) Some(ApiInvoker.deserialize(s, "", classOf[String]).asInstanceOf[String])
case _ => None case _ => None
@ -170,12 +213,16 @@ class UserApi {
} }
def logoutUser () = { def logoutUser () = {
// create path and map variables // create path and map variables
val path = "/user.{format}/logout".replaceAll("\\{format\\}","json")// query params val path = "/user/logout".replaceAll("\\{format\\}","json")
val contentType = {
"application/json"}
// query params
val queryParams = new HashMap[String, String] val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
try { try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match { apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
case s: String => case s: String =>
case _ => None case _ => None
} }

View File

@ -1,6 +1,6 @@
package com.wordnik.petstore.model package com.wordnik.petstore.model
case class Category ( case class Category (
id: Long, name: String,
name: String) id: Long)

View File

@ -3,9 +3,9 @@ package com.wordnik.petstore.model
import java.util.Date import java.util.Date
case class Order ( case class Order (
id: Long, id: Long,
petId: Long,
/* Order Status */ /* Order Status */
status: String, status: String,
petId: Long,
quantity: Int, quantity: Int,
shipDate: Date) shipDate: Date)

View File

@ -3,11 +3,11 @@ package com.wordnik.petstore.model
import com.wordnik.petstore.model.Category import com.wordnik.petstore.model.Category
import com.wordnik.petstore.model.Tag import com.wordnik.petstore.model.Tag
case class Pet ( case class Pet (
tags: List[Tag], name: String,
id: Long, id: Long,
category: Category, tags: List[Tag],
/* pet status in the store */ /* pet status in the store */
status: String, status: String,
name: String, photoUrls: List[String],
photoUrls: List[String]) category: Category)

View File

@ -1,6 +1,6 @@
package com.wordnik.petstore.model package com.wordnik.petstore.model
case class Tag ( case class Tag (
id: Long, name: String,
name: String) id: Long)

View File

@ -2,12 +2,12 @@ package com.wordnik.petstore.model
case class User ( case class User (
id: Long, id: Long,
lastName: String,
phone: String,
username: String,
email: String,
/* User Status */
userStatus: Int,
firstName: String, firstName: String,
password: String) username: String,
lastName: String,
email: String,
password: String,
phone: String,
/* User Status */
userStatus: Int)

View File

@ -27,12 +27,13 @@ class PetApiTest extends FlatSpec with ShouldMatchers {
it should "add a new pet" in { it should "add a new pet" in {
val pet = Pet( val pet = Pet(
(for (i <- (1 to 5)) yield Tag(i, "tag-" + i)).toList,
1000,
Category(1, "sold"),
"lost",
"dragon", "dragon",
(for (i <- (1 to 10)) yield "http://foo.com/photo/" + i).toList) 1000,
(for (i <- (1 to 5)) yield Tag("tag-" + i, i)).toList,
"lost",
(for (i <- (1 to 10)) yield "http://foo.com/photo/" + i).toList,
Category("sold", 1)
)
api.addPet(pet) api.addPet(pet)
api.getPetById("1000") match { api.getPetById("1000") match {
@ -51,12 +52,13 @@ class PetApiTest extends FlatSpec with ShouldMatchers {
it should "update a pet" in { it should "update a pet" in {
val pet = Pet( val pet = Pet(
(for (i <- (1 to 5)) yield Tag(i, "tag-" + i)).toList,
1000,
Category(1, "sold"),
"confused",
"programmer", "programmer",
(for (i <- (1 to 10)) yield "http://foo.com/photo/" + i).toList) 1000,
(for (i <- (1 to 5)) yield Tag("tag-" + i, i)).toList,
"confused",
(for (i <- (1 to 10)) yield "http://foo.com/photo/" + i).toList,
Category("sold", 1)
)
api.addPet(pet) api.addPet(pet)

View File

@ -34,8 +34,8 @@ class StoreApiTest extends FlatSpec with ShouldMatchers {
val now = new java.util.Date val now = new java.util.Date
val order = Order ( val order = Order (
1000, 1000,
10,
"pending", "pending",
10,
101, 101,
now) now)
@ -56,8 +56,8 @@ class StoreApiTest extends FlatSpec with ShouldMatchers {
val now = new java.util.Date val now = new java.util.Date
val order = Order( val order = Order(
1001, 1001,
10,
"pending", "pending",
10,
101, 101,
now) now)

View File

@ -49,13 +49,13 @@ class UserApiTest extends FlatSpec with ShouldMatchers {
it should "create a user" in { it should "create a user" in {
val user = User( val user = User(
1002, 1002,
"Rocket",
"408-867-5309",
"johnny",
"johnny@fail.com",
1,
"Johnny", "Johnny",
"XXXXXXXXXXX") "johnny",
"Rocket",
"johnny@fail.com",
"XXXXXXXXXXX",
"408-867-5309",
1)
api.createUser(user) api.createUser(user)
@ -72,14 +72,14 @@ class UserApiTest extends FlatSpec with ShouldMatchers {
val userArray = (for (i <- (1 to 2)) yield { val userArray = (for (i <- (1 to 2)) yield {
User( User(
2000 + i, 2000 + i,
"Rocket-" + i,
"408-867-5309",
"johnny-" + i,
"johnny-" + i + "@fail.com",
1,
"Johnny", "Johnny",
"XXXXXXXXXXX") "johnny-" + i,
}).toArray "Rocket-" + i,
"johnny-" + i + "@fail.com",
"XXXXXXXXXXX",
"408-867-5309",
1)
}).toList
api.createUsersWithArrayInput(userArray) api.createUsersWithArrayInput(userArray)
for (i <- (1 to 2)) { for (i <- (1 to 2)) {
@ -97,13 +97,13 @@ class UserApiTest extends FlatSpec with ShouldMatchers {
val userList = (for (i <- (1 to 3)) yield { val userList = (for (i <- (1 to 3)) yield {
User( User(
3000 + i, 3000 + i,
"Rocket-" + i,
"408-867-5309",
"fred-" + i,
"fred-" + i + "@fail.com",
1,
"Johnny", "Johnny",
"XXXXXXXXXXX") "fred-" + i,
"Rocket-" + i,
"fred-" + i + "@fail.com",
"XXXXXXXXXXX",
"408-867-5309",
1)
}).toList }).toList
api.createUsersWithListInput(userList) api.createUsersWithListInput(userList)
@ -121,13 +121,13 @@ class UserApiTest extends FlatSpec with ShouldMatchers {
it should "update a user" in { it should "update a user" in {
val user = User( val user = User(
4000, 4000,
"Tiger",
"408-867-5309",
"tony",
"tony@fail.com",
1,
"Tony", "Tony",
"XXXXXXXXXXX") "tony",
"Tiger",
"tony@fail.com",
"XXXXXXXXXXX",
"408-867-5309",
1)
api.createUser(user) api.createUser(user)