From c6e7de1bc86b9d02d47bba6f9c44ae3987878b1f Mon Sep 17 00:00:00 2001 From: Lintterer Date: Wed, 21 Aug 2024 08:50:03 +0200 Subject: [PATCH 1/2] feat: adding query url form encoding to smithy client endpoint --- .../smithy4play/client/SmithyPlayClientEndpoint.scala | 8 +++++--- smithy4playTest/test/TestControllerTest.scala | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/smithy4play/src/main/scala/de/innfactory/smithy4play/client/SmithyPlayClientEndpoint.scala b/smithy4play/src/main/scala/de/innfactory/smithy4play/client/SmithyPlayClientEndpoint.scala index 0f96e64f..3bdd8cc9 100644 --- a/smithy4play/src/main/scala/de/innfactory/smithy4play/client/SmithyPlayClientEndpoint.scala +++ b/smithy4play/src/main/scala/de/innfactory/smithy4play/client/SmithyPlayClientEndpoint.scala @@ -5,9 +5,11 @@ package client import cats.implicits._ import smithy4s.codecs.PayloadError import smithy4s.http._ -import smithy4s.{ Blob, Endpoint, Hints, Schema } +import smithy4s.{Blob, Endpoint, Hints, Schema} -import scala.concurrent.{ ExecutionContext, Future } +import java.net.URLEncoder +import java.nio.charset.StandardCharsets +import scala.concurrent.{ExecutionContext, Future} private[smithy4play] class SmithyPlayClientEndpoint[Op[_, _, _, _, _], I, E, O, SI, SO]( endpoint: Endpoint[Op, I, E, O, SI, SO], @@ -97,7 +99,7 @@ private[smithy4play] class SmithyPlayClientEndpoint[Op[_, _, _, _, _], I, E, O, def buildPath(metadata: Metadata): String = baseUri + httpEndpoint.path(input).mkString("/") + metadata.queryFlattened - .map(s => s._1 + "=" + s._2) + .map(s => URLEncoder.encode(s._1, StandardCharsets.UTF_8.name()) + "=" + URLEncoder.encode(s._2, StandardCharsets.UTF_8.name())) .mkString("?", "&", "") } diff --git a/smithy4playTest/test/TestControllerTest.scala b/smithy4playTest/test/TestControllerTest.scala index f03ea09c..e432814d 100644 --- a/smithy4playTest/test/TestControllerTest.scala +++ b/smithy4playTest/test/TestControllerTest.scala @@ -57,7 +57,7 @@ class TestControllerTest extends TestBase { "route to Test Endpoint by SmithyTestClient with Query Parameter, Path Parameter and Body" in { val pathParam = "thisIsAPathParam" - val testQuery = "thisIsATestQuery" + val testQuery = "this Is A Test Query" val testHeader = "thisIsATestHeader" val body = TestRequestBody("thisIsARequestBody") val result = genericClient.testWithOutput(pathParam, testQuery, testHeader, body).awaitRight From 51f52fd2a0e2cc5121d3d22899f7e8ac13e8e440 Mon Sep 17 00:00:00 2001 From: Lintterer Date: Wed, 21 Aug 2024 09:00:40 +0200 Subject: [PATCH 2/2] chore: scalafmt --- .../smithy4play/client/SmithyPlayClientEndpoint.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/smithy4play/src/main/scala/de/innfactory/smithy4play/client/SmithyPlayClientEndpoint.scala b/smithy4play/src/main/scala/de/innfactory/smithy4play/client/SmithyPlayClientEndpoint.scala index 3bdd8cc9..92ce58ee 100644 --- a/smithy4play/src/main/scala/de/innfactory/smithy4play/client/SmithyPlayClientEndpoint.scala +++ b/smithy4play/src/main/scala/de/innfactory/smithy4play/client/SmithyPlayClientEndpoint.scala @@ -5,11 +5,11 @@ package client import cats.implicits._ import smithy4s.codecs.PayloadError import smithy4s.http._ -import smithy4s.{Blob, Endpoint, Hints, Schema} +import smithy4s.{ Blob, Endpoint, Hints, Schema } import java.net.URLEncoder import java.nio.charset.StandardCharsets -import scala.concurrent.{ExecutionContext, Future} +import scala.concurrent.{ ExecutionContext, Future } private[smithy4play] class SmithyPlayClientEndpoint[Op[_, _, _, _, _], I, E, O, SI, SO]( endpoint: Endpoint[Op, I, E, O, SI, SO], @@ -99,7 +99,10 @@ private[smithy4play] class SmithyPlayClientEndpoint[Op[_, _, _, _, _], I, E, O, def buildPath(metadata: Metadata): String = baseUri + httpEndpoint.path(input).mkString("/") + metadata.queryFlattened - .map(s => URLEncoder.encode(s._1, StandardCharsets.UTF_8.name()) + "=" + URLEncoder.encode(s._2, StandardCharsets.UTF_8.name())) + .map(s => + URLEncoder.encode(s._1, StandardCharsets.UTF_8.name()) + "=" + URLEncoder + .encode(s._2, StandardCharsets.UTF_8.name()) + ) .mkString("?", "&", "") }