From 97aaddce538452dbd545fe0f184f4f88a9a86038 Mon Sep 17 00:00:00 2001 From: ameenhaq Date: Thu, 4 Feb 2021 09:04:27 +0000 Subject: [PATCH 1/6] Add check for input if is Map type --- .../src/main/resources/scala-akka-client/apiRequest.mustache | 2 ++ .../src/main/resources/scala-akka-client/paramCreation.mustache | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/scala-akka-client/apiRequest.mustache b/modules/openapi-generator/src/main/resources/scala-akka-client/apiRequest.mustache index fd2ba29ea0bd..10be69afa959 100644 --- a/modules/openapi-generator/src/main/resources/scala-akka-client/apiRequest.mustache +++ b/modules/openapi-generator/src/main/resources/scala-akka-client/apiRequest.mustache @@ -49,6 +49,8 @@ case class ApiRequest[U]( def withPathParam(name: String, value: Any): ApiRequest[U] = copy[U](pathParams = pathParams + (name -> value)) + def withQueryParam(values: Map[String, Any]): ApiRequest[U] = copy[U](queryParams = queryParams ++ values) + def withQueryParam(name: String, value: Any): ApiRequest[U] = copy[U](queryParams = queryParams + (name -> value)) def withHeaderParam(name: String, value: Any): ApiRequest[U] = copy[U](headerParams = headerParams + (name -> value)) diff --git a/modules/openapi-generator/src/main/resources/scala-akka-client/paramCreation.mustache b/modules/openapi-generator/src/main/resources/scala-akka-client/paramCreation.mustache index 68280bd9a36b..dc7bbc9f434e 100644 --- a/modules/openapi-generator/src/main/resources/scala-akka-client/paramCreation.mustache +++ b/modules/openapi-generator/src/main/resources/scala-akka-client/paramCreation.mustache @@ -1 +1 @@ -"{{baseName}}", {{#isContainer}}ArrayValues({{{paramName}}}{{#collectionFormat}}, {{collectionFormat.toUpperCase}}{{/collectionFormat}}){{/isContainer}}{{^isContainer}}{{{paramName}}}{{/isContainer}} \ No newline at end of file +{{#isMap}}{{baseName}}{{/isMap}}{{^isMap}}"{{baseName}}", {{#isContainer}}ArrayValues({{{paramName}}}{{#collectionFormat}}, {{collectionFormat.toUpperCase}}{{/collectionFormat}}){{/isContainer}}{{^isContainer}}{{{paramName}}}{{/isContainer}}{{/isMap}} \ No newline at end of file From f374b2285b849b71d1ab5a5e452037ff01648058 Mon Sep 17 00:00:00 2001 From: ameenhaq Date: Mon, 8 Feb 2021 12:31:50 +0000 Subject: [PATCH 2/6] Update Pet samples --- .../main/scala/org/openapitools/client/core/ApiRequest.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiRequest.scala b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiRequest.scala index 3dfa61094de0..d6f5ae6182e3 100644 --- a/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiRequest.scala +++ b/samples/client/petstore/scala-akka/src/main/scala/org/openapitools/client/core/ApiRequest.scala @@ -59,6 +59,8 @@ case class ApiRequest[U]( def withPathParam(name: String, value: Any): ApiRequest[U] = copy[U](pathParams = pathParams + (name -> value)) + def withQueryParam(values: Map[String, Any]): ApiRequest[U] = copy[U](queryParams = queryParams ++ values) + def withQueryParam(name: String, value: Any): ApiRequest[U] = copy[U](queryParams = queryParams + (name -> value)) def withHeaderParam(name: String, value: Any): ApiRequest[U] = copy[U](headerParams = headerParams + (name -> value)) From 62220fe3c54d87938d1f867041a111d4d173462d Mon Sep 17 00:00:00 2001 From: ameenhaq Date: Tue, 23 Feb 2021 14:50:55 +0000 Subject: [PATCH 3/6] Add PetApi support for filter by Pet property --- samples/client/petstore/scala-akka/README.md | 1 + .../org/openapitools/client/api/PetApi.scala | 20 +++++++++++++++++-- .../src/test/scala/PetApiTest.scala | 16 ++++++++++++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/samples/client/petstore/scala-akka/README.md b/samples/client/petstore/scala-akka/README.md index cc830a260e35..365ca5ddbdd2 100644 --- a/samples/client/petstore/scala-akka/README.md +++ b/samples/client/petstore/scala-akka/README.md @@ -69,6 +69,7 @@ Class | Method | HTTP request | Description *PetApi* | **deletePet** | **DELETE** /pet/{petId} | Deletes a pet *PetApi* | **findPetsByStatus** | **GET** /pet/findByStatus | Finds Pets by status *PetApi* | **findPetsByTags** | **GET** /pet/findByTags | Finds Pets by tags +*PetApi* | **findPetsByFilters** | **GET** /pet/findPetsByFilters | Finds Pets by tags *PetApi* | **getPetById** | **GET** /pet/{petId} | Find pet by ID *PetApi* | **updatePet** | **PUT** /pet | Update an existing pet *PetApi* | **updatePetWithForm** | **POST** /pet/{petId} | Updates a pet in the store with form data 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 c0ba5d4c6ae2..c69b51814d40 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 @@ -20,7 +20,7 @@ import org.openapitools.client.core.ApiKeyLocations._ object PetApi { - def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new PetApi(baseUrl) + def apply(baseUrl: String = "https://petstore.swagger.io/v2") = new PetApi(baseUrl) } class PetApi(baseUrl: String) { @@ -83,7 +83,23 @@ class PetApi(baseUrl: String) { .withQueryParam("tags", ArrayValues(tags, CSV)) .withSuccessResponse[Seq[Pet]](200) .withErrorResponse[Unit](400) - + + + /** + * Filter by multiple Pet properties via Map + * + * Expected answers: + * code 200 : Seq[Pet] (successful operation) + * code 400 : (Invalid tag value) + * + * @param filters Pet properties to filter by + */ + def findPetsByArbitraryFilters(filters: Map[String, Any]): ApiRequest[Seq[Pet]] = + ApiRequest[Seq[Pet]](ApiMethods.GET, baseUrl, "/pet/findByStatus", "application/json") + .withQueryParam(filters) + .withSuccessResponse[Seq[Pet]](200) + .withErrorResponse[Unit](400) + /** * Returns a single pet 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 e6229fb05f3a..74e577eb6542 100644 --- a/samples/client/petstore/scala-akka/src/test/scala/PetApiTest.scala +++ b/samples/client/petstore/scala-akka/src/test/scala/PetApiTest.scala @@ -86,7 +86,6 @@ class PetApiTest extends AsyncFlatSpec with Matchers { it should "find pets by status" in { val request = api.findPetsByStatus(List("available")) - invoker .execute(request) .map { apiResponse => @@ -119,5 +118,20 @@ class PetApiTest extends AsyncFlatSpec with Matchers { } } */ + + it should "find pets by arbitrary filter" in { + val request = api.findPetsByArbitraryFilters(Map("status" -> "available")) + invoker + .execute(request) + .map { apiResponse => + apiResponse.code should be(200) + val pets = apiResponse.content + pets should not be empty + + forAll(pets) { pet => + pet.status should contain(PetEnums.Status.Available) + } + } + } } From fea602ef4fdaa11a105a01381b1c61d4bf9a11b7 Mon Sep 17 00:00:00 2001 From: ameenhaq Date: Fri, 26 Feb 2021 01:00:36 +0000 Subject: [PATCH 4/6] Clean up --- samples/client/petstore/scala-akka/README.md | 1 - .../src/main/scala/org/openapitools/client/api/PetApi.scala | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/samples/client/petstore/scala-akka/README.md b/samples/client/petstore/scala-akka/README.md index 365ca5ddbdd2..cc830a260e35 100644 --- a/samples/client/petstore/scala-akka/README.md +++ b/samples/client/petstore/scala-akka/README.md @@ -69,7 +69,6 @@ Class | Method | HTTP request | Description *PetApi* | **deletePet** | **DELETE** /pet/{petId} | Deletes a pet *PetApi* | **findPetsByStatus** | **GET** /pet/findByStatus | Finds Pets by status *PetApi* | **findPetsByTags** | **GET** /pet/findByTags | Finds Pets by tags -*PetApi* | **findPetsByFilters** | **GET** /pet/findPetsByFilters | Finds Pets by tags *PetApi* | **getPetById** | **GET** /pet/{petId} | Find pet by ID *PetApi* | **updatePet** | **PUT** /pet | Update an existing pet *PetApi* | **updatePetWithForm** | **POST** /pet/{petId} | Updates a pet in the store with form data 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 c69b51814d40..3e677f9bea93 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 @@ -86,11 +86,11 @@ class PetApi(baseUrl: String) { /** - * Filter by multiple Pet properties via Map + * Filter by multiple Pet properties using Map * * Expected answers: * code 200 : Seq[Pet] (successful operation) - * code 400 : (Invalid tag value) + * code 400 : (Invalid property) * * @param filters Pet properties to filter by */ From a3c47c5fcec00ad034295a89cd0364c7203c275e Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 13 Dec 2023 15:45:03 +0800 Subject: [PATCH 5/6] update samples --- .../org/openapitools/client/api/PetApi.scala | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) 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 bc87adb2870b..f2467942f84a 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 @@ -20,7 +20,7 @@ import org.openapitools.client.core.ApiKeyLocations._ object PetApi { - def apply(baseUrl: String = "https://petstore.swagger.io/v2") = new PetApi(baseUrl) + def apply(baseUrl: String = "http://petstore.swagger.io/v2") = new PetApi(baseUrl) } class PetApi(baseUrl: String) { @@ -87,23 +87,7 @@ class PetApi(baseUrl: String) { .withQueryParam("tags", ArrayValues(tags, CSV)) .withSuccessResponse[Seq[Pet]](200) .withErrorResponse[Unit](400) - - - /** - * Filter by multiple Pet properties using Map - * - * Expected answers: - * code 200 : Seq[Pet] (successful operation) - * code 400 : (Invalid property) - * - * @param filters Pet properties to filter by - */ - def findPetsByArbitraryFilters(filters: Map[String, Any]): ApiRequest[Seq[Pet]] = - ApiRequest[Seq[Pet]](ApiMethods.GET, baseUrl, "/pet/findByStatus", "application/json") - .withQueryParam(filters) - .withSuccessResponse[Seq[Pet]](200) - .withErrorResponse[Unit](400) - + /** * Returns a single pet From 25b310e87bb905b49d19be6677cd5beb1f949a76 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 13 Dec 2023 15:51:43 +0800 Subject: [PATCH 6/6] remove manual test --- .../scala-akka/src/test/scala/PetApiTest.scala | 15 --------------- 1 file changed, 15 deletions(-) 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 00f8c9f9bfd6..15bec1fea3ba 100644 --- a/samples/client/petstore/scala-akka/src/test/scala/PetApiTest.scala +++ b/samples/client/petstore/scala-akka/src/test/scala/PetApiTest.scala @@ -119,19 +119,4 @@ class PetApiTest extends AsyncFlatSpec with Matchers { } } */ - - it should "find pets by arbitrary filter" in { - val request = api.findPetsByArbitraryFilters(Map("status" -> "available")) - invoker - .execute(request) - .map { apiResponse => - apiResponse.code should be(200) - val pets = apiResponse.content - pets should not be empty - - forAll(pets) { pet => - pet.status should contain(PetEnums.Status.Available) - } - } - } }