Files
swift-openapi-lambda/Sources/HttpApi/OpenAPILambdaHttpApi.swift
T
Sébastien StormacqandGitHub c72834d93c Update to support AWS Lambda Runtime for Swift v2 (#22)
- Update this library to support the upcoming release of AWS Lambda
Runtime for Swift v2.
This change affects the public API (some `Sendable` added) and requires
a major version bump. I propose to release v2 to align this library's
major with the Swift AWS Lambda Runtime's major.

- Add a QuoteAPI example in the `Examples` directory
2025-09-06 11:34:56 +02:00

47 lines
1.7 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift OpenAPI Lambda open source project
//
// Copyright (c) 2023 Amazon.com, Inc. or its affiliates
// and the Swift OpenAPI Lambda project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift OpenAPI Lambda project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import Foundation
import AWSLambdaRuntime
import AWSLambdaEvents
import OpenAPIRuntime
import HTTPTypes
/// The errors that can be generated
public enum OpenAPILambdaHttpError: Error {
case invalidMethod(String)
}
/// An specialization of the `OpenAPILambda` protocol that works with Amazon API Gateway HTTP Mode, aka API Gateway v2
public protocol OpenAPILambdaHttpApi: OpenAPILambdaService
where
Event == APIGatewayV2Request,
Output == APIGatewayV2Response
{}
extension OpenAPILambdaHttpApi {
/// Transform a Lambda input (`APIGatewayV2Request` and `LambdaContext`) to an OpenAPILambdaRequest (`HTTPRequest`, `String?`)
public func request(context: LambdaContext, from request: Event) throws -> OpenAPILambdaRequest {
(try request.httpRequest(), request.body)
}
/// Transform an OpenAPI response (`HTTPResponse`, `String?`) to a Lambda Output (`APIGatewayV2Response`)
public func output(from response: OpenAPILambdaResponse) -> Output {
var apiResponse = APIGatewayV2Response(from: response.0)
apiResponse.body = response.1
return apiResponse
}
}