fix perl and asyncscala optional tab

This commit is contained in:
wing328 2015-06-25 23:10:25 +08:00
parent 8cce7ac053
commit 18ac6e8aae
15 changed files with 526 additions and 529 deletions

View File

@ -11,10 +11,9 @@ import collection.mutable
class {{classname}}(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
{{#operation}}
def {{nickname}}({{#allParams}}{{#optional}}{{paramName}}: Option[{{dataType}}] = {{#defaultValue}}Some({{defaultValue}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{#hasMore}},
{{/hasMore}}
{{/optional}}{{^optional}}{{paramName}}: {{dataType}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#hasMore}},
{{/hasMore}}{{/optional}}{{/allParams}})(implicit reader: ClientResponseReader[{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Unit{{/returnType}}]{{#bodyParams}}, writer: RequestWriter[{{dataType}}]{{/bodyParams}}){{#returnType}}: Future[{{returnType}}]{{/returnType}}{{^returnType}}: Future[Unit]{{/returnType}} = {
def {{nickname}}({{#allParams}}{{^required}}{{paramName}}: Option[{{dataType}}] = {{#defaultValue}}Some({{defaultValue}}){{/defaultValue}}{{^defaultValue}}None{{/defaultValue}}{{#hasMore}},{{/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}} = {
// create path and map variables
val path = (addFmt("{{path}}"){{#pathParams}}
replaceAll ("\\{" + "{{baseName}}" + "\\}",{{paramName}}.toString){{/pathParams}})
@ -27,8 +26,8 @@ class {{classname}}(client: TransportClient, config: SwaggerConfig) extends ApiC
val paramCount = (Set[Any]({{/requiredParamCount}}{{#requiredParams}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) - null).size
if (paramCount != {{requiredParamCount}}) sys.error("missing required params"){{/requiredParamCount}}
{{#queryParams}}{{#optional}}if({{paramName}} != null) {{paramName}}.foreach { v => queryParams += "{{baseName}}" -> v.toString }{{/optional}}{{^optional}}
if({{paramName}} != null) queryParams += "{{baseName}}" -> {{paramName}}.toString{{/optional}}{{/queryParams}}
{{#queryParams}}{{^required}}if({{paramName}} != null) {{paramName}}.foreach { v => queryParams += "{{baseName}}" -> v.toString }{{/required}}{{#required}}
if({{paramName}} != null) queryParams += "{{baseName}}" -> {{paramName}}.toString{{/required}}{{/queryParams}}
{{#headerParams}}headerParams += "{{baseName}}" -> {{paramName}}.toString{{/headerParams}}

View File

@ -54,7 +54,7 @@ sub new {
#
# {{{summary}}}
#
{{#allParams}}# @param {{dataType}} ${{paramName}} {{description}} {{^optional}}(required){{/optional}}{{#optional}}(optional){{/optional}}
{{#allParams}}# @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional){{/required}}
{{/allParams}}# @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
#
sub {{nickname}} {

View File

@ -3,10 +3,10 @@ organization := ""
name := "-client"
libraryDependencies ++= Seq(
"com.wordnik" %% "swagger-async-httpclient" % "0.3.5",
"joda-time" % "joda-time" % "2.3",
"org.joda" % "joda-convert" % "1.3.1",
"ch.qos.logback" % "logback-classic" % "1.0.13" % "provided",
"org.scalatest" %% "scalatest" % "2.2.1" % "test",
"junit" % "junit" % "4.11" % "test"
"io.swagger" %% "swagger-async-httpclient" % "0.3.5",
"joda-time" % "joda-time" % "2.3",
"org.joda" % "joda-convert" % "1.3.1",
"ch.qos.logback" % "logback-classic" % "1.0.13" % "provided",
"org.scalatest" %% "scalatest" % "2.2.1" % "test",
"junit" % "junit" % "4.11" % "test"
)

View File

@ -7,12 +7,12 @@ import io.swagger.client._
import java.io.Closeable
class SwaggerClient(config: SwaggerConfig) extends Closeable {
val locator = config.locator
val name = config.name
val locator = config.locator
val name = config.name
private[this] val client = transportClient
private[this] val client = transportClient
protected def transportClient: TransportClient = new RestClient(config)
protected def transportClient: TransportClient = new RestClient(config)
val user = new UserApi(client, config)
@ -21,7 +21,7 @@ protected def transportClient: TransportClient = new RestClient(config)
val store = new StoreApi(client, config)
def close() {
client.close()
}
def close() {
client.close()
}
}

View File

@ -7,10 +7,11 @@ import scala.concurrent.{ Future, Await }
import scala.concurrent.duration._
import collection.mutable
class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
def updatePet(body: Pet)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = {
def updatePet(body: Option[Pet] = None
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = {
// create path and map variables
val path = (addFmt("/pet"))
@ -31,7 +32,8 @@ import collection.mutable
}
def addPet(body: Pet)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = {
def addPet(body: Option[Pet] = None
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[Pet]): Future[Unit] = {
// create path and map variables
val path = (addFmt("/pet"))
@ -52,7 +54,8 @@ import collection.mutable
}
def findPetsByStatus(status: List[String] = available)(implicit reader: ClientResponseReader[List[Pet]]): Future[List[Pet]] = {
def findPetsByStatus(status: Option[List[String]] = Some(available)
)(implicit reader: ClientResponseReader[List[Pet]]): Future[List[Pet]] = {
// create path and map variables
val path = (addFmt("/pet/findByStatus"))
@ -62,8 +65,7 @@ import collection.mutable
if(status != null) queryParams += "status" -> status.toString
if(status != null) status.foreach { v => queryParams += "status" -> v.toString }
@ -74,7 +76,8 @@ import collection.mutable
}
def findPetsByTags(tags: List[String])(implicit reader: ClientResponseReader[List[Pet]]): Future[List[Pet]] = {
def findPetsByTags(tags: Option[List[String]] = None
)(implicit reader: ClientResponseReader[List[Pet]]): Future[List[Pet]] = {
// create path and map variables
val path = (addFmt("/pet/findByTags"))
@ -84,8 +87,7 @@ import collection.mutable
if(tags != null) queryParams += "tags" -> tags.toString
if(tags != null) tags.foreach { v => queryParams += "tags" -> v.toString }
@ -119,8 +121,9 @@ import collection.mutable
def updatePetWithForm(petId: String,
name: String,
status: String)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
name: Option[String] = None,
status: Option[String] = None
)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
// create path and map variables
val path = (addFmt("/pet/{petId}")
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
@ -142,7 +145,7 @@ import collection.mutable
}
def deletePet(apiKey: String,
def deletePet(apiKey: Option[String] = None,
petId: Long)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
// create path and map variables
val path = (addFmt("/pet/{petId}")
@ -166,8 +169,9 @@ import collection.mutable
def uploadFile(petId: Long,
additionalMetadata: String,
file: File)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
additionalMetadata: Option[String] = None,
file: Option[File] = None
)(implicit reader: ClientResponseReader[Unit]): Future[Unit] = {
// create path and map variables
val path = (addFmt("/pet/{petId}/uploadImage")
replaceAll ("\\{" + "petId" + "\\}",petId.toString))
@ -190,4 +194,4 @@ import collection.mutable
}
}

View File

@ -6,7 +6,7 @@ import scala.concurrent.{ Future, Await }
import scala.concurrent.duration._
import collection.mutable
class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(client, config) {
def getInventory()(implicit reader: ClientResponseReader[Map[String, Integer]]): Future[Map[String, Integer]] = {
@ -30,7 +30,8 @@ import collection.mutable
}
def placeOrder(body: Order)(implicit reader: ClientResponseReader[Order], writer: RequestWriter[Order]): Future[Order] = {
def placeOrder(body: Option[Order] = None
)(implicit reader: ClientResponseReader[Order], writer: RequestWriter[Order]): Future[Order] = {
// create path and map variables
val path = (addFmt("/store/order"))
@ -96,4 +97,4 @@ import collection.mutable
}
}

View File

@ -6,10 +6,11 @@ import scala.concurrent.{ Future, Await }
import scala.concurrent.duration._
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: User)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = {
def createUser(body: Option[User] = None
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = {
// create path and map variables
val path = (addFmt("/user"))
@ -30,7 +31,8 @@ import collection.mutable
}
def createUsersWithArrayInput(body: List[User])(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = {
def createUsersWithArrayInput(body: Option[List[User]] = None
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = {
// create path and map variables
val path = (addFmt("/user/createWithArray"))
@ -51,7 +53,8 @@ import collection.mutable
}
def createUsersWithListInput(body: List[User])(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = {
def createUsersWithListInput(body: Option[List[User]] = None
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[List[User]]): Future[Unit] = {
// create path and map variables
val path = (addFmt("/user/createWithList"))
@ -72,8 +75,9 @@ import collection.mutable
}
def loginUser(username: String,
password: String)(implicit reader: ClientResponseReader[String]): Future[String] = {
def loginUser(username: Option[String] = None,
password: Option[String] = None
)(implicit reader: ClientResponseReader[String]): Future[String] = {
// create path and map variables
val path = (addFmt("/user/login"))
@ -83,9 +87,7 @@ import collection.mutable
if(username != null) queryParams += "username" -> username.toString
if(password != null) queryParams += "password" -> password.toString
if(username != null) username.foreach { v => queryParams += "username" -> v.toString }if(password != null) password.foreach { v => queryParams += "password" -> v.toString }
@ -140,7 +142,8 @@ import collection.mutable
def updateUser(username: String,
body: User)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = {
body: Option[User] = None
)(implicit reader: ClientResponseReader[Unit], writer: RequestWriter[User]): Future[Unit] = {
// create path and map variables
val path = (addFmt("/user/{username}")
replaceAll ("\\{" + "username" + "\\}",username.toString))
@ -185,4 +188,4 @@ import collection.mutable
}
}

View File

@ -3,10 +3,8 @@ package io.swagger.client.model
import org.joda.time.DateTime
case class Category (
case class Category (
id: Long,
name: String
)
)

View File

@ -3,8 +3,7 @@ package io.swagger.client.model
import org.joda.time.DateTime
case class Order (
case class Order (
id: Long,
petId: Long,
quantity: Integer,
@ -12,5 +11,4 @@ import org.joda.time.DateTime
status: String, // Order Status
complete: Boolean
)
)

View File

@ -3,8 +3,7 @@ package io.swagger.client.model
import org.joda.time.DateTime
case class Pet (
case class Pet (
id: Long,
category: Category,
name: String,
@ -12,5 +11,4 @@ import org.joda.time.DateTime
tags: List[Tag],
status: String // pet status in the store
)
)

View File

@ -3,10 +3,8 @@ package io.swagger.client.model
import org.joda.time.DateTime
case class Tag (
case class Tag (
id: Long,
name: String
)
)

View File

@ -3,8 +3,7 @@ package io.swagger.client.model
import org.joda.time.DateTime
case class User (
case class User (
id: Long,
username: String,
firstName: String,
@ -14,5 +13,4 @@ import org.joda.time.DateTime
phone: String,
userStatus: Integer // User Status
)
)

View File

@ -52,7 +52,7 @@ sub new {
#
# Update an existing pet
#
# @param Pet $body Pet object that needs to be added to the store (required)
# @param Pet $body Pet object that needs to be added to the store (optional)
# @return void
#
sub update_pet {
@ -102,7 +102,7 @@ sub update_pet {
#
# Add a new pet to the store
#
# @param Pet $body Pet object that needs to be added to the store (required)
# @param Pet $body Pet object that needs to be added to the store (optional)
# @return void
#
sub add_pet {
@ -152,7 +152,7 @@ sub add_pet {
#
# Finds Pets by status
#
# @param ARRAY[string] $status Status values that need to be considered for filter (required)
# @param ARRAY[string] $status Status values that need to be considered for filter (optional)
# @return ARRAY[Pet]
#
sub find_pets_by_status {
@ -205,7 +205,7 @@ sub find_pets_by_status {
#
# Finds Pets by tags
#
# @param ARRAY[string] $tags Tags to filter by (required)
# @param ARRAY[string] $tags Tags to filter by (optional)
# @return ARRAY[Pet]
#
sub find_pets_by_tags {
@ -319,8 +319,8 @@ sub get_pet_by_id {
# Updates a pet in the store with form data
#
# @param string $pet_id ID of pet that needs to be updated (required)
# @param string $name Updated name of the pet (required)
# @param string $status Updated status of the pet (required)
# @param string $name Updated name of the pet (optional)
# @param string $status Updated status of the pet (optional)
# @return void
#
sub update_pet_with_form {
@ -387,7 +387,7 @@ sub update_pet_with_form {
#
# Deletes a pet
#
# @param string $api_key (required)
# @param string $api_key (optional)
# @param int $pet_id Pet id to delete (required)
# @return void
#
@ -449,8 +449,8 @@ sub delete_pet {
# uploads an image
#
# @param int $pet_id ID of pet to update (required)
# @param string $additional_metadata Additional data to pass to server (required)
# @param file $file file to upload (required)
# @param string $additional_metadata Additional data to pass to server (optional)
# @param file $file file to upload (optional)
# @return void
#
sub upload_file {

View File

@ -101,7 +101,7 @@ sub get_inventory {
#
# Place an order for a pet
#
# @param Order $body order placed for purchasing the pet (required)
# @param Order $body order placed for purchasing the pet (optional)
# @return Order
#
sub place_order {

View File

@ -52,7 +52,7 @@ sub new {
#
# Create user
#
# @param User $body Created user object (required)
# @param User $body Created user object (optional)
# @return void
#
sub create_user {
@ -102,7 +102,7 @@ sub create_user {
#
# Creates list of users with given input array
#
# @param ARRAY[User] $body List of user object (required)
# @param ARRAY[User] $body List of user object (optional)
# @return void
#
sub create_users_with_array_input {
@ -152,7 +152,7 @@ sub create_users_with_array_input {
#
# Creates list of users with given input array
#
# @param ARRAY[User] $body List of user object (required)
# @param ARRAY[User] $body List of user object (optional)
# @return void
#
sub create_users_with_list_input {
@ -202,8 +202,8 @@ sub create_users_with_list_input {
#
# Logs user into the system
#
# @param string $username The user name for login (required)
# @param string $password The password for login in clear text (required)
# @param string $username The user name for login (optional)
# @param string $password The password for login in clear text (optional)
# @return string
#
sub login_user {
@ -366,7 +366,7 @@ sub get_user_by_name {
# Updated user
#
# @param string $username name that need to be deleted (required)
# @param User $body Updated user object (required)
# @param User $body Updated user object (optional)
# @return void
#
sub update_user {