From a7e3d39e1fb080b1dbb144f07fc089b65044d99d Mon Sep 17 00:00:00 2001 From: Sergiusz Kierat Date: Tue, 24 Dec 2024 09:52:54 +0100 Subject: [PATCH 1/9] Add server options to AWS Lambda handler *Why I did it?* LambdaHandler had the hardcoded AwsServerOptions, so delivering the custom server options was impossible. *How I did it:* LambdaHandler started to accept options by analogous to ZioLambdaHandler Closes #4064 --- .../aws/cdk/tests/CdkTestLambdaHandler.scala | 2 +- .../aws/cdk/IOLambdaHandlerV1Test.scala | 23 ++++++++++++++++--- .../aws/cdk/test/IOLambdaHandlerV1.scala | 4 ++-- .../serverless/aws/lambda/LambdaHandler.scala | 7 +++--- .../aws/ziolambda/ZioLambdaHandler.scala | 2 +- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/serverless/aws/cdk-tests/src/main/scala/sttp/tapir/serverless/aws/cdk/tests/CdkTestLambdaHandler.scala b/serverless/aws/cdk-tests/src/main/scala/sttp/tapir/serverless/aws/cdk/tests/CdkTestLambdaHandler.scala index ac79696e53..184b734af5 100644 --- a/serverless/aws/cdk-tests/src/main/scala/sttp/tapir/serverless/aws/cdk/tests/CdkTestLambdaHandler.scala +++ b/serverless/aws/cdk-tests/src/main/scala/sttp/tapir/serverless/aws/cdk/tests/CdkTestLambdaHandler.scala @@ -11,7 +11,7 @@ import java.io.{InputStream, OutputStream} /** Used by [[AwsCdkAppTemplate]] for integration tests */ -object CdkTestLambdaHandler extends LambdaHandler[IO, AwsRequestV1] { +object CdkTestLambdaHandler extends LambdaHandler[IO, AwsRequestV1](AwsCatsEffectServerOptions.default[IO]) { override protected def getAllEndpoints: List[ServerEndpoint[Any, IO]] = allEndpoints.toList override def handleRequest(input: InputStream, output: OutputStream, context: Context): Unit = { diff --git a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/IOLambdaHandlerV1Test.scala b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/IOLambdaHandlerV1Test.scala index 1e47875e3c..d09484b94b 100644 --- a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/IOLambdaHandlerV1Test.scala +++ b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/IOLambdaHandlerV1Test.scala @@ -1,12 +1,13 @@ package sttp.tapir.serverless.aws.cdk +import cats.effect.IO import com.amazonaws.services.lambda.runtime.api.client.api._ import io.circe.generic.auto._ import io.circe.parser.decode import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers import sttp.tapir.serverless.aws.cdk.test.IOLambdaHandlerV1 -import sttp.tapir.serverless.aws.lambda.AwsResponse +import sttp.tapir.serverless.aws.lambda.{AwsCatsEffectServerOptions, AwsResponse} import java.io.{ByteArrayInputStream, ByteArrayOutputStream} @@ -81,10 +82,10 @@ class IOLambdaHandlerV1Test extends AnyFunSuite with Matchers { new LambdaClientContext() ) - test("lambda handler") { + test("lambda handler without encoding") { val output = new ByteArrayOutputStream() - val handler = new IOLambdaHandlerV1 + val handler = new IOLambdaHandlerV1(AwsCatsEffectServerOptions.noEncoding[IO]) handler.handleRequest(new ByteArrayInputStream(input.getBytes), output, context) val expected = AwsResponse( @@ -96,4 +97,20 @@ class IOLambdaHandlerV1Test extends AnyFunSuite with Matchers { decode[AwsResponse](output.toString()) shouldBe Right(expected) } + + test("lambda handler with default encoding") { + val output = new ByteArrayOutputStream() + + val handler = new IOLambdaHandlerV1(AwsCatsEffectServerOptions.default[IO]) + handler.handleRequest(new ByteArrayInputStream(input.getBytes), output, context) + + val expected = AwsResponse( + isBase64Encoded = true, + 200, + Map("Content-Length" -> "9", "Content-Type" -> "text/plain; charset=UTF-8"), + "SGkhIEp1bGll" + ) + + decode[AwsResponse](output.toString()) shouldBe Right(expected) + } } diff --git a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala index d89f255d58..6d60178b07 100644 --- a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala +++ b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala @@ -5,11 +5,11 @@ import cats.effect.unsafe.implicits.global import com.amazonaws.services.lambda.runtime.Context import io.circe.generic.auto._ import sttp.tapir.server.ServerEndpoint -import sttp.tapir.serverless.aws.lambda.{AwsRequestV1, LambdaHandler} +import sttp.tapir.serverless.aws.lambda.{AwsRequestV1, AwsServerOptions, LambdaHandler} import java.io.{InputStream, OutputStream} -class IOLambdaHandlerV1 extends LambdaHandler[IO, AwsRequestV1] { +class IOLambdaHandlerV1(options: AwsServerOptions[IO]) extends LambdaHandler[IO, AwsRequestV1](options) { override protected def getAllEndpoints: List[ServerEndpoint[Any, IO]] = TestEndpoints.all[IO].toList diff --git a/serverless/aws/lambda-cats-effect/src/main/scala/sttp/tapir/serverless/aws/lambda/LambdaHandler.scala b/serverless/aws/lambda-cats-effect/src/main/scala/sttp/tapir/serverless/aws/lambda/LambdaHandler.scala index 1c4150834a..b7e792514c 100644 --- a/serverless/aws/lambda-cats-effect/src/main/scala/sttp/tapir/serverless/aws/lambda/LambdaHandler.scala +++ b/serverless/aws/lambda-cats-effect/src/main/scala/sttp/tapir/serverless/aws/lambda/LambdaHandler.scala @@ -18,14 +18,15 @@ import java.nio.charset.StandardCharsets * @tparam R * AWS API Gateway request type [[AwsRequestV1]] or [[AwsRequest]]. At the moment mapping is required as there is no support for * generating API Gateway V2 definitions with AWS CDK v2. + * @param options + * Server options of type AwsServerOptions. */ -abstract class LambdaHandler[F[_]: Sync, R: Decoder] extends RequestStreamHandler { +abstract class LambdaHandler[F[_]: Sync, R: Decoder](options: AwsServerOptions[F]) extends RequestStreamHandler { protected def getAllEndpoints: List[ServerEndpoint[Any, F]] protected def process(input: InputStream, output: OutputStream): F[Unit] = { - val server: AwsCatsEffectServerInterpreter[F] = - AwsCatsEffectServerInterpreter(AwsCatsEffectServerOptions.noEncoding[F]) + val server: AwsCatsEffectServerInterpreter[F] = AwsCatsEffectServerInterpreter(options) for { allBytes <- Sync[F].blocking(input.readAllBytes()) diff --git a/serverless/aws/lambda-zio/src/main/scala/sttp/tapir/serverless/aws/ziolambda/ZioLambdaHandler.scala b/serverless/aws/lambda-zio/src/main/scala/sttp/tapir/serverless/aws/ziolambda/ZioLambdaHandler.scala index 37d5bc7efb..ea5b33bc1f 100644 --- a/serverless/aws/lambda-zio/src/main/scala/sttp/tapir/serverless/aws/ziolambda/ZioLambdaHandler.scala +++ b/serverless/aws/lambda-zio/src/main/scala/sttp/tapir/serverless/aws/ziolambda/ZioLambdaHandler.scala @@ -16,7 +16,7 @@ import java.nio.charset.StandardCharsets * * @tparam Env * The Environment type of the handler . - * @tparam options + * @param options * Server options of type AwsServerOptions. */ abstract class ZioLambdaHandler[Env: RIOMonadError](options: AwsServerOptions[RIO[Env, *]]) { From fffe51b910e1b4662526cdd60ff4deba99d23d41 Mon Sep 17 00:00:00 2001 From: Sergiusz Kierat Date: Tue, 24 Dec 2024 12:59:36 +0100 Subject: [PATCH 2/9] fixes --- .../sttp/tapir/serverless/aws/examples/LambdaApiExample.scala | 2 +- .../sttp/tapir/serverless/aws/examples/LambdaApiV1Example.scala | 2 +- .../tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala b/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala index 83b4520f05..a5db944732 100644 --- a/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala +++ b/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala @@ -11,7 +11,7 @@ import sttp.tapir.serverless.aws.lambda._ import java.io.{InputStream, OutputStream} -object LambdaApiExample extends LambdaHandler[IO, AwsRequest] { +object LambdaApiExample(options: AwsServerOptions[IO]) extends LambdaHandler[IO, AwsRequest](options) { val helloEndpoint: ServerEndpoint[Any, IO] = endpoint.get .in("api" / "hello") diff --git a/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiV1Example.scala b/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiV1Example.scala index edf871da6c..b9ce7bd42f 100644 --- a/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiV1Example.scala +++ b/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiV1Example.scala @@ -11,7 +11,7 @@ import sttp.tapir.serverless.aws.lambda._ import java.io.{InputStream, OutputStream} -object LambdaApiV1Example extends LambdaHandler[IO, AwsRequestV1] { +object LambdaApiV1Example(options: AwsServerOptions[IO]) extends LambdaHandler[IO, AwsRequestV1](options) { val helloEndpoint: ServerEndpoint[Any, IO] = endpoint.get .in("api" / "hello") diff --git a/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala b/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala index 65d5c6aa53..d4a4b912e3 100644 --- a/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala +++ b/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala @@ -8,7 +8,7 @@ import sttp.tapir.server.ServerEndpoint import sttp.tapir.serverless.aws.lambda.{AwsRequest, LambdaHandler} import java.io.{InputStream, OutputStream} -class IOLambdaHandlerV2 extends LambdaHandler[IO, AwsRequest] { +class IOLambdaHandlerV2(options: AwsServerOptions[IO]) extends LambdaHandler[IO, AwsRequest](options) { override protected def getAllEndpoints: List[ServerEndpoint[Any, IO]] = allEndpoints.toList From 27f6778740d65bc62dc7304650a82f7bc8ec7cd1 Mon Sep 17 00:00:00 2001 From: Sergiusz Kierat Date: Tue, 24 Dec 2024 13:12:45 +0100 Subject: [PATCH 3/9] fixes --- .../sttp/tapir/serverless/aws/examples/LambdaApiExample.scala | 2 +- .../sttp/tapir/serverless/aws/examples/LambdaApiV1Example.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala b/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala index a5db944732..f7771d7259 100644 --- a/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala +++ b/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala @@ -11,7 +11,7 @@ import sttp.tapir.serverless.aws.lambda._ import java.io.{InputStream, OutputStream} -object LambdaApiExample(options: AwsServerOptions[IO]) extends LambdaHandler[IO, AwsRequest](options) { +object LambdaApiExample extends LambdaHandler[IO, AwsRequest](AwsCatsEffectServerOptions.default[IO]) { val helloEndpoint: ServerEndpoint[Any, IO] = endpoint.get .in("api" / "hello") diff --git a/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiV1Example.scala b/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiV1Example.scala index b9ce7bd42f..f9626ea5fc 100644 --- a/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiV1Example.scala +++ b/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiV1Example.scala @@ -11,7 +11,7 @@ import sttp.tapir.serverless.aws.lambda._ import java.io.{InputStream, OutputStream} -object LambdaApiV1Example(options: AwsServerOptions[IO]) extends LambdaHandler[IO, AwsRequestV1](options) { +object LambdaApiV1Example extends LambdaHandler[IO, AwsRequestV1](AwsCatsEffectServerOptions.default[IO]) { val helloEndpoint: ServerEndpoint[Any, IO] = endpoint.get .in("api" / "hello") From 8c905dff92651441beb39d168b190c4d7f4e3708 Mon Sep 17 00:00:00 2001 From: Sergiusz Kierat Date: Tue, 24 Dec 2024 13:20:17 +0100 Subject: [PATCH 4/9] fix --- .../tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala b/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala index d4a4b912e3..70b0e35aa2 100644 --- a/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala +++ b/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala @@ -5,7 +5,7 @@ import cats.effect.unsafe.implicits.global import com.amazonaws.services.lambda.runtime.Context import io.circe.generic.auto._ import sttp.tapir.server.ServerEndpoint -import sttp.tapir.serverless.aws.lambda.{AwsRequest, LambdaHandler} +import sttp.tapir.serverless.aws.lambda.{AwsRequest, AwsServerOptions, LambdaHandler} import java.io.{InputStream, OutputStream} class IOLambdaHandlerV2(options: AwsServerOptions[IO]) extends LambdaHandler[IO, AwsRequest](options) { From 087f9ffd1269b3a80246d1fd4e87c2957fd130c6 Mon Sep 17 00:00:00 2001 From: Sergiusz Kierat Date: Fri, 27 Dec 2024 11:55:01 +0100 Subject: [PATCH 5/9] set default --- .../tapir/serverless/aws/cdk/IOLambdaHandlerV1Test.scala | 2 +- .../tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala | 6 +++--- .../serverless/aws/lambda/tests/IOLambdaHandlerV2.scala | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/IOLambdaHandlerV1Test.scala b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/IOLambdaHandlerV1Test.scala index d09484b94b..268f0bd21d 100644 --- a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/IOLambdaHandlerV1Test.scala +++ b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/IOLambdaHandlerV1Test.scala @@ -85,7 +85,7 @@ class IOLambdaHandlerV1Test extends AnyFunSuite with Matchers { test("lambda handler without encoding") { val output = new ByteArrayOutputStream() - val handler = new IOLambdaHandlerV1(AwsCatsEffectServerOptions.noEncoding[IO]) + val handler = new IOLambdaHandlerV1() handler.handleRequest(new ByteArrayInputStream(input.getBytes), output, context) val expected = AwsResponse( diff --git a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala index 6d60178b07..966524a46e 100644 --- a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala +++ b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala @@ -3,13 +3,13 @@ package sttp.tapir.serverless.aws.cdk.test import cats.effect.IO import cats.effect.unsafe.implicits.global import com.amazonaws.services.lambda.runtime.Context -import io.circe.generic.auto._ +import io.circe.generic.auto.* import sttp.tapir.server.ServerEndpoint -import sttp.tapir.serverless.aws.lambda.{AwsRequestV1, AwsServerOptions, LambdaHandler} +import sttp.tapir.serverless.aws.lambda.{AwsCatsEffectServerOptions, AwsRequestV1, AwsServerOptions, LambdaHandler} import java.io.{InputStream, OutputStream} -class IOLambdaHandlerV1(options: AwsServerOptions[IO]) extends LambdaHandler[IO, AwsRequestV1](options) { +class IOLambdaHandlerV1(options: AwsServerOptions[IO] = AwsCatsEffectServerOptions.noEncoding[IO]) extends LambdaHandler[IO, AwsRequestV1](options) { override protected def getAllEndpoints: List[ServerEndpoint[Any, IO]] = TestEndpoints.all[IO].toList diff --git a/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala b/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala index 70b0e35aa2..7788e874c5 100644 --- a/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala +++ b/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala @@ -5,10 +5,10 @@ import cats.effect.unsafe.implicits.global import com.amazonaws.services.lambda.runtime.Context import io.circe.generic.auto._ import sttp.tapir.server.ServerEndpoint -import sttp.tapir.serverless.aws.lambda.{AwsRequest, AwsServerOptions, LambdaHandler} +import sttp.tapir.serverless.aws.lambda.{AwsCatsEffectServerOptions, AwsRequest, AwsServerOptions, LambdaHandler} import java.io.{InputStream, OutputStream} -class IOLambdaHandlerV2(options: AwsServerOptions[IO]) extends LambdaHandler[IO, AwsRequest](options) { +class IOLambdaHandlerV2(options: AwsServerOptions[IO] = AwsCatsEffectServerOptions.noEncoding[IO]) extends LambdaHandler[IO, AwsRequest](options) { override protected def getAllEndpoints: List[ServerEndpoint[Any, IO]] = allEndpoints.toList From e09bc289c8564c34cb87de4cb2d851d63eaaf1ff Mon Sep 17 00:00:00 2001 From: Sergiusz Kierat Date: Fri, 27 Dec 2024 12:13:48 +0100 Subject: [PATCH 6/9] fix compilation --- .../sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala index 966524a46e..f449bfb59a 100644 --- a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala +++ b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala @@ -3,7 +3,7 @@ package sttp.tapir.serverless.aws.cdk.test import cats.effect.IO import cats.effect.unsafe.implicits.global import com.amazonaws.services.lambda.runtime.Context -import io.circe.generic.auto.* +import io.circe.generic.auto._ import sttp.tapir.server.ServerEndpoint import sttp.tapir.serverless.aws.lambda.{AwsCatsEffectServerOptions, AwsRequestV1, AwsServerOptions, LambdaHandler} From 32e7d35a42695ad002ecad6c00598642735c358a Mon Sep 17 00:00:00 2001 From: Sergiusz Kierat Date: Fri, 27 Dec 2024 14:36:34 +0100 Subject: [PATCH 7/9] noEncoding --- .../tapir/serverless/aws/cdk/tests/CdkTestLambdaHandler.scala | 2 +- .../sttp/tapir/serverless/aws/examples/LambdaApiExample.scala | 2 +- .../sttp/tapir/serverless/aws/examples/LambdaApiV1Example.scala | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/serverless/aws/cdk-tests/src/main/scala/sttp/tapir/serverless/aws/cdk/tests/CdkTestLambdaHandler.scala b/serverless/aws/cdk-tests/src/main/scala/sttp/tapir/serverless/aws/cdk/tests/CdkTestLambdaHandler.scala index 184b734af5..7b7fbc96fc 100644 --- a/serverless/aws/cdk-tests/src/main/scala/sttp/tapir/serverless/aws/cdk/tests/CdkTestLambdaHandler.scala +++ b/serverless/aws/cdk-tests/src/main/scala/sttp/tapir/serverless/aws/cdk/tests/CdkTestLambdaHandler.scala @@ -11,7 +11,7 @@ import java.io.{InputStream, OutputStream} /** Used by [[AwsCdkAppTemplate]] for integration tests */ -object CdkTestLambdaHandler extends LambdaHandler[IO, AwsRequestV1](AwsCatsEffectServerOptions.default[IO]) { +object CdkTestLambdaHandler extends LambdaHandler[IO, AwsRequestV1](AwsCatsEffectServerOptions.noEncoding[IO]) { override protected def getAllEndpoints: List[ServerEndpoint[Any, IO]] = allEndpoints.toList override def handleRequest(input: InputStream, output: OutputStream, context: Context): Unit = { diff --git a/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala b/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala index f7771d7259..8657f71611 100644 --- a/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala +++ b/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiExample.scala @@ -11,7 +11,7 @@ import sttp.tapir.serverless.aws.lambda._ import java.io.{InputStream, OutputStream} -object LambdaApiExample extends LambdaHandler[IO, AwsRequest](AwsCatsEffectServerOptions.default[IO]) { +object LambdaApiExample extends LambdaHandler[IO, AwsRequest](AwsCatsEffectServerOptions.noEncoding[IO]) { val helloEndpoint: ServerEndpoint[Any, IO] = endpoint.get .in("api" / "hello") diff --git a/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiV1Example.scala b/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiV1Example.scala index f9626ea5fc..d5eab0b771 100644 --- a/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiV1Example.scala +++ b/serverless/aws/examples/src/main/scalajvm/sttp/tapir/serverless/aws/examples/LambdaApiV1Example.scala @@ -11,7 +11,7 @@ import sttp.tapir.serverless.aws.lambda._ import java.io.{InputStream, OutputStream} -object LambdaApiV1Example extends LambdaHandler[IO, AwsRequestV1](AwsCatsEffectServerOptions.default[IO]) { +object LambdaApiV1Example extends LambdaHandler[IO, AwsRequestV1](AwsCatsEffectServerOptions.noEncoding[IO]) { val helloEndpoint: ServerEndpoint[Any, IO] = endpoint.get .in("api" / "hello") From 0607a8704bf9008402a12f8bc0ed87c7c9a03698 Mon Sep 17 00:00:00 2001 From: Sergiusz Kierat Date: Fri, 27 Dec 2024 15:08:40 +0100 Subject: [PATCH 8/9] class without parameters --- .../sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala | 2 +- .../tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala index f449bfb59a..56d90e2b94 100644 --- a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala +++ b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala @@ -9,7 +9,7 @@ import sttp.tapir.serverless.aws.lambda.{AwsCatsEffectServerOptions, AwsRequestV import java.io.{InputStream, OutputStream} -class IOLambdaHandlerV1(options: AwsServerOptions[IO] = AwsCatsEffectServerOptions.noEncoding[IO]) extends LambdaHandler[IO, AwsRequestV1](options) { +class IOLambdaHandlerV1 extends LambdaHandler[IO, AwsRequestV1](AwsCatsEffectServerOptions.noEncoding[IO]) { override protected def getAllEndpoints: List[ServerEndpoint[Any, IO]] = TestEndpoints.all[IO].toList diff --git a/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala b/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala index 7788e874c5..35446ca7af 100644 --- a/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala +++ b/serverless/aws/lambda-cats-effect-tests/src/main/scala/sttp/tapir/serverless/aws/lambda/tests/IOLambdaHandlerV2.scala @@ -8,7 +8,7 @@ import sttp.tapir.server.ServerEndpoint import sttp.tapir.serverless.aws.lambda.{AwsCatsEffectServerOptions, AwsRequest, AwsServerOptions, LambdaHandler} import java.io.{InputStream, OutputStream} -class IOLambdaHandlerV2(options: AwsServerOptions[IO] = AwsCatsEffectServerOptions.noEncoding[IO]) extends LambdaHandler[IO, AwsRequest](options) { +class IOLambdaHandlerV2 extends LambdaHandler[IO, AwsRequest](AwsCatsEffectServerOptions.noEncoding[IO]) { override protected def getAllEndpoints: List[ServerEndpoint[Any, IO]] = allEndpoints.toList From d4b41dff03a1886ad5c47cad23af04021261ccae Mon Sep 17 00:00:00 2001 From: Sergiusz Kierat Date: Fri, 27 Dec 2024 15:22:43 +0100 Subject: [PATCH 9/9] revert test change --- .../aws/cdk/IOLambdaHandlerV1Test.scala | 23 +++---------------- .../aws/cdk/test/IOLambdaHandlerV1.scala | 2 +- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/IOLambdaHandlerV1Test.scala b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/IOLambdaHandlerV1Test.scala index 268f0bd21d..1e47875e3c 100644 --- a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/IOLambdaHandlerV1Test.scala +++ b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/IOLambdaHandlerV1Test.scala @@ -1,13 +1,12 @@ package sttp.tapir.serverless.aws.cdk -import cats.effect.IO import com.amazonaws.services.lambda.runtime.api.client.api._ import io.circe.generic.auto._ import io.circe.parser.decode import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers import sttp.tapir.serverless.aws.cdk.test.IOLambdaHandlerV1 -import sttp.tapir.serverless.aws.lambda.{AwsCatsEffectServerOptions, AwsResponse} +import sttp.tapir.serverless.aws.lambda.AwsResponse import java.io.{ByteArrayInputStream, ByteArrayOutputStream} @@ -82,10 +81,10 @@ class IOLambdaHandlerV1Test extends AnyFunSuite with Matchers { new LambdaClientContext() ) - test("lambda handler without encoding") { + test("lambda handler") { val output = new ByteArrayOutputStream() - val handler = new IOLambdaHandlerV1() + val handler = new IOLambdaHandlerV1 handler.handleRequest(new ByteArrayInputStream(input.getBytes), output, context) val expected = AwsResponse( @@ -97,20 +96,4 @@ class IOLambdaHandlerV1Test extends AnyFunSuite with Matchers { decode[AwsResponse](output.toString()) shouldBe Right(expected) } - - test("lambda handler with default encoding") { - val output = new ByteArrayOutputStream() - - val handler = new IOLambdaHandlerV1(AwsCatsEffectServerOptions.default[IO]) - handler.handleRequest(new ByteArrayInputStream(input.getBytes), output, context) - - val expected = AwsResponse( - isBase64Encoded = true, - 200, - Map("Content-Length" -> "9", "Content-Type" -> "text/plain; charset=UTF-8"), - "SGkhIEp1bGll" - ) - - decode[AwsResponse](output.toString()) shouldBe Right(expected) - } } diff --git a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala index 56d90e2b94..6f21393489 100644 --- a/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala +++ b/serverless/aws/cdk/src/test/scala/sttp/tapir/serverless/aws/cdk/test/IOLambdaHandlerV1.scala @@ -5,7 +5,7 @@ import cats.effect.unsafe.implicits.global import com.amazonaws.services.lambda.runtime.Context import io.circe.generic.auto._ import sttp.tapir.server.ServerEndpoint -import sttp.tapir.serverless.aws.lambda.{AwsCatsEffectServerOptions, AwsRequestV1, AwsServerOptions, LambdaHandler} +import sttp.tapir.serverless.aws.lambda.{AwsCatsEffectServerOptions, AwsRequestV1, LambdaHandler} import java.io.{InputStream, OutputStream}