fix requireParameterCount in scala

This commit is contained in:
wing328 2016-04-16 00:09:15 +08:00
parent c317f99466
commit 79decc53a1
16 changed files with 138 additions and 579 deletions

View File

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

View File

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

View File

@ -10,7 +10,7 @@ import collection.mutable
class {{classname}}(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) { class {{classname}}(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
{{#operation}} {{#operation}}
def {{nickname}}({{#allParams}}{{^required}}{{paramName}}: Option[{{dataType}}] = {{#defaultValue}}Some({{defaultValue}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{#hasMore}},{{/hasMore}} def {{operationId}}({{#allParams}}{{^required}}{{paramName}}: Option[{{dataType}}] = {{#defaultValue}}Some({{defaultValue}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{#hasMore}},{{/hasMore}}
{{/required}}{{#required}}{{paramName}}: {{dataType}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#hasMore}}, {{/required}}{{#required}}{{paramName}}: {{dataType}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#hasMore}},
{{/hasMore}}{{/required}}{{/allParams}})(implicit reader: ClientResponseReader[{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}]{{#bodyParams}}, writer: RequestWriter[{{dataType}}]{{/bodyParams}}){{#returnType}}: Future[{{returnType}}]{{/returnType}}{{^returnType}}: Future[Unit]{{/returnType}} = { {{/hasMore}}{{/required}}{{/allParams}})(implicit reader: ClientResponseReader[{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}]{{#bodyParams}}, writer: RequestWriter[{{dataType}}]{{/bodyParams}}){{#returnType}}: Future[{{returnType}}]{{/returnType}}{{^returnType}}: Future[Unit]{{/returnType}} = {
// create path and map variables // create path and map variables
@ -21,14 +21,28 @@ class {{classname}}(client: TransportClient, config: SwaggerConfig) extends ApiC
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
{{#allParams}}// verify required params are set {{#allParams}}
val paramCount = (Set[Any]({{/allParams}}{{#required}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/required}}{{#allParams}}) - null).size {{#required}}
if (paramCount != {{requiredParamCount}}) sys.error("missing required params"){{/allParams}} {{^isPrimitiveType}}
if ({{paramName}} == null) throw new Exception("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}")
{{#queryParams}}{{^required}}if({{paramName}} != null) {{paramName}}.foreach { v => queryParams += "{{baseName}}" -> v.toString }{{/required}}{{#required}} {{/isPrimitiveType}}
if({{paramName}} != null) queryParams += "{{baseName}}" -> {{paramName}}.toString{{/required}}{{/queryParams}} {{/required}}
{{/allParams}}
{{#queryParams}}
{{^required}}
if ({{paramName}} != null) {{paramName}}.foreach { v => queryParams += "{{baseName}}" -> v.toString }
{{#headerParams}}headerParams += "{{baseName}}" -> {{paramName}}.toString{{/headerParams}} {{/required}}
{{#required}}
if ({{paramName}} != null) queryParams += "{{baseName}}" -> {{paramName}}.toString
{{/required}}
{{/queryParams}}
{{#headerParams}}
headerParams += "{{baseName}}" -> {{paramName}}.toString
{{/headerParams}}
val resFuture = client.submit("{{httpMethod}}", path, queryParams.toMap, headerParams.toMap, {{#bodyParam}}writer.write({{paramName}}){{/bodyParam}}{{^bodyParam}}"{{emptyBodyParam}}"{{/bodyParam}}) val resFuture = client.submit("{{httpMethod}}", path, queryParams.toMap, headerParams.toMap, {{#bodyParam}}writer.write({{paramName}}){{/bodyParam}}{{^bodyParam}}"{{emptyBodyParam}}"{{/bodyParam}})
resFuture flatMap { resp => resFuture flatMap { resp =>

View File

@ -46,10 +46,12 @@ class {{classname}}(val defBasePath: String = "{{basePath}}",
{{#allParams}} {{#allParams}}
{{#required}} {{#required}}
{{^isPrimitiveType}}
if ({{paramName}} == null) throw new Exception("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}") if ({{paramName}} == null) throw new Exception("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}")
{{/isPrimitiveType}}
{{/required}} {{/required}}
{{/allParams}} {{/allParams}}
{{#queryParams}}if(String.valueOf({{paramName}}) != "null") queryParams += "{{baseName}}" -> {{paramName}}.toString {{#queryParams}}if(String.valueOf({{paramName}}) != "null") queryParams += "{{baseName}}" -> {{paramName}}.toString
{{/queryParams}} {{/queryParams}}
@ -69,7 +71,8 @@ class {{classname}}(val defBasePath: String = "{{basePath}}",
postBody = mp postBody = mp
} }
else { else {
{{#formParams}}{{#notFile}}formParams += "{{baseName}}" -> {{paramName}}.toString(){{/notFile}} {{#formParams}}
{{#notFile}}formParams += "{{baseName}}" -> {{paramName}}.toString(){{/notFile}}
{{/formParams}} {{/formParams}}
} }
@ -85,6 +88,7 @@ class {{classname}}(val defBasePath: String = "{{basePath}}",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
{{/operation}} {{/operation}}
} }
{{/operations}} {{/operations}}

View File

@ -1,8 +1,7 @@
package io.swagger.client.api package io.swagger.client.api
import io.swagger.client.model.Pet import io.swagger.client.model.Pet
import io.swagger.client.model.Inline_response_200 import io.swagger.client.model.ApiResponse
import io.swagger.client.model.Binary
import java.io.File import java.io.File
import com.wordnik.swagger.client._ import com.wordnik.swagger.client._
import scala.concurrent.Future import scala.concurrent.Future
@ -10,8 +9,7 @@ import collection.mutable
class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) { class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
def addPet(body: Option[Pet] = None def addPet(body: Pet)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = {
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = {
// create path and map variables // create path and map variables
val path = (addFmt("/pet")) val path = (addFmt("/pet"))
@ -19,36 +17,9 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set if (body == null) throw new Exception("Missing required parameter 'body' when calling PetApi->addPet")
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
resFuture flatMap { resp =>
process(reader.read(resp))
}
}
def addPetUsingByteArray(body: Option[Binary] = None
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Binary]): Future[Unit] = {
// create path and map variables
val path = (addFmt("/pet?testing_byte_array=true"))
// query params
val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String]
// verify required params are set
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body)) val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -67,13 +38,6 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set
val paramCount = (Set[Any](// verify required params are set
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")) - null).size
if (paramCount != ) sys.error("missing required params")
headerParams += "api_key" -> apiKey.toString headerParams += "api_key" -> apiKey.toString
@ -83,8 +47,7 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
} }
} }
def findPetsByStatus(status: Option[List[String]] = Some(available) def findPetsByStatus(status: List[String])(implicit reader: ClientResponseReader[List[Pet]]): Future[List[Pet]] = {
)(implicit reader: ClientResponseReader[List[Pet]]): Future[List[Pet]] = {
// create path and map variables // create path and map variables
val path = (addFmt("/pet/findByStatus")) val path = (addFmt("/pet/findByStatus"))
@ -92,13 +55,11 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set if (status == null) throw new Exception("Missing required parameter 'status' when calling PetApi->findPetsByStatus")
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params") if (status != null) queryParams += "status" -> status.toString
if(status != null) status.foreach { v => queryParams += "status" -> v.toString }
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "") val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -106,8 +67,7 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
} }
} }
def findPetsByTags(tags: Option[List[String]] = None def findPetsByTags(tags: List[String])(implicit reader: ClientResponseReader[List[Pet]]): Future[List[Pet]] = {
)(implicit reader: ClientResponseReader[List[Pet]]): Future[List[Pet]] = {
// create path and map variables // create path and map variables
val path = (addFmt("/pet/findByTags")) val path = (addFmt("/pet/findByTags"))
@ -115,13 +75,11 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set if (tags == null) throw new Exception("Missing required parameter 'tags' when calling PetApi->findPetsByTags")
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params") if (tags != null) queryParams += "tags" -> tags.toString
if(tags != null) tags.foreach { v => queryParams += "tags" -> v.toString }
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "") val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -138,13 +96,7 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "") val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -152,54 +104,7 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
} }
} }
def getPetByIdInObject(petId: Long)(implicit reader: ClientResponseReader[Inline_response_200]): Future[Inline_response_200] = { def updatePet(body: Pet)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = {
// create path and map variables
val path = (addFmt("/pet/{petId}?response=inline_arbitrary_object")
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
// query params
val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String]
// verify required params are set
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
}
}
def petPetIdtestingByteArraytrueGet(petId: Long)(implicit reader: ClientResponseReader[Binary]): Future[Binary] = {
// create path and map variables
val path = (addFmt("/pet/{petId}?testing_byte_array=true")
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
// query params
val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String]
// verify required params are set
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
}
}
def updatePet(body: Option[Pet] = None
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = {
// create path and map variables // create path and map variables
val path = (addFmt("/pet")) val path = (addFmt("/pet"))
@ -207,13 +112,9 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set if (body == null) throw new Exception("Missing required parameter 'body' when calling PetApi->updatePet")
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body)) val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body))
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -221,7 +122,7 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
} }
} }
def updatePetWithForm(petId: String, def updatePetWithForm(petId: Long,
name: Option[String] = None, name: Option[String] = None,
status: Option[String] = None status: Option[String] = None
)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = { )(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
@ -233,17 +134,7 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set
val paramCount = (Set[Any](// verify required params are set
val paramCount = (Set[Any](// verify required params are set
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")) - null).size
if (paramCount != ) sys.error("missing required params")) - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, "") val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -254,7 +145,7 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
def uploadFile(petId: Long, def uploadFile(petId: Long,
additionalMetadata: Option[String] = None, additionalMetadata: Option[String] = None,
file: Option[File] = None file: Option[File] = None
)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = { )(implicit reader: ClientResponseReader[ApiResponse]): Future[ApiResponse] = {
// create path and map variables // create path and map variables
val path = (addFmt("/pet/{petId}/uploadImage") val path = (addFmt("/pet/{petId}/uploadImage")
replaceAll ("\\{" + "petId" + "\\}",petId.toString)) replaceAll ("\\{" + "petId" + "\\}",petId.toString))
@ -263,17 +154,7 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set
val paramCount = (Set[Any](// verify required params are set
val paramCount = (Set[Any](// verify required params are set
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")) - null).size
if (paramCount != ) sys.error("missing required params")) - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, "") val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp => resFuture flatMap { resp =>

View File

@ -1,7 +1,6 @@
package io.swagger.client.api package io.swagger.client.api
import io.swagger.client.model.Order import io.swagger.client.model.Order
import io.swagger.client.model.Any
import com.wordnik.swagger.client._ import com.wordnik.swagger.client._
import scala.concurrent.Future import scala.concurrent.Future
import collection.mutable import collection.mutable
@ -17,13 +16,7 @@ class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "") val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -31,29 +24,6 @@ class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient
} }
} }
def findOrdersByStatus(status: Option[String] = Some(placed)
)(implicit reader: ClientResponseReader[List[Order]]): Future[List[Order]] = {
// create path and map variables
val path = (addFmt("/store/findByStatus"))
// query params
val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String]
// verify required params are set
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")
if(status != null) status.foreach { v => queryParams += "status" -> v.toString }
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
}
}
def getInventory()(implicit reader: ClientResponseReader[Map[String, Integer]]): Future[Map[String, Integer]] = { def getInventory()(implicit reader: ClientResponseReader[Map[String, Integer]]): Future[Map[String, Integer]] = {
// create path and map variables // create path and map variables
val path = (addFmt("/store/inventory")) val path = (addFmt("/store/inventory"))
@ -62,11 +32,7 @@ class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "") val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -74,27 +40,7 @@ class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient
} }
} }
def getInventoryInObject()(implicit reader: ClientResponseReader[Any]): Future[Any] = { def getOrderById(orderId: Long)(implicit reader: ClientResponseReader[Order]): Future[Order] = {
// create path and map variables
val path = (addFmt("/store/inventory?response=arbitrary_object"))
// query params
val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String]
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp =>
process(reader.read(resp))
}
}
def getOrderById(orderId: String)(implicit reader: ClientResponseReader[Order]): Future[Order] = {
// create path and map variables // create path and map variables
val path = (addFmt("/store/order/{orderId}") val path = (addFmt("/store/order/{orderId}")
replaceAll ("\\{" + "orderId" + "\\}",orderId.toString)) replaceAll ("\\{" + "orderId" + "\\}",orderId.toString))
@ -103,13 +49,7 @@ class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "") val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -117,8 +57,7 @@ class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient
} }
} }
def placeOrder(body: Option[Order] = None def placeOrder(body: Order)(implicit reader: ClientResponseReader[Order], writer: RequestWriter[Order]): Future[Order] = {
)(implicit reader: ClientResponseReader[Order], writer: RequestWriter[Order]): Future[Order] = {
// create path and map variables // create path and map variables
val path = (addFmt("/store/order")) val path = (addFmt("/store/order"))
@ -126,13 +65,9 @@ class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set if (body == null) throw new Exception("Missing required parameter 'body' when calling StoreApi->placeOrder")
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body)) val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
resFuture flatMap { resp => resFuture flatMap { resp =>

View File

@ -7,8 +7,7 @@ import collection.mutable
class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) { class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
def createUser(body: Option[User] = None def createUser(body: User)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = {
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = {
// create path and map variables // create path and map variables
val path = (addFmt("/user")) val path = (addFmt("/user"))
@ -16,13 +15,9 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set if (body == null) throw new Exception("Missing required parameter 'body' when calling UserApi->createUser")
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body)) val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -30,8 +25,7 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
} }
} }
def createUsersWithArrayInput(body: Option[List[User]] = None def createUsersWithArrayInput(body: List[User])(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = {
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = {
// create path and map variables // create path and map variables
val path = (addFmt("/user/createWithArray")) val path = (addFmt("/user/createWithArray"))
@ -39,13 +33,9 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set if (body == null) throw new Exception("Missing required parameter 'body' when calling UserApi->createUsersWithArrayInput")
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body)) val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -53,8 +43,7 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
} }
} }
def createUsersWithListInput(body: Option[List[User]] = None def createUsersWithListInput(body: List[User])(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = {
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = {
// create path and map variables // create path and map variables
val path = (addFmt("/user/createWithList")) val path = (addFmt("/user/createWithList"))
@ -62,13 +51,9 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set if (body == null) throw new Exception("Missing required parameter 'body' when calling UserApi->createUsersWithListInput")
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body)) val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -85,13 +70,7 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "") val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -108,13 +87,7 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "") val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -122,9 +95,8 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
} }
} }
def loginUser(username: Option[String] = None, def loginUser(username: String,
password: Option[String] = None password: String)(implicit reader: ClientResponseReader[String]): Future[String] = {
)(implicit reader: ClientResponseReader[String]): Future[String] = {
// create path and map variables // create path and map variables
val path = (addFmt("/user/login")) val path = (addFmt("/user/login"))
@ -132,15 +104,11 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set if (username != null) queryParams += "username" -> username.toString
val paramCount = (Set[Any](// verify required params are set
val paramCount = (Set[Any]() - null).size if (password != null) queryParams += "password" -> password.toString
if (paramCount != ) sys.error("missing required params")) - null).size
if (paramCount != ) sys.error("missing required params")
if(username != null) username.foreach { v => queryParams += "username" -> v.toString }if(password != null) password.foreach { v => queryParams += "password" -> v.toString }
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "") val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -156,11 +124,7 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "") val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
resFuture flatMap { resp => resFuture flatMap { resp =>
@ -169,8 +133,7 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
} }
def updateUser(username: String, def updateUser(username: String,
body: Option[User] = None body: User)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = {
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = {
// create path and map variables // create path and map variables
val path = (addFmt("/user/{username}") val path = (addFmt("/user/{username}")
replaceAll ("\\{" + "username" + "\\}",username.toString)) replaceAll ("\\{" + "username" + "\\}",username.toString))
@ -179,15 +142,9 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
val queryParams = new mutable.HashMap[String, String] val queryParams = new mutable.HashMap[String, String]
val headerParams = new mutable.HashMap[String, String] val headerParams = new mutable.HashMap[String, String]
// verify required params are set if (body == null) throw new Exception("Missing required parameter 'body' when calling UserApi->updateUser")
val paramCount = (Set[Any](// verify required params are set
val paramCount = (Set[Any]() - null).size
if (paramCount != ) sys.error("missing required params")) - null).size
if (paramCount != ) sys.error("missing required params")
val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body)) val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body))
resFuture flatMap { resp => resFuture flatMap { resp =>

View File

@ -1,8 +1,18 @@
import io.swagger.client._
import io.swagger.client.api._
import io.swagger.client.model._
import java.net.URI import java.net.URI
import scala.concurrent._ import scala.concurrent._
import scala.concurrent.duration._ import scala.concurrent.duration._
import scala.util.{Failure, Success} import scala.util.{Failure, Success}
import org.scalatest._
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.FunSuite
import com.wordnik.swagger._
com.wordnik.swagger.client
@RunWith(classOf[JUnitRunner]) @RunWith(classOf[JUnitRunner])
class SimpleTest extends FlatSpec with Matchers { class SimpleTest extends FlatSpec with Matchers {
@ -24,4 +34,4 @@ class SimpleTest extends FlatSpec with Matchers {
case Failure(t) => println("failed " + t.getMessage) case Failure(t) => println("failed " + t.getMessage)
} }
} }
} }

View File

@ -1,7 +1,7 @@
package io.swagger.client.api package io.swagger.client.api
import io.swagger.client.model.Pet import io.swagger.client.model.Pet
import io.swagger.client.model.InlineResponse200 import io.swagger.client.model.ApiResponse
import java.io.File import java.io.File
import io.swagger.client.ApiInvoker import io.swagger.client.ApiInvoker
import io.swagger.client.ApiException import io.swagger.client.ApiException
@ -26,7 +26,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
/** /**
* Add a new pet to the store * Add a new pet to the store
* *
* @param body Pet object that needs to be added to the store (optional) * @param body Pet object that needs to be added to the store
* @return void * @return void
*/ */
def addPet (body: Pet) = { def addPet (body: Pet) = {
@ -40,6 +40,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (body == null) throw new Exception("Missing required parameter 'body' when calling PetApi->addPet")
@ -51,7 +52,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -63,46 +64,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/**
* Fake endpoint to test byte array in body parameter for adding a new pet to the store
*
* @param body Pet object in the form of byte array (optional)
* @return void
*/
def addPetUsingByteArray (body: String) = {
// create path and map variables
val path = "/pet?testing_byte_array=true".replaceAll("\\{format\\}","json")
val contentTypes = List("application/json", "application/xml", "application/json")
val contentType = contentTypes(0)
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String]
var postBody: AnyRef = body
if(contentType.startsWith("multipart/form-data")) {
val mp = new FormDataMultiPart()
postBody = mp
}
else {
}
try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
case s: String =>
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
/** /**
* Deletes a pet * Deletes a pet
* *
@ -123,8 +85,6 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (petId == null) throw new Exception("Missing required parameter 'petId' when calling PetApi->deletePet")
headerParams += "api_key" -> apiKey headerParams += "api_key" -> apiKey
@ -136,7 +96,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -148,13 +108,14 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/** /**
* Finds Pets by status * Finds Pets by status
* Multiple status values can be provided with comma separated strings * Multiple status values can be provided with comma separated strings
* @param status Status values that need to be considered for query (optional, default to available) * @param status Status values that need to be considered for filter
* @return List[Pet] * @return List[Pet]
*/ */
def findPetsByStatus (status: List[String] /* = available */) : Option[List[Pet]] = { def findPetsByStatus (status: List[String]) : Option[List[Pet]] = {
// create path and map variables // create path and map variables
val path = "/pet/findByStatus".replaceAll("\\{format\\}","json") val path = "/pet/findByStatus".replaceAll("\\{format\\}","json")
val contentTypes = List("application/json") val contentTypes = List("application/json")
@ -165,6 +126,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (status == null) throw new Exception("Missing required parameter 'status' when calling PetApi->findPetsByStatus")
if(String.valueOf(status) != "null") queryParams += "status" -> status.toString if(String.valueOf(status) != "null") queryParams += "status" -> status.toString
@ -177,7 +139,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -190,10 +152,11 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/** /**
* Finds Pets by tags * Finds Pets by tags
* Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* @param tags Tags to filter by (optional) * @param tags Tags to filter by
* @return List[Pet] * @return List[Pet]
*/ */
def findPetsByTags (tags: List[String]) : Option[List[Pet]] = { def findPetsByTags (tags: List[String]) : Option[List[Pet]] = {
@ -207,6 +170,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (tags == null) throw new Exception("Missing required parameter 'tags' when calling PetApi->findPetsByTags")
if(String.valueOf(tags) != "null") queryParams += "tags" -> tags.toString if(String.valueOf(tags) != "null") queryParams += "tags" -> tags.toString
@ -219,7 +183,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -232,10 +196,11 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/** /**
* Find pet by ID * Find pet by ID
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions * Returns a single pet
* @param petId ID of pet that needs to be fetched * @param petId ID of pet to return
* @return Pet * @return Pet
*/ */
def getPetById (petId: Long) : Option[Pet] = { def getPetById (petId: Long) : Option[Pet] = {
@ -251,8 +216,6 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (petId == null) throw new Exception("Missing required parameter 'petId' when calling PetApi->getPetById")
var postBody: AnyRef = null var postBody: AnyRef = null
@ -263,7 +226,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -276,98 +239,11 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/**
* Fake endpoint to test inline arbitrary object return by 'Find pet by ID'
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
* @param petId ID of pet that needs to be fetched
* @return InlineResponse200
*/
def getPetByIdInObject (petId: Long) : Option[InlineResponse200] = {
// create path and map variables
val path = "/pet/{petId}?response=inline_arbitrary_object".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}",apiInvoker.escape(petId))
val contentTypes = List("application/json")
val contentType = contentTypes(0)
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String]
if (petId == null) throw new Exception("Missing required parameter 'petId' when calling PetApi->getPetByIdInObject")
var postBody: AnyRef = null
if(contentType.startsWith("multipart/form-data")) {
val mp = new FormDataMultiPart()
postBody = mp
}
else {
}
try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[InlineResponse200]).asInstanceOf[InlineResponse200])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
/**
* Fake endpoint to test byte array return by 'Find pet by ID'
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
* @param petId ID of pet that needs to be fetched
* @return String
*/
def petPetIdtestingByteArraytrueGet (petId: Long) : Option[String] = {
// create path and map variables
val path = "/pet/{petId}?testing_byte_array=true".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}",apiInvoker.escape(petId))
val contentTypes = List("application/json")
val contentType = contentTypes(0)
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String]
if (petId == null) throw new Exception("Missing required parameter 'petId' when calling PetApi->petPetIdtestingByteArraytrueGet")
var postBody: AnyRef = null
if(contentType.startsWith("multipart/form-data")) {
val mp = new FormDataMultiPart()
postBody = mp
}
else {
}
try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[String]).asInstanceOf[String])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
/** /**
* Update an existing pet * Update an existing pet
* *
* @param body Pet object that needs to be added to the store (optional) * @param body Pet object that needs to be added to the store
* @return void * @return void
*/ */
def updatePet (body: Pet) = { def updatePet (body: Pet) = {
@ -381,6 +257,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (body == null) throw new Exception("Missing required parameter 'body' when calling PetApi->updatePet")
@ -392,7 +269,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "PUT", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "PUT", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -404,6 +281,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/** /**
* Updates a pet in the store with form data * Updates a pet in the store with form data
* *
@ -412,7 +290,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
* @param status Updated status of the pet (optional) * @param status Updated status of the pet (optional)
* @return void * @return void
*/ */
def updatePetWithForm (petId: String, name: String, status: String) = { def updatePetWithForm (petId: Long, name: String, status: String) = {
// create path and map variables // create path and map variables
val path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}",apiInvoker.escape(petId)) val path = "/pet/{petId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}",apiInvoker.escape(petId))
@ -425,8 +303,6 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (petId == null) throw new Exception("Missing required parameter 'petId' when calling PetApi->updatePetWithForm")
var postBody: AnyRef = null var postBody: AnyRef = null
@ -442,7 +318,7 @@ class PetApi(val defBasePath: String = "http://petstore.swagger.io/v2",
} }
else { else {
formParams += "name" -> name.toString() formParams += "name" -> name.toString()
formParams += "status" -> status.toString() formParams += "status" -> status.toString()
} }
try { try {
@ -455,15 +331,16 @@ formParams += "status" -> status.toString()
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/** /**
* uploads an image * uploads an image
* *
* @param petId ID of pet to update * @param petId ID of pet to update
* @param additionalMetadata Additional data to pass to server (optional) * @param additionalMetadata Additional data to pass to server (optional)
* @param file file to upload (optional) * @param file file to upload (optional)
* @return void * @return ApiResponse
*/ */
def uploadFile (petId: Long, additionalMetadata: String, file: File) = { def uploadFile (petId: Long, additionalMetadata: String, file: File) : Option[ApiResponse] = {
// create path and map variables // create path and map variables
val path = "/pet/{petId}/uploadImage".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}",apiInvoker.escape(petId)) val path = "/pet/{petId}/uploadImage".replaceAll("\\{format\\}","json").replaceAll("\\{" + "petId" + "\\}",apiInvoker.escape(petId))
@ -476,8 +353,6 @@ formParams += "status" -> status.toString()
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (petId == null) throw new Exception("Missing required parameter 'petId' when calling PetApi->uploadFile")
var postBody: AnyRef = null var postBody: AnyRef = null
@ -494,17 +369,19 @@ formParams += "status" -> status.toString()
} }
else { else {
formParams += "additionalMetadata" -> additionalMetadata.toString() formParams += "additionalMetadata" -> additionalMetadata.toString()
} }
try { try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
case s: String => case s: String =>
case _ => None Some(ApiInvoker.deserialize(s, "", classOf[ApiResponse]).asInstanceOf[ApiResponse])
case _ => None
} }
} catch { } catch {
case ex: ApiException if ex.code == 404 => None case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
} }

View File

@ -40,8 +40,6 @@ class StoreApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (orderId == null) throw new Exception("Missing required parameter 'orderId' when calling StoreApi->deleteOrder")
var postBody: AnyRef = null var postBody: AnyRef = null
@ -52,7 +50,7 @@ class StoreApi(val defBasePath: String = "http://petstore.swagger.io/v2",
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -64,48 +62,7 @@ class StoreApi(val defBasePath: String = "http://petstore.swagger.io/v2",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/**
* Finds orders by status
* A single status value can be provided as a string
* @param status Status value that needs to be considered for query (optional, default to placed)
* @return List[Order]
*/
def findOrdersByStatus (status: String /* = placed */) : Option[List[Order]] = {
// create path and map variables
val path = "/store/findByStatus".replaceAll("\\{format\\}","json")
val contentTypes = List("application/json")
val contentType = contentTypes(0)
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String]
if(String.valueOf(status) != "null") queryParams += "status" -> status.toString
var postBody: AnyRef = null
if(contentType.startsWith("multipart/form-data")) {
val mp = new FormDataMultiPart()
postBody = mp
}
else {
}
try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "array", classOf[Order]).asInstanceOf[List[Order]])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
/** /**
* Returns pet inventories by status * Returns pet inventories by status
* Returns a map of status codes to quantities * Returns a map of status codes to quantities
@ -122,7 +79,6 @@ class StoreApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
var postBody: AnyRef = null var postBody: AnyRef = null
@ -133,7 +89,7 @@ class StoreApi(val defBasePath: String = "http://petstore.swagger.io/v2",
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -146,53 +102,14 @@ class StoreApi(val defBasePath: String = "http://petstore.swagger.io/v2",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/**
* Fake endpoint to test arbitrary object return by 'Get inventory'
* Returns an arbitrary object which is actually a map of status codes to quantities
* @return Any
*/
def getInventoryInObject () : Option[Any] = {
// create path and map variables
val path = "/store/inventory?response=arbitrary_object".replaceAll("\\{format\\}","json")
val contentTypes = List("application/json")
val contentType = contentTypes(0)
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String]
var postBody: AnyRef = null
if(contentType.startsWith("multipart/form-data")) {
val mp = new FormDataMultiPart()
postBody = mp
}
else {
}
try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[Any]).asInstanceOf[Any])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
/** /**
* Find purchase order by ID * Find purchase order by ID
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
* @param orderId ID of pet that needs to be fetched * @param orderId ID of pet that needs to be fetched
* @return Order * @return Order
*/ */
def getOrderById (orderId: String) : Option[Order] = { def getOrderById (orderId: Long) : Option[Order] = {
// create path and map variables // create path and map variables
val path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}",apiInvoker.escape(orderId)) val path = "/store/order/{orderId}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "orderId" + "\\}",apiInvoker.escape(orderId))
@ -205,8 +122,6 @@ class StoreApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (orderId == null) throw new Exception("Missing required parameter 'orderId' when calling StoreApi->getOrderById")
var postBody: AnyRef = null var postBody: AnyRef = null
@ -217,7 +132,7 @@ class StoreApi(val defBasePath: String = "http://petstore.swagger.io/v2",
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -230,10 +145,11 @@ class StoreApi(val defBasePath: String = "http://petstore.swagger.io/v2",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/** /**
* Place an order for a pet * Place an order for a pet
* *
* @param body order placed for purchasing the pet (optional) * @param body order placed for purchasing the pet
* @return Order * @return Order
*/ */
def placeOrder (body: Order) : Option[Order] = { def placeOrder (body: Order) : Option[Order] = {
@ -247,6 +163,7 @@ class StoreApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (body == null) throw new Exception("Missing required parameter 'body' when calling StoreApi->placeOrder")
@ -258,7 +175,7 @@ class StoreApi(val defBasePath: String = "http://petstore.swagger.io/v2",
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -271,4 +188,5 @@ class StoreApi(val defBasePath: String = "http://petstore.swagger.io/v2",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
} }

View File

@ -24,7 +24,7 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
/** /**
* Create user * Create user
* This can only be done by the logged in user. * This can only be done by the logged in user.
* @param body Created user object (optional) * @param body Created user object
* @return void * @return void
*/ */
def createUser (body: User) = { def createUser (body: User) = {
@ -38,6 +38,7 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (body == null) throw new Exception("Missing required parameter 'body' when calling UserApi->createUser")
@ -49,7 +50,7 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -61,10 +62,11 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/** /**
* Creates list of users with given input array * Creates list of users with given input array
* *
* @param body List of user object (optional) * @param body List of user object
* @return void * @return void
*/ */
def createUsersWithArrayInput (body: List[User]) = { def createUsersWithArrayInput (body: List[User]) = {
@ -78,6 +80,7 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (body == null) throw new Exception("Missing required parameter 'body' when calling UserApi->createUsersWithArrayInput")
@ -89,7 +92,7 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -101,10 +104,11 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/** /**
* Creates list of users with given input array * Creates list of users with given input array
* *
* @param body List of user object (optional) * @param body List of user object
* @return void * @return void
*/ */
def createUsersWithListInput (body: List[User]) = { def createUsersWithListInput (body: List[User]) = {
@ -118,6 +122,7 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (body == null) throw new Exception("Missing required parameter 'body' when calling UserApi->createUsersWithListInput")
@ -129,7 +134,7 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -141,6 +146,7 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/** /**
* Delete user * Delete user
* This can only be done by the logged in user. * This can only be done by the logged in user.
@ -160,8 +166,6 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (username == null) throw new Exception("Missing required parameter 'username' when calling UserApi->deleteUser")
var postBody: AnyRef = null var postBody: AnyRef = null
@ -172,7 +176,7 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -184,6 +188,7 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/** /**
* Get user by user name * Get user by user name
* *
@ -203,8 +208,6 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (username == null) throw new Exception("Missing required parameter 'username' when calling UserApi->getUserByName")
var postBody: AnyRef = null var postBody: AnyRef = null
@ -215,7 +218,7 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -228,11 +231,12 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/** /**
* Logs user into the system * Logs user into the system
* *
* @param username The user name for login (optional) * @param username The user name for login
* @param password The password for login in clear text (optional) * @param password The password for login in clear text
* @return String * @return String
*/ */
def loginUser (username: String, password: String) : Option[String] = { def loginUser (username: String, password: String) : Option[String] = {
@ -246,7 +250,6 @@ class UserApi(val defBasePath: String = "http://petstore.swagger.io/v2",
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
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
@ -259,7 +262,7 @@ if(String.valueOf(password) != "null") queryParams += "password" -> password.toS
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -272,6 +275,7 @@ if(String.valueOf(password) != "null") queryParams += "password" -> password.toS
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/** /**
* Logs out current logged in user session * Logs out current logged in user session
* *
@ -288,7 +292,6 @@ if(String.valueOf(password) != "null") queryParams += "password" -> password.toS
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
var postBody: AnyRef = null var postBody: AnyRef = null
@ -299,7 +302,7 @@ if(String.valueOf(password) != "null") queryParams += "password" -> password.toS
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -311,11 +314,12 @@ if(String.valueOf(password) != "null") queryParams += "password" -> password.toS
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
/** /**
* Updated user * Updated user
* This can only be done by the logged in user. * This can only be done by the logged in user.
* @param username name that need to be deleted * @param username name that need to be deleted
* @param body Updated user object (optional) * @param body Updated user object
* @return void * @return void
*/ */
def updateUser (username: String, body: User) = { def updateUser (username: String, body: User) = {
@ -331,7 +335,7 @@ if(String.valueOf(password) != "null") queryParams += "password" -> password.toS
val headerParams = new HashMap[String, String] val headerParams = new HashMap[String, String]
val formParams = new HashMap[String, String] val formParams = new HashMap[String, String]
if (username == null) throw new Exception("Missing required parameter 'username' when calling UserApi->updateUser") if (body == null) throw new Exception("Missing required parameter 'body' when calling UserApi->updateUser")
@ -343,7 +347,7 @@ if(String.valueOf(password) != "null") queryParams += "password" -> password.toS
postBody = mp postBody = mp
} }
else { else {
} }
try { try {
apiInvoker.invokeApi(basePath, path, "PUT", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match { apiInvoker.invokeApi(basePath, path, "PUT", queryParams.toMap, formParams.toMap, postBody, headerParams.toMap, contentType) match {
@ -355,4 +359,5 @@ if(String.valueOf(password) != "null") queryParams += "password" -> password.toS
case ex: ApiException => throw ex case ex: ApiException => throw ex
} }
} }
} }

View File

@ -1,13 +0,0 @@
package io.swagger.client.model
case class InlineResponse200 (
tags: List[Tag],
id: Long,
category: Any,
/* pet status in the store */
status: String,
name: String,
photoUrls: List[String])

View File

@ -1,7 +0,0 @@
package io.swagger.client.model
case class Model200Response (
name: Integer)

View File

@ -1,7 +0,0 @@
package io.swagger.client.model
case class ModelReturn (
_return: Integer)

View File

@ -1,8 +0,0 @@
package io.swagger.client.model
case class Name (
name: Integer,
snakeCase: Integer)

View File

@ -1,7 +0,0 @@
package io.swagger.client.model
case class SpecialModelName (
specialPropertyName: Long)