forked from loafle/openapi-generator-original
updated to 1.2
This commit is contained in:
parent
01ff7be020
commit
701d4c15a9
@ -11,11 +11,6 @@
|
||||
</prerequisites>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>scala-tools.org</id>
|
||||
<name>Scala-Tools Maven2 Repository</name>
|
||||
<url>http://scala-tools.org/repo-releases</url>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>maven-mongodb-plugin-repo</id>
|
||||
<name>maven mongodb plugin repository</name>
|
||||
@ -114,9 +109,9 @@
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.scala-tools</groupId>
|
||||
<artifactId>maven-scala-plugin</artifactId>
|
||||
<version>2.15.2</version>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<version>${scala-maven-plugin-version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>scala-compile-first</id>
|
||||
@ -161,6 +156,12 @@
|
||||
<version>${jersey-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.jersey.contribs</groupId>
|
||||
<artifactId>jersey-multipart</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.scala-lang</groupId>
|
||||
<artifactId>scala-library</artifactId>
|
||||
@ -195,5 +196,7 @@
|
||||
<scala-test-version>1.6.1</scala-test-version>
|
||||
<junit-version>4.8.1</junit-version>
|
||||
<scala-test-version>1.6.1</scala-test-version>
|
||||
<scala-maven-plugin-version>3.1.5</scala-maven-plugin-version>
|
||||
</properties>
|
||||
</project>
|
||||
|
||||
|
@ -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.filter.LoggingFilter
|
||||
|
||||
import com.sun.jersey.multipart.FormDataMultiPart
|
||||
import com.sun.jersey.multipart.file.FileDataBodyPart
|
||||
|
||||
import java.io.File
|
||||
import java.net.URLEncoder
|
||||
import javax.ws.rs.core.MediaType
|
||||
|
||||
@ -50,8 +54,13 @@ object ApiInvoker {
|
||||
case _ => null
|
||||
}
|
||||
} else {
|
||||
containerType match {
|
||||
case "List" => {
|
||||
containerType.toLowerCase match {
|
||||
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 response = mapper.readValue(json, typeInfo).asInstanceOf[java.util.List[_]]
|
||||
response.asScala.toList
|
||||
@ -75,11 +84,11 @@ object ApiInvoker {
|
||||
} 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 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))
|
||||
defaultHeaders.map(p => {
|
||||
@ -94,10 +103,21 @@ object ApiInvoker {
|
||||
builder.get(classOf[ClientResponse]).asInstanceOf[ClientResponse]
|
||||
}
|
||||
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" => {
|
||||
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" => {
|
||||
builder.delete(classOf[ClientResponse])
|
||||
@ -135,3 +155,4 @@ class ApiException extends Exception {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,6 +3,9 @@ package com.wordnik.petstore.api
|
||||
import com.wordnik.petstore.model.Pet
|
||||
import com.wordnik.client.ApiInvoker
|
||||
import com.wordnik.client.ApiException
|
||||
|
||||
import java.io.File
|
||||
|
||||
import scala.collection.mutable.HashMap
|
||||
|
||||
class PetApi {
|
||||
@ -13,7 +16,11 @@ class PetApi {
|
||||
|
||||
def getPetById (petId: String) : Option[Pet]= {
|
||||
// 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
|
||||
val queryParams = new HashMap[String, String]
|
||||
@ -25,7 +32,7 @@ class PetApi {
|
||||
case _ => throw new Exception("missing required params")
|
||||
}
|
||||
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 =>
|
||||
Some(ApiInvoker.deserialize(s, "", classOf[Pet]).asInstanceOf[Pet])
|
||||
case _ => None
|
||||
@ -35,9 +42,43 @@ class PetApi {
|
||||
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) = {
|
||||
// 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 headerParams = new HashMap[String, String]
|
||||
|
||||
@ -47,7 +88,7 @@ class PetApi {
|
||||
case _ => throw new Exception("missing required params")
|
||||
}
|
||||
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 _ => None
|
||||
}
|
||||
@ -58,7 +99,14 @@ class PetApi {
|
||||
}
|
||||
def updatePet (body: Pet) = {
|
||||
// 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 headerParams = new HashMap[String, String]
|
||||
|
||||
@ -68,7 +116,7 @@ class PetApi {
|
||||
case _ => throw new Exception("missing required params")
|
||||
}
|
||||
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 _ => None
|
||||
}
|
||||
@ -79,7 +127,11 @@ class PetApi {
|
||||
}
|
||||
def findPetsByStatus (status: String= "available") : Option[List[Pet]]= {
|
||||
// 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 headerParams = new HashMap[String, String]
|
||||
|
||||
@ -90,9 +142,9 @@ class PetApi {
|
||||
}
|
||||
if(String.valueOf(status) != "null") queryParams += "status" -> status.toString
|
||||
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 =>
|
||||
Some(ApiInvoker.deserialize(s, "List", classOf[Pet]).asInstanceOf[List[Pet]])
|
||||
Some(ApiInvoker.deserialize(s, "array", classOf[Pet]).asInstanceOf[List[Pet]])
|
||||
case _ => None
|
||||
}
|
||||
} catch {
|
||||
@ -102,7 +154,11 @@ class PetApi {
|
||||
}
|
||||
def findPetsByTags (tags: String) : Option[List[Pet]]= {
|
||||
// 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 headerParams = new HashMap[String, String]
|
||||
|
||||
@ -113,9 +169,9 @@ class PetApi {
|
||||
}
|
||||
if(String.valueOf(tags) != "null") queryParams += "tags" -> tags.toString
|
||||
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 =>
|
||||
Some(ApiInvoker.deserialize(s, "List", classOf[Pet]).asInstanceOf[List[Pet]])
|
||||
Some(ApiInvoker.deserialize(s, "array", classOf[Pet]).asInstanceOf[List[Pet]])
|
||||
case _ => None
|
||||
}
|
||||
} catch {
|
||||
|
@ -3,6 +3,9 @@ package com.wordnik.petstore.api
|
||||
import com.wordnik.petstore.model.Order
|
||||
import com.wordnik.client.ApiInvoker
|
||||
import com.wordnik.client.ApiException
|
||||
|
||||
import java.io.File
|
||||
|
||||
import scala.collection.mutable.HashMap
|
||||
|
||||
class StoreApi {
|
||||
@ -13,7 +16,11 @@ class StoreApi {
|
||||
|
||||
def getOrderById (orderId: String) : Option[Order]= {
|
||||
// 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
|
||||
val queryParams = new HashMap[String, String]
|
||||
@ -25,7 +32,7 @@ class StoreApi {
|
||||
case _ => throw new Exception("missing required params")
|
||||
}
|
||||
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 =>
|
||||
Some(ApiInvoker.deserialize(s, "", classOf[Order]).asInstanceOf[Order])
|
||||
case _ => None
|
||||
@ -37,7 +44,11 @@ class StoreApi {
|
||||
}
|
||||
def deleteOrder (orderId: String) = {
|
||||
// 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
|
||||
val queryParams = new HashMap[String, String]
|
||||
@ -49,7 +60,7 @@ class StoreApi {
|
||||
case _ => throw new Exception("missing required params")
|
||||
}
|
||||
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 _ => None
|
||||
}
|
||||
@ -60,7 +71,14 @@ class StoreApi {
|
||||
}
|
||||
def placeOrder (body: Order) = {
|
||||
// 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 headerParams = new HashMap[String, String]
|
||||
|
||||
@ -70,7 +88,7 @@ class StoreApi {
|
||||
case _ => throw new Exception("missing required params")
|
||||
}
|
||||
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 _ => None
|
||||
}
|
||||
|
@ -3,6 +3,9 @@ package com.wordnik.petstore.api
|
||||
import com.wordnik.petstore.model.User
|
||||
import com.wordnik.client.ApiInvoker
|
||||
import com.wordnik.client.ApiException
|
||||
|
||||
import java.io.File
|
||||
|
||||
import scala.collection.mutable.HashMap
|
||||
|
||||
class UserApi {
|
||||
@ -11,9 +14,16 @@ class UserApi {
|
||||
|
||||
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
||||
|
||||
def createUsersWithArrayInput (body: Array[User]) = {
|
||||
def createUser (body: User) = {
|
||||
// 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 headerParams = new HashMap[String, String]
|
||||
|
||||
@ -23,7 +33,7 @@ class UserApi {
|
||||
case _ => throw new Exception("missing required params")
|
||||
}
|
||||
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 _ => None
|
||||
}
|
||||
@ -32,9 +42,16 @@ class UserApi {
|
||||
case ex: ApiException => throw ex
|
||||
}
|
||||
}
|
||||
def createUser (body: User) = {
|
||||
def createUsersWithArrayInput (body: List[User]) = {
|
||||
// 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 headerParams = new HashMap[String, String]
|
||||
|
||||
@ -44,7 +61,7 @@ class UserApi {
|
||||
case _ => throw new Exception("missing required params")
|
||||
}
|
||||
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 _ => None
|
||||
}
|
||||
@ -55,7 +72,14 @@ class UserApi {
|
||||
}
|
||||
def createUsersWithListInput (body: List[User]) = {
|
||||
// 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 headerParams = new HashMap[String, String]
|
||||
|
||||
@ -65,7 +89,7 @@ class UserApi {
|
||||
case _ => throw new Exception("missing required params")
|
||||
}
|
||||
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 _ => None
|
||||
}
|
||||
@ -76,7 +100,14 @@ class UserApi {
|
||||
}
|
||||
def updateUser (username: String, body: User) = {
|
||||
// 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
|
||||
val queryParams = new HashMap[String, String]
|
||||
@ -88,7 +119,7 @@ class UserApi {
|
||||
case _ => throw new Exception("missing required params")
|
||||
}
|
||||
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 _ => None
|
||||
}
|
||||
@ -99,7 +130,11 @@ class UserApi {
|
||||
}
|
||||
def deleteUser (username: String) = {
|
||||
// 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
|
||||
val queryParams = new HashMap[String, String]
|
||||
@ -111,7 +146,7 @@ class UserApi {
|
||||
case _ => throw new Exception("missing required params")
|
||||
}
|
||||
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 _ => None
|
||||
}
|
||||
@ -122,7 +157,11 @@ class UserApi {
|
||||
}
|
||||
def getUserByName (username: String) : Option[User]= {
|
||||
// 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
|
||||
val queryParams = new HashMap[String, String]
|
||||
@ -134,7 +173,7 @@ class UserApi {
|
||||
case _ => throw new Exception("missing required params")
|
||||
}
|
||||
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 =>
|
||||
Some(ApiInvoker.deserialize(s, "", classOf[User]).asInstanceOf[User])
|
||||
case _ => None
|
||||
@ -146,7 +185,11 @@ class UserApi {
|
||||
}
|
||||
def loginUser (username: String, password: String) : Option[String]= {
|
||||
// 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 headerParams = new HashMap[String, String]
|
||||
|
||||
@ -158,7 +201,7 @@ class UserApi {
|
||||
if(String.valueOf(username) != "null") queryParams += "username" -> username.toString
|
||||
if(String.valueOf(password) != "null") queryParams += "password" -> password.toString
|
||||
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 =>
|
||||
Some(ApiInvoker.deserialize(s, "", classOf[String]).asInstanceOf[String])
|
||||
case _ => None
|
||||
@ -170,12 +213,16 @@ class UserApi {
|
||||
}
|
||||
def logoutUser () = {
|
||||
// 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 headerParams = new HashMap[String, String]
|
||||
|
||||
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 _ => None
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.wordnik.petstore.model
|
||||
|
||||
case class Category (
|
||||
id: Long,
|
||||
name: String)
|
||||
name: String,
|
||||
id: Long)
|
||||
|
||||
|
@ -3,9 +3,9 @@ package com.wordnik.petstore.model
|
||||
import java.util.Date
|
||||
case class Order (
|
||||
id: Long,
|
||||
petId: Long,
|
||||
/* Order Status */
|
||||
status: String,
|
||||
petId: Long,
|
||||
quantity: Int,
|
||||
shipDate: Date)
|
||||
|
||||
|
@ -3,11 +3,11 @@ package com.wordnik.petstore.model
|
||||
import com.wordnik.petstore.model.Category
|
||||
import com.wordnik.petstore.model.Tag
|
||||
case class Pet (
|
||||
tags: List[Tag],
|
||||
name: String,
|
||||
id: Long,
|
||||
category: Category,
|
||||
tags: List[Tag],
|
||||
/* pet status in the store */
|
||||
status: String,
|
||||
name: String,
|
||||
photoUrls: List[String])
|
||||
photoUrls: List[String],
|
||||
category: Category)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.wordnik.petstore.model
|
||||
|
||||
case class Tag (
|
||||
id: Long,
|
||||
name: String)
|
||||
name: String,
|
||||
id: Long)
|
||||
|
||||
|
@ -2,12 +2,12 @@ package com.wordnik.petstore.model
|
||||
|
||||
case class User (
|
||||
id: Long,
|
||||
lastName: String,
|
||||
phone: String,
|
||||
username: String,
|
||||
email: String,
|
||||
/* User Status */
|
||||
userStatus: Int,
|
||||
firstName: String,
|
||||
password: String)
|
||||
username: String,
|
||||
lastName: String,
|
||||
email: String,
|
||||
password: String,
|
||||
phone: String,
|
||||
/* User Status */
|
||||
userStatus: Int)
|
||||
|
||||
|
@ -27,12 +27,13 @@ class PetApiTest extends FlatSpec with ShouldMatchers {
|
||||
|
||||
it should "add a new pet" in {
|
||||
val pet = Pet(
|
||||
(for (i <- (1 to 5)) yield Tag(i, "tag-" + i)).toList,
|
||||
1000,
|
||||
Category(1, "sold"),
|
||||
"lost",
|
||||
"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.getPetById("1000") match {
|
||||
@ -51,12 +52,13 @@ class PetApiTest extends FlatSpec with ShouldMatchers {
|
||||
|
||||
it should "update a pet" in {
|
||||
val pet = Pet(
|
||||
(for (i <- (1 to 5)) yield Tag(i, "tag-" + i)).toList,
|
||||
1000,
|
||||
Category(1, "sold"),
|
||||
"confused",
|
||||
"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)
|
||||
|
||||
|
@ -34,8 +34,8 @@ class StoreApiTest extends FlatSpec with ShouldMatchers {
|
||||
val now = new java.util.Date
|
||||
val order = Order (
|
||||
1000,
|
||||
10,
|
||||
"pending",
|
||||
10,
|
||||
101,
|
||||
now)
|
||||
|
||||
@ -56,8 +56,8 @@ class StoreApiTest extends FlatSpec with ShouldMatchers {
|
||||
val now = new java.util.Date
|
||||
val order = Order(
|
||||
1001,
|
||||
10,
|
||||
"pending",
|
||||
10,
|
||||
101,
|
||||
now)
|
||||
|
||||
|
@ -49,13 +49,13 @@ class UserApiTest extends FlatSpec with ShouldMatchers {
|
||||
it should "create a user" in {
|
||||
val user = User(
|
||||
1002,
|
||||
"Rocket",
|
||||
"408-867-5309",
|
||||
"johnny",
|
||||
"johnny@fail.com",
|
||||
1,
|
||||
"Johnny",
|
||||
"XXXXXXXXXXX")
|
||||
"johnny",
|
||||
"Rocket",
|
||||
"johnny@fail.com",
|
||||
"XXXXXXXXXXX",
|
||||
"408-867-5309",
|
||||
1)
|
||||
|
||||
api.createUser(user)
|
||||
|
||||
@ -72,14 +72,14 @@ class UserApiTest extends FlatSpec with ShouldMatchers {
|
||||
val userArray = (for (i <- (1 to 2)) yield {
|
||||
User(
|
||||
2000 + i,
|
||||
"Rocket-" + i,
|
||||
"408-867-5309",
|
||||
"johnny-" + i,
|
||||
"johnny-" + i + "@fail.com",
|
||||
1,
|
||||
"Johnny",
|
||||
"XXXXXXXXXXX")
|
||||
}).toArray
|
||||
"johnny-" + i,
|
||||
"Rocket-" + i,
|
||||
"johnny-" + i + "@fail.com",
|
||||
"XXXXXXXXXXX",
|
||||
"408-867-5309",
|
||||
1)
|
||||
}).toList
|
||||
api.createUsersWithArrayInput(userArray)
|
||||
|
||||
for (i <- (1 to 2)) {
|
||||
@ -97,13 +97,13 @@ class UserApiTest extends FlatSpec with ShouldMatchers {
|
||||
val userList = (for (i <- (1 to 3)) yield {
|
||||
User(
|
||||
3000 + i,
|
||||
"Rocket-" + i,
|
||||
"408-867-5309",
|
||||
"fred-" + i,
|
||||
"fred-" + i + "@fail.com",
|
||||
1,
|
||||
"Johnny",
|
||||
"XXXXXXXXXXX")
|
||||
"fred-" + i,
|
||||
"Rocket-" + i,
|
||||
"fred-" + i + "@fail.com",
|
||||
"XXXXXXXXXXX",
|
||||
"408-867-5309",
|
||||
1)
|
||||
}).toList
|
||||
api.createUsersWithListInput(userList)
|
||||
|
||||
@ -121,13 +121,13 @@ class UserApiTest extends FlatSpec with ShouldMatchers {
|
||||
it should "update a user" in {
|
||||
val user = User(
|
||||
4000,
|
||||
"Tiger",
|
||||
"408-867-5309",
|
||||
"tony",
|
||||
"tony@fail.com",
|
||||
1,
|
||||
"Tony",
|
||||
"XXXXXXXXXXX")
|
||||
"tony",
|
||||
"Tiger",
|
||||
"tony@fail.com",
|
||||
"XXXXXXXXXXX",
|
||||
"408-867-5309",
|
||||
1)
|
||||
|
||||
api.createUser(user)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user