@@ -18,7 +18,11 @@ import OpenAPIRuntime
18
18
import HTTPTypes
19
19
20
20
/// Specialization of LambdaHandler which runs an OpenAPILambda
21
- public struct OpenAPILambdaHandler < L: OpenAPILambda > : LambdaHandler {
21
+ public struct OpenAPILambdaHandler < L: OpenAPILambda > : Sendable where L. Event: Sendable , L. Output: Sendable {
22
+
23
+ private let router : OpenAPILambdaRouter
24
+ private let transport : OpenAPILambdaTransport
25
+ private let lambda : L
22
26
23
27
/// the input type for this Lambda handler (received from the `OpenAPILambda`)
24
28
public typealias Event = L . Event
@@ -31,7 +35,7 @@ public struct OpenAPILambdaHandler<L: OpenAPILambda>: LambdaHandler {
31
35
/// Create application, set it up and create `OpenAPILambda` from application and create responder
32
36
/// - Parameters
33
37
/// - context: Lambda initialization context
34
- public init ( context : LambdaInitializationContext ) throws {
38
+ public init ( ) throws {
35
39
self . router = TrieRouter ( )
36
40
self . transport = OpenAPILambdaTransport ( router: self . router)
37
41
self . lambda = try . init( transport: self . transport)
@@ -45,14 +49,14 @@ public struct OpenAPILambdaHandler<L: OpenAPILambda>: LambdaHandler {
45
49
/// - context: Runtime ``LambdaContext``.
46
50
///
47
51
/// - Returns: A Lambda result ot type `Output`.
48
- public func handle ( _ request : Event , context: LambdaContext ) async throws -> Output {
52
+ public func handler ( event : L . Event , context: LambdaContext ) async throws -> L . Output {
49
53
50
- // by default return HTTP 500
54
+ // by default returns HTTP 500
51
55
var lambdaResponse : OpenAPILambdaResponse = ( HTTPResponse ( status: . internalServerError) , " unknown error " )
52
56
53
57
do {
54
58
// convert Lambda event source to OpenAPILambdaRequest
55
- let request = try lambda. request ( context: context, from: request )
59
+ let request = try lambda. request ( context: context, from: event )
56
60
57
61
// route the request to find the handlers and extract the paramaters
58
62
let ( handler, parameters) = try await router. route ( method: request. 0 . method, path: request. 0 . path!)
@@ -103,8 +107,28 @@ public struct OpenAPILambdaHandler<L: OpenAPILambda>: LambdaHandler {
103
107
// transform the OpenAPILambdaResponse to the Lambda Output
104
108
return lambda. output ( from: lambdaResponse)
105
109
}
106
-
107
- let router : OpenAPILambdaRouter
108
- let transport : OpenAPILambdaTransport
109
- let lambda : L
110
110
}
111
+
112
+ // struct Test<L: OpenAPILambda> where L.Event: Sendable, L.Output: Sendable {
113
+ // private let router: OpenAPILambdaRouter
114
+ // private let transport: OpenAPILambdaTransport
115
+ // private let lambda: L
116
+ // private let logger: Logger = Logger(label: "test")
117
+
118
+ // /// the input type for this Lambda handler (received from the `OpenAPILambda`)
119
+ // public typealias Event = L.Event
120
+
121
+ // /// the output type for this Lambda handler (received from the `OpenAPILambda`)
122
+ // public typealias Output = L.Output
123
+
124
+ // /// Function entry point when the runtime environment is created
125
+ // private func main() async throws {
126
+ // // Instantiate LambdaRuntime with a handler implementing the business logic of the Lambda function
127
+ // let lambdaRuntime = LambdaRuntime(logger: logger, body: self.handler)
128
+ // try await lambdaRuntime.run()
129
+ // }
130
+ // private func handler(event: Event, context: LambdaContext) async throws -> Output {
131
+ // fatalError()
132
+ // }
133
+
134
+ // }
0 commit comments