Skip to content

Commit 2a6de31

Browse files
committed
move OpenAPILambda's creation to the library
1 parent cf87e66 commit 2a6de31

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Examples/quoteapi/Sources/QuoteAPI/QuoteService.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ struct QuoteServiceImpl: APIProtocol, OpenAPILambdaHttpApi {
2525
}
2626

2727
static func main() async throws {
28-
let lambda = try OpenAPILambdaHandler<QuoteServiceImpl>()
29-
30-
// Instantiate LambdaRuntime with a handler implementing the business logic of the Lambda function
31-
let lambdaRuntime = LambdaRuntime(body: lambda.handler)
28+
let lambdaRuntime = try LambdaRuntime(body: Self.handler())
3229
try await lambdaRuntime.run()
3330
}
3431

Sources/OpenAPILambda.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@ public protocol OpenAPILambda: Sendable {
3838
/// - Parameter from: response from OpenAPIRuntime
3939
func output(from: OpenAPILambdaResponse) -> Output
4040
}
41+
42+
extension OpenAPILambda {
43+
public static func handler() throws -> @Sendable (Event, LambdaContext) async throws -> Output {
44+
try OpenAPILambdaHandler<Self>().handler
45+
}
46+
}

0 commit comments

Comments
 (0)