Skip to content

Commit 91a69c3

Browse files
committed
Use explicit types all the time
1 parent 64f5a1e commit 91a69c3

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Sources/OpenAPILambda.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,23 @@ extension OpenAPILambdaService {
5656
/// try await lambdaRuntime.run()
5757
///
5858
/// - Returns: A handler function that can be used with AWS Lambda Runtime
59-
public static func handler() throws -> (Event, LambdaContext) async throws -> Output {
60-
try OpenAPILambdaHandler<Self>().handler
59+
public static func makeHandler() throws -> OpenAPILambdaHandler<Self> {
60+
try OpenAPILambdaHandler<Self>()
6161
}
6262

6363
/// Start the Lambda Runtime with the Lambda handler function for this OpenAPI Lambda implementation with a custom logger,
6464
/// when one is given.
6565
/// - Parameter logger: The logger to use for Lambda runtime logging
6666
public static func run(logger: Logger? = nil) async throws {
6767
let _logger = logger ?? Logger(label: "OpenAPILambdaService")
68-
let lambdaRuntime = LambdaRuntime(logger: _logger, body: try Self.handler())
68+
69+
let handler = LambdaCodableAdapter(
70+
encoder: JSONEncoder(),
71+
decoder: JSONDecoder(),
72+
handler: LambdaHandlerAdapter(handler: try Self.makeHandler())
73+
)
74+
75+
let lambdaRuntime = LambdaRuntime(handler: handler, logger: _logger,)
6976
try await lambdaRuntime.run()
7077
}
7178
}

Sources/OpenAPILambdaHandler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import OpenAPIRuntime
1818
import HTTPTypes
1919

2020
/// Specialization of LambdaHandler which runs an OpenAPILambda
21-
public struct OpenAPILambdaHandler<OALS: OpenAPILambdaService>: Sendable {
21+
public struct OpenAPILambdaHandler<OALS: OpenAPILambdaService>: LambdaHandler {
2222

2323
private let router: OpenAPILambdaRouter
2424
private let transport: OpenAPILambdaTransport
@@ -65,7 +65,7 @@ public struct OpenAPILambdaHandler<OALS: OpenAPILambdaService>: Sendable {
6565
/// - context: Runtime ``LambdaContext``.
6666
///
6767
/// - Returns: A Lambda result ot type `Output`.
68-
public func handler(event: OALS.Event, context: LambdaContext) async throws -> OALS.Output {
68+
public func handle(_ event: OALS.Event, context: AWSLambdaRuntime.LambdaContext) async throws -> OALS.Output {
6969

7070
// by default returns HTTP 500
7171
var lambdaResponse: OpenAPILambdaResponse = (HTTPResponse(status: .internalServerError), "unknown error")

0 commit comments

Comments
 (0)