@@ -19,10 +19,10 @@ import OpenAPIRuntime
19
19
import HTTPTypes
20
20
21
21
/// A Lambda function implemented with a OpenAPI server (implementing `APIProtocol` from Swift OpenAPIRuntime)
22
- public protocol OpenAPILambda {
22
+ public protocol OpenAPILambda : Sendable {
23
23
24
- associatedtype Event : Decodable
25
- associatedtype Output : Encodable
24
+ associatedtype Event : Decodable , Sendable
25
+ associatedtype Output : Encodable , Sendable
26
26
27
27
/// Initialize application.
28
28
///
@@ -47,22 +47,26 @@ extension OpenAPILambda {
47
47
try OpenAPILambdaHandler < Self > ( ) . handler
48
48
}
49
49
50
- /// Run the Lambda handler function for this OpenAPI Lambda implementation with a custom logger, when one is given.
50
+ /// Invokes the OpenAPI Lambda handler function for this OpenAPI Lambda implementation
51
+ /// - Parameters:
52
+ /// - event: The event for the Lambda function
53
+ /// - context: The Lambda context
54
+ /// - Throws: An error if the handler function fails
55
+ /// - Returns: The output of the handler function
56
+ private static func handler( event: Event , context: LambdaContext ) async throws -> Output {
57
+ try await Self . handler ( ) ( event, context)
58
+ }
59
+
60
+ /// Start the Lambda Runtime with the Lambda handler function for this OpenAPI Lambda implementation with a custom logger,
61
+ /// when one is given.
51
62
/// - Parameter logger: The logger to use for Lambda runtime logging
52
63
public static func run( logger: Logger ? = nil ) async throws {
53
- let lambdaRuntime :
54
- LambdaRuntime <
55
- LambdaCodableAdapter <
56
- LambdaHandlerAdapter < Self . Event , Self . Output , ClosureHandler < Self . Event , Self . Output > > , Self . Event ,
57
- Self . Output , LambdaJSONEventDecoder , LambdaJSONOutputEncoder < Self . Output >
58
- >
59
- >
60
- if let logger {
61
- lambdaRuntime = try LambdaRuntime ( logger: logger, body: Self . handler ( ) )
62
- }
63
- else {
64
- lambdaRuntime = try LambdaRuntime ( body: Self . handler ( ) )
64
+
65
+ let lambdaRuntime = LambdaRuntime { ( event: Event , context: LambdaContext ) in
66
+ try await Self . handler ( event: event, context: context)
65
67
}
68
+
69
+ // let lambdaRuntime = try LambdaRuntime(body: Self.handler())
66
70
try await lambdaRuntime. run ( )
67
71
}
68
72
}
0 commit comments