forked from loafle/openapi-generator-original
Fixed bug for handling optional header parameters (#3776)
* Fixed #3774 Refactored code to handle optional header parameters. * Changed null check with pattern matching
This commit is contained in:
parent
fe7acabc4b
commit
1e4f30eb16
@ -25,23 +25,34 @@ class {{classname}}(client: TransportClient, config: SwaggerConfig) extends ApiC
|
||||
{{#required}}
|
||||
{{^isPrimitiveType}}
|
||||
if ({{paramName}} == null) throw new Exception("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}")
|
||||
|
||||
{{/isPrimitiveType}}
|
||||
{{#isString}}
|
||||
if ({{paramName}} == null) throw new Exception("Missing required parameter '{{paramName}}' when calling {{classname}}->{{operationId}}")
|
||||
|
||||
{{/isString}}
|
||||
{{/required}}
|
||||
{{/allParams}}
|
||||
{{#queryParams}}
|
||||
{{^required}}
|
||||
if ({{paramName}} != null) {{paramName}}.foreach { v => queryParams += "{{baseName}}" -> v.toString }
|
||||
|
||||
{{paramName}} match {
|
||||
case Some(param) => queryParams += "{{baseName}}" -> param.toString
|
||||
case _ => queryParams
|
||||
}
|
||||
{{/required}}
|
||||
{{#required}}
|
||||
if ({{paramName}} != null) queryParams += "{{baseName}}" -> {{paramName}}.toString
|
||||
|
||||
queryParams += "{{baseName}}" -> {{paramName}}.toString
|
||||
{{/required}}
|
||||
{{/queryParams}}
|
||||
|
||||
{{#headerParams}}
|
||||
{{^required}}
|
||||
{{paramName}} match {
|
||||
case Some(param) => headerParams += "{{baseName}}" -> param.toString
|
||||
case _ => headerParams
|
||||
}
|
||||
{{/required}}
|
||||
{{#required}}
|
||||
headerParams += "{{baseName}}" -> {{paramName}}.toString
|
||||
{{/required}}
|
||||
{{/headerParams}}
|
||||
|
||||
val resFuture = client.submit("{{httpMethod}}", path, queryParams.toMap, headerParams.toMap, {{#bodyParam}}writer.write({{paramName}}){{/bodyParam}}{{^bodyParam}}"{{emptyBodyParam}}"{{/bodyParam}})
|
||||
|
@ -19,8 +19,6 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
|
||||
|
||||
if (body == null) throw new Exception("Missing required parameter 'body' when calling PetApi->addPet")
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
@ -38,8 +36,10 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
headerParams += "api_key" -> apiKey.toString
|
||||
apiKey match {
|
||||
case Some(param) => headerParams += "api_key" -> param.toString
|
||||
case _ => headerParams
|
||||
}
|
||||
|
||||
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
@ -56,10 +56,7 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
if (status == null) throw new Exception("Missing required parameter 'status' when calling PetApi->findPetsByStatus")
|
||||
|
||||
if (status != null) queryParams += "status" -> status.toString
|
||||
|
||||
|
||||
queryParams += "status" -> status.toString
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
@ -76,10 +73,7 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
if (tags == null) throw new Exception("Missing required parameter 'tags' when calling PetApi->findPetsByTags")
|
||||
|
||||
if (tags != null) queryParams += "tags" -> tags.toString
|
||||
|
||||
|
||||
queryParams += "tags" -> tags.toString
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
@ -97,7 +91,6 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
@ -114,8 +107,6 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
|
||||
|
||||
if (body == null) throw new Exception("Missing required parameter 'body' when calling PetApi->updatePet")
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
@ -135,7 +126,6 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
@ -155,7 +145,6 @@ class PetApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(c
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
|
@ -16,6 +16,7 @@ class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
if (orderId == null) throw new Exception("Missing required parameter 'orderId' when calling StoreApi->deleteOrder")
|
||||
|
||||
|
||||
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
|
||||
@ -33,7 +34,6 @@ class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
@ -50,7 +50,6 @@ class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
@ -67,8 +66,6 @@ class StoreApi(client: TransportClient, config: SwaggerConfig) extends ApiClient
|
||||
|
||||
if (body == null) throw new Exception("Missing required parameter 'body' when calling StoreApi->placeOrder")
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
|
@ -17,8 +17,6 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
|
||||
|
||||
if (body == null) throw new Exception("Missing required parameter 'body' when calling UserApi->createUser")
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
@ -35,8 +33,6 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
|
||||
|
||||
if (body == null) throw new Exception("Missing required parameter 'body' when calling UserApi->createUsersWithArrayInput")
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
@ -53,8 +49,6 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
|
||||
|
||||
if (body == null) throw new Exception("Missing required parameter 'body' when calling UserApi->createUsersWithListInput")
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("POST", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
@ -70,6 +64,7 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
if (username == null) throw new Exception("Missing required parameter 'username' when calling UserApi->deleteUser")
|
||||
|
||||
|
||||
val resFuture = client.submit("DELETE", path, queryParams.toMap, headerParams.toMap, "")
|
||||
@ -87,6 +82,7 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
if (username == null) throw new Exception("Missing required parameter 'username' when calling UserApi->getUserByName")
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
@ -104,11 +100,12 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
if (username != null) queryParams += "username" -> username.toString
|
||||
|
||||
if (password != null) queryParams += "password" -> password.toString
|
||||
if (username == null) throw new Exception("Missing required parameter 'username' when calling UserApi->loginUser")
|
||||
|
||||
if (password == null) throw new Exception("Missing required parameter 'password' when calling UserApi->loginUser")
|
||||
|
||||
queryParams += "username" -> username.toString
|
||||
queryParams += "password" -> password.toString
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
@ -125,7 +122,6 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
|
||||
val headerParams = new mutable.HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("GET", path, queryParams.toMap, headerParams.toMap, "")
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
@ -142,10 +138,10 @@ class UserApi(client: TransportClient, config: SwaggerConfig) extends ApiClient(
|
||||
val queryParams = new mutable.HashMap[String, String]
|
||||
val headerParams = new mutable.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")
|
||||
|
||||
|
||||
|
||||
val resFuture = client.submit("PUT", path, queryParams.toMap, headerParams.toMap, writer.write(body))
|
||||
resFuture flatMap { resp =>
|
||||
process(reader.read(resp))
|
||||
|
@ -1,18 +1,17 @@
|
||||
import io.swagger.client._
|
||||
import io.swagger.client.api._
|
||||
import io.swagger.client.model._
|
||||
|
||||
import java.net.URI
|
||||
|
||||
import com.wordnik.swagger.client.ClientResponseReaders.Json4sFormatsReader._
|
||||
import com.wordnik.swagger.client.RequestWriters.Json4sFormatsWriter._
|
||||
import com.wordnik.swagger.client.SwaggerConfig
|
||||
import io.swagger.client.SwaggerClient
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest._
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
|
||||
import scala.concurrent.ExecutionContext.Implicits.global
|
||||
import scala.concurrent._
|
||||
import scala.concurrent.duration._
|
||||
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])
|
||||
class SimpleTest extends FlatSpec with Matchers {
|
||||
|
Loading…
x
Reference in New Issue
Block a user