Skip to content

[scala-akka-client] Scala Akka client does not support arbitrary query string parameters #8610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"{{baseName}}", {{#isContainer}}ArrayValues({{{paramName}}}{{#collectionFormat}}, {{collectionFormat.toUpperCase}}{{/collectionFormat}}){{/isContainer}}{{^isContainer}}{{{paramName}}}{{/isContainer}}
{{#isMap}}{{baseName}}{{/isMap}}{{^isMap}}"{{baseName}}", {{#isContainer}}ArrayValues({{{paramName}}}{{#collectionFormat}}, {{collectionFormat.toUpperCase}}{{/collectionFormat}}){{/isContainer}}{{^isContainer}}{{{paramName}}}{{/isContainer}}{{/isMap}}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert this change as the local instance of the petstore server doesn't support https

}

class PetApi(baseUrl: String) {
Expand Down Expand Up @@ -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 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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move this method to samples/client/petstore/scala-akka/src/test/scala/PetApiTest.scala instead.


/**
* Returns a single pet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down Expand Up @@ -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)
}
}
}
}