Skip to content

Commit b2fa4cc

Browse files
committed
rename LambdaOpenAPITransport to OpenAPILambdaTransport for consistency
1 parent 9784bd4 commit b2fa4cc

9 files changed

+24
-24
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import OpenAPILambda // <-- 1. import this library
6969
@main // <-- 2. flag this struct as the executable target entrypoint
7070
struct QuoteServiceImpl: APIProtocol, OpenAPILambdaHttpApi { // <-- 3. add the OpenAPILambdaHttpApi protocol
7171

72-
init(transport: LambdaOpenAPITransport) throws { // <-- 4. add this constructor (don't remove the call to `registerHandlers(on:)`)
72+
init(transport: OpenAPILambdaTransport) throws { // <-- 4. add this constructor (don't remove the call to `registerHandlers(on:)`)
7373
try self.registerHandlers(on: transport)
7474
}
7575

@@ -247,7 +247,7 @@ import OpenAPILambda
247247
@main
248248
struct QuoteServiceImpl: APIProtocol, OpenAPILambdaHttpApi {
249249

250-
init(transport: LambdaOpenAPITransport) throws {
250+
init(transport: OpenAPILambdaTransport) throws {
251251
try self.registerHandlers(on: transport)
252252
}
253253

@@ -494,7 +494,7 @@ Here is an example using `APIGatewayRequest` and `APIGatewayResponse`:
494494
struct QuoteServiceLambda: OpenAPILambda {
495495
typealias Event = APIGatewayRequest
496496
typealias Output = APIGatewayResponse
497-
public init(transport: LambdaOpenAPITransport) throws {
497+
public init(transport: OpenAPILambdaTransport) throws {
498498
let openAPIHandler = QuoteServiceImpl()
499499
try openAPIHandler.registerHandlers(on: transport)
500500
}
@@ -529,7 +529,7 @@ extension APIGatewayRequest {
529529
/// Return an `HTTPRequest.Method` for this `APIGatewayRequest`
530530
public func httpRequestMethod() throws -> HTTPRequest.Method {
531531
guard let method = HTTPRequest.Method(rawValue: self.httpMethod.rawValue) else {
532-
throw LambdaOpenAPIHttpError.invalidMethod(self.httpMethod.rawValue)
532+
throw OpenAPILambdaHttpError.invalidMethod(self.httpMethod.rawValue)
533533
}
534534
return method
535535
}

Sources/HttpApi/APIGatewayV2+HTTPRequest.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension APIGatewayV2Request {
2121
/// Return an `HTTPRequest.Method` for this `APIGatewayV2Request`
2222
public func httpRequestMethod() throws -> HTTPRequest.Method {
2323
guard let method = HTTPRequest.Method(rawValue: self.context.http.method.rawValue) else {
24-
throw LambdaOpenAPIHttpError.invalidMethod(self.context.http.method.rawValue)
24+
throw OpenAPILambdaHttpError.invalidMethod(self.context.http.method.rawValue)
2525
}
2626
return method
2727
}

Sources/HttpApi/OpenAPILambdaHttpApi.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import OpenAPIRuntime
1919
import HTTPTypes
2020

2121
/// The errors that can be generated
22-
public enum LambdaOpenAPIHttpError: Error {
22+
public enum OpenAPILambdaHttpError: Error {
2323
case invalidMethod(String)
2424
}
2525

Sources/OpenAPILambda.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public protocol OpenAPILambda {
2626
/// Initialize application.
2727
///
2828
/// This is where you create your OpenAPI service implementation and register the transport
29-
init(transport: LambdaOpenAPITransport) throws
29+
init(transport: OpenAPILambdaTransport) throws
3030

3131
/// Convert from `Event` type to `OpenAPILambdaRequest`
3232
/// - Parameters:

Sources/OpenAPILambdaHandler.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public struct OpenAPILambdaHandler<L: OpenAPILambda>: LambdaHandler {
3333
/// - context: Lambda initialization context
3434
public init(context: LambdaInitializationContext) throws {
3535
self.router = TrieRouter()
36-
self.transport = LambdaOpenAPITransport(router: self.router)
36+
self.transport = OpenAPILambdaTransport(router: self.router)
3737
self.lambda = try .init(transport: self.transport)
3838
}
3939

@@ -67,7 +67,7 @@ public struct OpenAPILambdaHandler<L: OpenAPILambda>: LambdaHandler {
6767
return lambda.output(from: lambdaResponse)
6868
}
6969

70-
let router: LambdaOpenAPIRouter
71-
let transport: LambdaOpenAPITransport
70+
let router: OpenAPILambdaRouter
71+
let transport: OpenAPILambdaTransport
7272
let lambda: L
7373
}

Sources/OpenAPILambdaTransport.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ public typealias OpenAPIHandler = @Sendable (HTTPRequest, HTTPBody?, ServerReque
3535
)
3636

3737
/// Lambda Transport for OpenAPI generator
38-
public struct LambdaOpenAPITransport: ServerTransport {
38+
public struct OpenAPILambdaTransport: ServerTransport {
3939

40-
private var router: LambdaOpenAPIRouter
40+
private var router: OpenAPILambdaRouter
4141

42-
/// Create a `LambdaOpenAPITransport` with the given `LambdaOpenAPIRouter`
43-
public init(router: LambdaOpenAPIRouter) { self.router = router }
42+
/// Create a `OpenAPILambdaTransport` with the given `OpenAPILambdaRouter`
43+
public init(router: OpenAPILambdaRouter) { self.router = router }
4444

4545
/// Registers an HTTP operation handler at the provided path and method.
4646
/// - Parameters:

Sources/Router/OpenAPILambdaRouter.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ import Foundation
1717
import HTTPTypes
1818

1919
/// Errors returned by the router
20-
public enum LambdaOpenAPIRouterError: Error {
20+
public enum OpenAPILambdaRouterError: Error {
2121
case noRouteForPath(String)
2222
case noHandlerForPath(String)
2323
case noRouteForMethod(HTTPRequest.Method)
2424
}
2525

2626
/// A router API
27-
public protocol LambdaOpenAPIRouter {
27+
public protocol OpenAPILambdaRouter {
2828
/// add a route for a given HTTP method and path and associate a handler
2929
func add(method: HTTPRequest.Method, path: String, handler: @escaping OpenAPIHandler) throws
3030

Sources/Router/OpenAPILambdaRouterTrie.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import HTTPTypes
1616

1717
/// A Trie router implementation
18-
public struct TrieRouter: LambdaOpenAPIRouter {
18+
public struct TrieRouter: OpenAPILambdaRouter {
1919
private let uriPath: URIPathCollection = URIPath()
2020

2121
/// add a route for a given HTTP method and path and associate a handler
@@ -88,16 +88,16 @@ struct URIPath: URIPathCollection {
8888
/// - the OpenAPIHandler for this path
8989
/// - the OpenAI ServerRequestMetadata (a [String:String] with parameter names and their values
9090
/// - Throws:
91-
/// - LambdaOpenAPIRouterError.noRouteForPath when there is no handler in the graph for the given combination of HTTP method and path
92-
/// - LambdaOpenAPIRouterError.noRouteForMethod when there is no handler for that HTTP method
93-
/// - LambdaOpenAPIRouterError.noHandlerForPath when there is no handler as leaf node of the tree. This is a programming error and should not happen
91+
/// - OpenAPILambdaRouterError.noRouteForPath when there is no handler in the graph for the given combination of HTTP method and path
92+
/// - OpenAPILambdaRouterError.noRouteForMethod when there is no handler for that HTTP method
93+
/// - OpenAPILambdaRouterError.noHandlerForPath when there is no handler as leaf node of the tree. This is a programming error and should not happen
9494
func find(method: HTTPRequest.Method, path: String) throws -> (OpenAPIHandler, OpenAPILambdaRequestParameters) {
9595
var parameters: OpenAPILambdaRequestParameters = [:]
9696
let root: Node = root()
9797

9898
// first node is the HTTP Method
9999
guard let nodeHTTP = root.children[method.rawValue] else {
100-
throw LambdaOpenAPIRouterError.noRouteForMethod(method)
100+
throw OpenAPILambdaRouterError.noRouteForMethod(method)
101101
}
102102

103103
// search for each path component. If a component is not found, it might be a parameter
@@ -125,18 +125,18 @@ struct URIPath: URIPathCollection {
125125
currentNode = child
126126
}
127127
else {
128-
throw LambdaOpenAPIRouterError.noRouteForPath(path)
128+
throw OpenAPILambdaRouterError.noRouteForPath(path)
129129
}
130130
}
131131
}
132132

133133
//at this stage, current node must have a handler child
134134
guard let handlerNode = currentNode.handlerChild() else {
135-
throw LambdaOpenAPIRouterError.noHandlerForPath(path)
135+
throw OpenAPILambdaRouterError.noHandlerForPath(path)
136136
}
137137

138138
// did we found an handler ?
139-
guard let handler = handlerNode.value.handler else { throw LambdaOpenAPIRouterError.noHandlerForPath(path) }
139+
guard let handler = handlerNode.value.handler else { throw OpenAPILambdaRouterError.noHandlerForPath(path) }
140140
return (handler, parameters)
141141
}
142142

assets/swift-openapi-lambda.gif

799 KB
Loading

0 commit comments

Comments
 (0)