-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3795ae
commit 66a98ca
Showing
39 changed files
with
560 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions
23
...io-tests/src/main/scala/sttp/tapir/serverless/aws/ziolambda/tests/LambdaSamTemplate.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package sttp.tapir.serverless.aws.ziolambda.tests | ||
|
||
import sttp.tapir.serverless.aws.sam.{AwsSamInterpreter, AwsSamOptions, CodeSource} | ||
|
||
import java.nio.charset.StandardCharsets.UTF_8 | ||
import java.nio.file.{Files, Paths} | ||
|
||
object LambdaSamTemplate extends App { | ||
|
||
val jarPath = Paths.get("serverless/aws/lambda-zio-tests/target/jvm-2.13/tapir-aws-lambda-zio-tests.jar").toAbsolutePath.toString | ||
|
||
val samOptions: AwsSamOptions = AwsSamOptions( | ||
"Tests", | ||
source = CodeSource( | ||
"java11", | ||
jarPath, | ||
"sttp.tapir.serverless.aws.ziolambda.tests.ZioLambdaHandlerImpl::handleRequest" | ||
), | ||
memorySize = 1024 | ||
) | ||
val yaml = AwsSamInterpreter(samOptions).toSamTemplate(allEndpoints.map(_.endpoint).toList).toYaml | ||
Files.write(Paths.get("aws-lambda-zio-template.yaml"), yaml.getBytes(UTF_8)) | ||
} |
22 changes: 22 additions & 0 deletions
22
...tests/src/main/scala/sttp/tapir/serverless/aws/ziolambda/tests/ZioLambdaHandlerImpl.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package sttp.tapir.serverless.aws.ziolambda.tests | ||
|
||
import com.amazonaws.services.lambda.runtime.{Context, RequestStreamHandler} | ||
import io.circe.generic.auto._ | ||
import sttp.tapir.serverless.aws.lambda.AwsRequest | ||
import sttp.tapir.serverless.aws.ziolambda.ZioLambdaHandler | ||
import sttp.tapir.ztapir.RIOMonadError | ||
import zio.{Runtime, Unsafe} | ||
|
||
import java.io.{InputStream, OutputStream} | ||
|
||
class ZioLambdaHandlerImpl extends RequestStreamHandler { | ||
private implicit val m = new RIOMonadError[Any] | ||
private val handler = ZioLambdaHandler.default[Any](allEndpoints.toList) | ||
|
||
override def handleRequest(input: InputStream, output: OutputStream, context: Context): Unit = { | ||
val runtime = Runtime.default | ||
Unsafe.unsafe { implicit unsafe => | ||
runtime.unsafe.run(handler.process[AwsRequest](input, output)).getOrThrowFiberFailure() | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...s/lambda-zio-tests/src/main/scala/sttp/tapir/serverless/aws/ziolambda/tests/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package sttp.tapir.serverless.aws.ziolambda | ||
|
||
import sttp.tapir.{endpoint, stringToPath} | ||
import sttp.tapir.tests.Basic._ | ||
import sttp.tapir.tests.Mapping.in_4query_out_4header_extended | ||
import sttp.tapir.tests.TestUtil.inputStreamToByteArray | ||
import sttp.tapir.ztapir.ZTapir | ||
import zio.ZIO | ||
|
||
import java.io.{ByteArrayInputStream, InputStream} | ||
|
||
package object tests extends ZTapir { | ||
|
||
type ZioEndpoint = ZServerEndpoint[Any, Any] | ||
|
||
// this endpoint is used to wait until sam local starts up before running actual tests | ||
val health_endpoint: ZioEndpoint = | ||
endpoint.get.in("health").zServerLogic(_ => ZIO.unit) | ||
|
||
val in_path_path_out_string_endpoint: ZioEndpoint = | ||
in_path_path_out_string.zServerLogic { case (fruit: String, amount: Int) => | ||
ZIO.attempt(s"$fruit $amount").mapError(_ => ()) | ||
} | ||
|
||
val in_string_out_string_endpoint: ZioEndpoint = | ||
in_string_out_string.in("string").zServerLogic(v => ZIO.attempt(v).mapError(_ => ())) | ||
|
||
val in_json_out_json_endpoint: ZioEndpoint = | ||
in_json_out_json.in("json").zServerLogic(v => ZIO.attempt(v).mapError(_ => ())) | ||
|
||
val in_headers_out_headers_endpoint: ZioEndpoint = | ||
in_headers_out_headers.zServerLogic(v => ZIO.attempt(v).mapError(_ => ())) | ||
|
||
val in_input_stream_out_input_stream_endpoint: ZioEndpoint = | ||
in_input_stream_out_input_stream.in("is").zServerLogic { is => | ||
ZIO.attempt(new ByteArrayInputStream(inputStreamToByteArray(is)): InputStream).orDie | ||
} | ||
|
||
val in_4query_out_4header_extended_endpoint: ZioEndpoint = | ||
in_4query_out_4header_extended.in("echo" / "query").zServerLogic(v => ZIO.attempt(v).mapError(_ => ())) | ||
|
||
val allEndpoints: Set[ZioEndpoint] = Set( | ||
health_endpoint, | ||
in_path_path_out_string_endpoint, | ||
in_string_out_string_endpoint, | ||
in_json_out_json_endpoint, | ||
in_headers_out_headers_endpoint, | ||
in_input_stream_out_input_stream_endpoint, | ||
in_4query_out_4header_extended_endpoint | ||
) | ||
|
||
} |
Oops, something went wrong.