diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java index 2d291924a7c7..fa18c5432fad 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaClientCodegen.java @@ -150,12 +150,13 @@ public void processOpts() { super.processOpts(); if (additionalProperties.containsKey("mainPackage")) { setMainPackage((String) additionalProperties.get("mainPackage")); + additionalProperties.replace("configKeyPath", this.configKeyPath); apiPackage = mainPackage + ".api"; modelPackage = mainPackage + ".model"; invokerPackage = mainPackage + ".core"; additionalProperties.put("apiPackage", apiPackage); - additionalProperties.put("modelPackage", apiPackage); - additionalProperties.put("invokerPackage", apiPackage); + additionalProperties.put("modelPackage", modelPackage); + additionalProperties.put("invokerPackage", invokerPackage); } supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); @@ -366,6 +367,6 @@ public String escapeQuotationMark(String input) { } public void setMainPackage(String mainPackage) { - this.mainPackage = mainPackage; + this.configKeyPath = this.mainPackage = mainPackage; } } diff --git a/modules/openapi-generator/src/main/resources/scala-akka-client/api.mustache b/modules/openapi-generator/src/main/resources/scala-akka-client/api.mustache index b9211855b8b6..506776b33a06 100644 --- a/modules/openapi-generator/src/main/resources/scala-akka-client/api.mustache +++ b/modules/openapi-generator/src/main/resources/scala-akka-client/api.mustache @@ -22,7 +22,7 @@ class {{classname}}(baseUrl: String) { {{/javadocRenderer}} def {{operationId}}({{>methodParameters}}): ApiRequest[{{>operationReturnType}}] = ApiRequest[{{>operationReturnType}}](ApiMethods.{{httpMethod.toUpperCase}}, baseUrl, "{{{path}}}", {{#consumes.0}}"{{{mediaType}}}"{{/consumes.0}}{{^consumes}}"application/json"{{/consumes}}) - {{#authMethods}}{{#isApiKey}}.withApiKey(apiKey, "{{keyParamName}}", {{#isKeyInQuery}}QUERY{{/isKeyInQuery}}{{#isKeyInHeader}}HEADER{{/isKeyInHeader}}) + {{#authMethods}}{{#isApiKey}}.withApiKey(apiKey, "{{keyParamName}}", {{#isKeyInQuery}}QUERY{{/isKeyInQuery}}{{#isKeyInHeader}}HEADER{{/isKeyInHeader}}{{#isKeyInCookie}}COOKIE{{/isKeyInCookie}}) {{/isApiKey}}{{#isBasic}}.withCredentials(basicAuth) {{/isBasic}}{{/authMethods}}{{#bodyParam}}.withBody({{paramName}}) {{/bodyParam}}{{#formParams}}.withFormParam({{>paramCreation}}) diff --git a/modules/openapi-generator/src/main/resources/scala-akka-client/apiInvoker.mustache b/modules/openapi-generator/src/main/resources/scala-akka-client/apiInvoker.mustache index 701f38ddbd7b..f987e857a3bb 100644 --- a/modules/openapi-generator/src/main/resources/scala-akka-client/apiInvoker.mustache +++ b/modules/openapi-generator/src/main/resources/scala-akka-client/apiInvoker.mustache @@ -45,7 +45,7 @@ object ApiInvoker { * * @param request the apiRequest to be executed */ - implicit class ApiRequestImprovements[T](request: ApiRequest[T]) { + implicit class ApiRequestImprovements[T: Manifest](request: ApiRequest[T]) { def response(invoker: ApiInvoker)(implicit ec: ExecutionContext, system: ActorSystem): Future[ApiResponse[T]] = response(ec, system, invoker) @@ -67,7 +67,7 @@ object ApiInvoker { def toAkkaHttpMethod: HttpMethod = HttpMethods.getForKey(method.value).getOrElse(HttpMethods.GET) } - case object DateTimeSerializer extends CustomSerializer[DateTime](format => ( { + case object DateTimeSerializer extends CustomSerializer[DateTime](_ => ( { case JString(s) => ISODateTimeFormat.dateOptionalTimeParser().parseDateTime(s) }, { @@ -215,7 +215,7 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC Uri(r.basePath + opPathWithParams).withQuery(query) } - def execute[T](r: ApiRequest[T]): Future[ApiResponse[T]] = { + def execute[T: Manifest](r: ApiRequest[T]): Future[ApiResponse[T]] = { implicit val timeout: Timeout = settings.connectionTimeout val request = createRequest(makeUri(r), r) @@ -239,8 +239,8 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC .flatMap(unmarshallApiResponse(r)) } - def unmarshallApiResponse[T](request: ApiRequest[T])(response: HttpResponse): Future[ApiResponse[T]] = { - def responseForState[V](state: ResponseState, value: V) = { + def unmarshallApiResponse[T: Manifest](request: ApiRequest[T])(response: HttpResponse): Future[ApiResponse[T]] = { + def responseForState[V](state: ResponseState, value: V): ApiResponse[V] = { state match { case ResponseState.Success => ApiResponse(response.status.intValue, value, response.headers.map(header => (header.name, header.value)).toMap) @@ -253,31 +253,29 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC ) } } - + val mf = implicitly(manifest[T]) request - .responseForCode(response.status.intValue) - .map { - case (Manifest.Unit, state: ResponseState) => - // FIXME Casting is ugly, how to do better? - Future(responseForState(state, Unit)).asInstanceOf[Future[ApiResponse[T]]] - case (manifest: Manifest[T], state: ResponseState) => - implicit val m: Unmarshaller[HttpEntity, T] = unmarshaller[T](manifest, serialization, formats) - - Unmarshal(response.entity) - .to[T] - .recoverWith { - case e ⇒ throw ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString), e) - } - .map(value => responseForState(state, value)) - } - .getOrElse(Future.failed(ApiError(response.status.intValue, "Unexpected response code", Some(response.entity.toString)))) + .responseForCode(response.status.intValue) match { + case Some((Manifest.Unit, state: ResponseState)) => + Future(responseForState(state, Unit).asInstanceOf[ApiResponse[T]]) + case Some((manifest, state: ResponseState)) if manifest == mf => + implicit val m: Unmarshaller[HttpEntity, T] = unmarshaller[T](mf, serialization, formats) + Unmarshal(response.entity) + .to[T] + .recoverWith { + case e ⇒ throw ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString), e) + } + .map(value => responseForState(state, value)) + case None | Some(_) => + Future.failed(ApiError(response.status.intValue, "Unexpected response code", Some(response.entity.toString))) + } } } sealed trait CustomContentTypes { protected def normalizedContentType(original: String): ContentType = - ContentType(MediaTypes.forExtension(original), () => HttpCharsets.`UTF-8`) + ContentType(parseContentType(original).mediaType, () => HttpCharsets.`UTF-8`) protected def parseContentType(contentType: String): ContentType = { diff --git a/modules/openapi-generator/src/main/resources/scala-akka-client/model.mustache b/modules/openapi-generator/src/main/resources/scala-akka-client/model.mustache index f4c9eb919fe2..d5e9b9d3876b 100644 --- a/modules/openapi-generator/src/main/resources/scala-akka-client/model.mustache +++ b/modules/openapi-generator/src/main/resources/scala-akka-client/model.mustache @@ -1,9 +1,10 @@ {{>licenseInfo}} package {{package}} +{{#imports}} +import {{import}} +{{/imports}} import {{mainPackage}}.core.ApiModel -import org.joda.time.DateTime -import java.util.UUID {{#models}} {{#model}} diff --git a/modules/openapi-generator/src/main/resources/scala-akka-client/requests.mustache b/modules/openapi-generator/src/main/resources/scala-akka-client/requests.mustache index 3f7e58056cbf..6c129147b73c 100644 --- a/modules/openapi-generator/src/main/resources/scala-akka-client/requests.mustache +++ b/modules/openapi-generator/src/main/resources/scala-akka-client/requests.mustache @@ -85,6 +85,8 @@ object ApiKeyLocations { case object HEADER extends ApiKeyLocation + case object COOKIE extends ApiKeyLocation + } diff --git a/modules/openapi-generator/src/test/resources/3_0/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/petstore.yaml index 88722011083e..8feeb2440f3e 100644 --- a/modules/openapi-generator/src/test/resources/3_0/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/petstore.yaml @@ -26,6 +26,15 @@ paths: description: '' operationId: addPet responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' '405': description: Invalid input security: @@ -41,6 +50,15 @@ paths: description: '' operationId: updatePet responses: + '200': + description: successful operation + content: + application/xml: + schema: + $ref: '#/components/schemas/Pet' + application/json: + schema: + $ref: '#/components/schemas/Pet' '400': description: Invalid ID supplied '404': diff --git a/modules/openapi-generator/src/test/resources/codegen/scala/SomeObj.scala.txt b/modules/openapi-generator/src/test/resources/codegen/scala/SomeObj.scala.txt index 52725e7e1236..bb7de3621217 100644 --- a/modules/openapi-generator/src/test/resources/codegen/scala/SomeObj.scala.txt +++ b/modules/openapi-generator/src/test/resources/codegen/scala/SomeObj.scala.txt @@ -11,9 +11,8 @@ */ package hello.world.model -import hello.world.core.ApiModel import org.joda.time.DateTime -import java.util.UUID +import hello.world.core.ApiModel case class SomeObj ( `type`: Option[SomeObjEnums.`Type`] = None, diff --git a/samples/client/petstore/scala-akka/README.md b/samples/client/petstore/scala-akka/README.md index a1ab296dc4d8..040074e90ff1 100644 --- a/samples/client/petstore/scala-akka/README.md +++ b/samples/client/petstore/scala-akka/README.md @@ -91,6 +91,8 @@ Class | Method | HTTP request | Description - [ApiResponse](ApiResponse.md) - [Category](Category.md) + - [InlineObject](InlineObject.md) + - [InlineObject1](InlineObject1.md) - [Order](Order.md) - [Pet](Pet.md) - [Tag](Tag.md) @@ -106,6 +108,12 @@ Authentication schemes defined for the API: - **API key parameter name**: api_key - **Location**: HTTP header +### auth_cookie + +- **Type**: API key +- **API key parameter name**: AUTH_KEY +- **Location**: + ## Author diff --git a/samples/client/petstore/scala-akka/project/build.properties b/samples/client/petstore/scala-akka/project/build.properties index c0bab04941d7..00b48d978b25 100644 --- a/samples/client/petstore/scala-akka/project/build.properties +++ b/samples/client/petstore/scala-akka/project/build.properties @@ -1 +1 @@ -sbt.version=1.2.8 +sbt.version=1.3.6 diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/PetApi.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/PetApi.scala index 658f7fb8fe31..df82ca29fca2 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/PetApi.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/PetApi.scala @@ -27,13 +27,15 @@ class PetApi(baseUrl: String) { /** * Expected answers: + * code 200 : Pet (successful operation) * code 405 : (Invalid input) * - * @param body Pet object that needs to be added to the store + * @param pet Pet object that needs to be added to the store */ - def addPet(body: Pet): ApiRequest[Unit] = - ApiRequest[Unit](ApiMethods.POST, baseUrl, "/pet", "application/json") - .withBody(body) + def addPet(pet: Pet): ApiRequest[Pet] = + ApiRequest[Pet](ApiMethods.POST, baseUrl, "/pet", "application/json") + .withBody(pet) + .withSuccessResponse[Pet](200) .withErrorResponse[Unit](405) @@ -107,15 +109,17 @@ class PetApi(baseUrl: String) { /** * Expected answers: + * code 200 : Pet (successful operation) * code 400 : (Invalid ID supplied) * code 404 : (Pet not found) * code 405 : (Validation exception) * - * @param body Pet object that needs to be added to the store + * @param pet Pet object that needs to be added to the store */ - def updatePet(body: Pet): ApiRequest[Unit] = - ApiRequest[Unit](ApiMethods.PUT, baseUrl, "/pet", "application/json") - .withBody(body) + def updatePet(pet: Pet): ApiRequest[Pet] = + ApiRequest[Pet](ApiMethods.PUT, baseUrl, "/pet", "application/json") + .withBody(pet) + .withSuccessResponse[Pet](200) .withErrorResponse[Unit](400) .withErrorResponse[Unit](404) .withErrorResponse[Unit](405) diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/StoreApi.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/StoreApi.scala index 534b3a4949a7..ba8a34ef6ec8 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/StoreApi.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/StoreApi.scala @@ -77,11 +77,11 @@ class StoreApi(baseUrl: String) { * code 200 : Order (successful operation) * code 400 : (Invalid Order) * - * @param body order placed for purchasing the pet + * @param order order placed for purchasing the pet */ - def placeOrder(body: Order): ApiRequest[Order] = + def placeOrder(order: Order): ApiRequest[Order] = ApiRequest[Order](ApiMethods.POST, baseUrl, "/store/order", "application/json") - .withBody(body) + .withBody(order) .withSuccessResponse[Order](200) .withErrorResponse[Unit](400) diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala index 7a1e796b70d4..7a784fd02985 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/api/UserApi.scala @@ -29,11 +29,15 @@ class UserApi(baseUrl: String) { * Expected answers: * code 0 : (successful operation) * - * @param body Created user object + * Available security schemes: + * auth_cookie (apiKey) + * + * @param user Created user object */ - def createUser(body: User): ApiRequest[Unit] = + def createUser(user: User)(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.POST, baseUrl, "/user", "application/json") - .withBody(body) + .withApiKey(apiKey, "AUTH_KEY", COOKIE) + .withBody(user) .withDefaultSuccessResponse[Unit] @@ -41,11 +45,15 @@ class UserApi(baseUrl: String) { * Expected answers: * code 0 : (successful operation) * - * @param body List of user object + * Available security schemes: + * auth_cookie (apiKey) + * + * @param user List of user object */ - def createUsersWithArrayInput(body: Seq[User]): ApiRequest[Unit] = + def createUsersWithArrayInput(user: Seq[User])(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.POST, baseUrl, "/user/createWithArray", "application/json") - .withBody(body) + .withApiKey(apiKey, "AUTH_KEY", COOKIE) + .withBody(user) .withDefaultSuccessResponse[Unit] @@ -53,11 +61,15 @@ class UserApi(baseUrl: String) { * Expected answers: * code 0 : (successful operation) * - * @param body List of user object + * Available security schemes: + * auth_cookie (apiKey) + * + * @param user List of user object */ - def createUsersWithListInput(body: Seq[User]): ApiRequest[Unit] = + def createUsersWithListInput(user: Seq[User])(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.POST, baseUrl, "/user/createWithList", "application/json") - .withBody(body) + .withApiKey(apiKey, "AUTH_KEY", COOKIE) + .withBody(user) .withDefaultSuccessResponse[Unit] @@ -68,10 +80,14 @@ class UserApi(baseUrl: String) { * code 400 : (Invalid username supplied) * code 404 : (User not found) * + * Available security schemes: + * auth_cookie (apiKey) + * * @param username The name that needs to be deleted */ - def deleteUser(username: String): ApiRequest[Unit] = + def deleteUser(username: String)(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.DELETE, baseUrl, "/user/{username}", "application/json") + .withApiKey(apiKey, "AUTH_KEY", COOKIE) .withPathParam("username", username) .withErrorResponse[Unit](400) .withErrorResponse[Unit](404) @@ -97,6 +113,7 @@ class UserApi(baseUrl: String) { * Expected answers: * code 200 : String (successful operation) * Headers : + * Set-Cookie - Cookie authentication key for use with the `auth_cookie` apiKey authentication. * X-Rate-Limit - calls per hour allowed by the user * X-Expires-After - date in UTC when toekn expires * code 400 : (Invalid username/password supplied) @@ -112,6 +129,7 @@ class UserApi(baseUrl: String) { .withErrorResponse[Unit](400) object LoginUserHeaders { + def setCookie(r: ApiReturnWithHeaders) = r.getStringHeader("Set-Cookie") def xRateLimit(r: ApiReturnWithHeaders) = r.getIntHeader("X-Rate-Limit") def xExpiresAfter(r: ApiReturnWithHeaders) = r.getDateTimeHeader("X-Expires-After") } @@ -119,9 +137,13 @@ class UserApi(baseUrl: String) { /** * Expected answers: * code 0 : (successful operation) + * + * Available security schemes: + * auth_cookie (apiKey) */ - def logoutUser(): ApiRequest[Unit] = + def logoutUser()(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.GET, baseUrl, "/user/logout", "application/json") + .withApiKey(apiKey, "AUTH_KEY", COOKIE) .withDefaultSuccessResponse[Unit] @@ -132,12 +154,16 @@ class UserApi(baseUrl: String) { * code 400 : (Invalid user supplied) * code 404 : (User not found) * + * Available security schemes: + * auth_cookie (apiKey) + * * @param username name that need to be deleted - * @param body Updated user object + * @param user Updated user object */ - def updateUser(username: String, body: User): ApiRequest[Unit] = + def updateUser(username: String, user: User)(implicit apiKey: ApiKeyValue): ApiRequest[Unit] = ApiRequest[Unit](ApiMethods.PUT, baseUrl, "/user/{username}", "application/json") - .withBody(body) + .withApiKey(apiKey, "AUTH_KEY", COOKIE) + .withBody(user) .withPathParam("username", username) .withErrorResponse[Unit](400) .withErrorResponse[Unit](404) diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiInvoker.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiInvoker.scala index 8b6eeee0bb51..cd23dc723d68 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiInvoker.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiInvoker.scala @@ -55,7 +55,7 @@ object ApiInvoker { * * @param request the apiRequest to be executed */ - implicit class ApiRequestImprovements[T](request: ApiRequest[T]) { + implicit class ApiRequestImprovements[T: Manifest](request: ApiRequest[T]) { def response(invoker: ApiInvoker)(implicit ec: ExecutionContext, system: ActorSystem): Future[ApiResponse[T]] = response(ec, system, invoker) @@ -77,7 +77,7 @@ object ApiInvoker { def toAkkaHttpMethod: HttpMethod = HttpMethods.getForKey(method.value).getOrElse(HttpMethods.GET) } - case object DateTimeSerializer extends CustomSerializer[DateTime](format => ( { + case object DateTimeSerializer extends CustomSerializer[DateTime](_ => ( { case JString(s) => ISODateTimeFormat.dateOptionalTimeParser().parseDateTime(s) }, { @@ -225,7 +225,7 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC Uri(r.basePath + opPathWithParams).withQuery(query) } - def execute[T](r: ApiRequest[T]): Future[ApiResponse[T]] = { + def execute[T: Manifest](r: ApiRequest[T]): Future[ApiResponse[T]] = { implicit val timeout: Timeout = settings.connectionTimeout val request = createRequest(makeUri(r), r) @@ -249,8 +249,8 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC .flatMap(unmarshallApiResponse(r)) } - def unmarshallApiResponse[T](request: ApiRequest[T])(response: HttpResponse): Future[ApiResponse[T]] = { - def responseForState[V](state: ResponseState, value: V) = { + def unmarshallApiResponse[T: Manifest](request: ApiRequest[T])(response: HttpResponse): Future[ApiResponse[T]] = { + def responseForState[V](state: ResponseState, value: V): ApiResponse[V] = { state match { case ResponseState.Success => ApiResponse(response.status.intValue, value, response.headers.map(header => (header.name, header.value)).toMap) @@ -263,31 +263,29 @@ class ApiInvoker(formats: Formats)(implicit system: ActorSystem) extends CustomC ) } } - + val mf = implicitly(manifest[T]) request - .responseForCode(response.status.intValue) - .map { - case (Manifest.Unit, state: ResponseState) => - // FIXME Casting is ugly, how to do better? - Future(responseForState(state, Unit)).asInstanceOf[Future[ApiResponse[T]]] - case (manifest: Manifest[T], state: ResponseState) => - implicit val m: Unmarshaller[HttpEntity, T] = unmarshaller[T](manifest, serialization, formats) - - Unmarshal(response.entity) - .to[T] - .recoverWith { - case e ⇒ throw ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString), e) - } - .map(value => responseForState(state, value)) - } - .getOrElse(Future.failed(ApiError(response.status.intValue, "Unexpected response code", Some(response.entity.toString)))) + .responseForCode(response.status.intValue) match { + case Some((Manifest.Unit, state: ResponseState)) => + Future(responseForState(state, Unit).asInstanceOf[ApiResponse[T]]) + case Some((manifest, state: ResponseState)) if manifest == mf => + implicit val m: Unmarshaller[HttpEntity, T] = unmarshaller[T](mf, serialization, formats) + Unmarshal(response.entity) + .to[T] + .recoverWith { + case e ⇒ throw ApiError(response.status.intValue, s"Unable to unmarshall content to [$manifest]", Some(response.entity.toString), e) + } + .map(value => responseForState(state, value)) + case None | Some(_) => + Future.failed(ApiError(response.status.intValue, "Unexpected response code", Some(response.entity.toString))) + } } } sealed trait CustomContentTypes { protected def normalizedContentType(original: String): ContentType = - ContentType(MediaTypes.forExtension(original), () => HttpCharsets.`UTF-8`) + ContentType(parseContentType(original).mediaType, () => HttpCharsets.`UTF-8`) protected def parseContentType(contentType: String): ContentType = { diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/requests.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/requests.scala index 155a86dcf112..b0b56b97fd73 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/requests.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/requests.scala @@ -95,6 +95,8 @@ object ApiKeyLocations { case object HEADER extends ApiKeyLocation + case object COOKIE extends ApiKeyLocation + } diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/ApiResponse.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/ApiResponse.scala index 0ef406429cbb..3ddf32c9bda7 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/ApiResponse.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/ApiResponse.scala @@ -12,8 +12,6 @@ package org.openapitools.client.model import org.openapitools.client.core.ApiModel -import org.joda.time.DateTime -import java.util.UUID case class ApiResponse ( code: Option[Int] = None, diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Category.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Category.scala index 23ba74821501..e62645a38b2a 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Category.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Category.scala @@ -12,8 +12,6 @@ package org.openapitools.client.model import org.openapitools.client.core.ApiModel -import org.joda.time.DateTime -import java.util.UUID case class Category ( id: Option[Long] = None, diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/InlineObject.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/InlineObject.scala new file mode 100644 index 000000000000..3d9ec200c9fc --- /dev/null +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/InlineObject.scala @@ -0,0 +1,23 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.client.model + +import org.openapitools.client.core.ApiModel + +case class InlineObject ( + /* Updated name of the pet */ + name: Option[String] = None, + /* Updated status of the pet */ + status: Option[String] = None +) extends ApiModel + + diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/InlineObject1.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/InlineObject1.scala new file mode 100644 index 000000000000..c41794c43d43 --- /dev/null +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/InlineObject1.scala @@ -0,0 +1,24 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package org.openapitools.client.model + +import java.io.File +import org.openapitools.client.core.ApiModel + +case class InlineObject1 ( + /* Additional data to pass to server */ + additionalMetadata: Option[String] = None, + /* file to upload */ + file: Option[File] = None +) extends ApiModel + + diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Order.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Order.scala index 83055706fd1d..6a9fdc141f08 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Order.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Order.scala @@ -11,9 +11,8 @@ */ package org.openapitools.client.model -import org.openapitools.client.core.ApiModel import org.joda.time.DateTime -import java.util.UUID +import org.openapitools.client.core.ApiModel case class Order ( id: Option[Long] = None, diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Pet.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Pet.scala index 1f78a72e57ba..3a78a7c3f183 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Pet.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Pet.scala @@ -12,8 +12,6 @@ package org.openapitools.client.model import org.openapitools.client.core.ApiModel -import org.joda.time.DateTime -import java.util.UUID case class Pet ( id: Option[Long] = None, diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Tag.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Tag.scala index 30dfbf441914..ac0c7763720c 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Tag.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/Tag.scala @@ -12,8 +12,6 @@ package org.openapitools.client.model import org.openapitools.client.core.ApiModel -import org.joda.time.DateTime -import java.util.UUID case class Tag ( id: Option[Long] = None, diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/User.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/User.scala index 0d33ce64753e..aad2117b16d5 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/User.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/model/User.scala @@ -12,8 +12,6 @@ package org.openapitools.client.model import org.openapitools.client.core.ApiModel -import org.joda.time.DateTime -import java.util.UUID case class User ( id: Option[Long] = None, diff --git a/samples/client/petstore/scala-akka/src/test/scala/PetApiTest.scala b/samples/client/petstore/scala-akka/src/test/scala/PetApiTest.scala index 2cbdacd506ac..9327a6d7585d 100644 --- a/samples/client/petstore/scala-akka/src/test/scala/PetApiTest.scala +++ b/samples/client/petstore/scala-akka/src/test/scala/PetApiTest.scala @@ -2,7 +2,7 @@ import akka.actor.ActorSystem import org.junit.runner.RunWith import org.openapitools.client._ import org.openapitools.client.api._ -import org.openapitools.client.core.{ ApiInvoker, ApiKeyValue } +import org.openapitools.client.core.{ApiInvoker, ApiKeyValue} import org.openapitools.client.model._ import org.scalatest.Inspectors._ import org.scalatest._ @@ -14,8 +14,8 @@ class PetApiTest extends AsyncFlatSpec with Matchers { private implicit val system: ActorSystem = ActorSystem() behavior of "PetApi" - val api = PetApi() - val invoker = ApiInvoker() + val api: PetApi = PetApi() + val invoker: ApiInvoker = ApiInvoker(EnumsSerializers.all) private implicit val apiKey: ApiKeyValue = ApiKeyValue("special-key") it should "add and fetch a pet" in { @@ -54,7 +54,7 @@ class PetApiTest extends AsyncFlatSpec with Matchers { } it should "update a pet" in { - val petId = Math.random().toInt + val petId = (Math.random()*1000000000).toLong val createdPet = Pet( Some(petId), Some(Category(Some(1), Some("sold"))), @@ -64,19 +64,24 @@ class PetApiTest extends AsyncFlatSpec with Matchers { Some(PetEnums.Status.Available) ) - for { - _ <- invoker.execute(api.addPet(createdPet)) - pet: core.ApiResponse[Pet] <- invoker.execute(api.getPetById(petId)) - updatedPet = pet.content.copy(status = Some(PetEnums.Status.Sold)) - _ <- invoker.execute(api.updatePet(updatedPet)) - updatedRequested <- invoker.execute(api.getPetById(petId)) + for { + createdPet <- invoker.execute(api.addPet(createdPet)) + pet: core.ApiResponse[Pet] <- invoker.execute(api.getPetById(createdPet.content.id.get)) + updatedPet = pet.content.copy(status = Some(PetEnums.Status.Sold), name = "developer") + updatedPetResponse: core.ApiResponse[Pet] <- invoker.execute(api.updatePet(updatedPet)) + updatedRequested: core.ApiResponse[Pet] <- invoker.execute(api.getPetById(createdPet.content.id.get)) } yield { pet.content.name should be("programmer") pet.content.status should be(Some(PetEnums.Status.Available)) - updatedRequested.content.name should be("programmer") + updatedPetResponse.content.name should be("developer") + updatedPetResponse.content.status should be(Some(PetEnums.Status.Sold)) + + updatedRequested.content.name should be("developer") updatedRequested.content.status should be(Some(PetEnums.Status.Sold)) + } + } it should "find pets by status" in { @@ -90,7 +95,7 @@ class PetApiTest extends AsyncFlatSpec with Matchers { pets should not be empty forAll(pets) { pet => - pet.status should contain("available") + pet.status should contain(PetEnums.Status.Available) } } }