Skip to content

Commit 1197bb4

Browse files
committed
Put query string into the path for OpenAPIGenerator code
1 parent a59a572 commit 1197bb4

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

Sources/HttpApi/APIGatewayV2+HTTPRequest.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ import OpenAPIRuntime
1818

1919
extension APIGatewayV2Request {
2020

21+
// OpenAPIGenerator expects the path to include the query string
22+
var pathWithQueryString: String {
23+
rawPath + (rawQueryString.isEmpty ? "" : "?\(rawQueryString)")
24+
}
25+
2126
/// Return an `HTTPRequest` for this `APIGatewayV2Request`
2227
public func httpRequest() throws -> HTTPRequest {
2328
HTTPRequest(
2429
method: self.context.http.method,
2530
scheme: "https",
2631
authority: "",
27-
path: self.rawPath,
32+
path: pathWithQueryString,
2833
headerFields: self.headers.httpFields()
2934
)
3035
}

Sources/Router/OpenAPILambdaRouterTrie.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct URIPath: URIPathCollection {
101101
}
102102

103103
// search for each path component. If a component is not found, it might be a parameter
104-
let pathComponents = path.split(separator: "/")
104+
let pathComponents = path.prefix(while: { $0 != "?" }).split(separator: "/")
105105
var currentNode = nodeHTTP
106106
for component in pathComponents {
107107
if let child = currentNode.child(with: component) {

Tests/OpenAPILambdaTests/Router/RouterGraphTest.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,18 +323,26 @@ struct RouterGraphTests {
323323

324324
//when
325325
#expect(throws: Never.self) { try graph.find(method: method, path: pathToTest) }
326-
let (handler, metadata) = try graph.find(method: method, path: pathToTest)
326+
let (handler, metadata) = try graph.find(method: method, path: pathToTest )
327327
#expect(metadata.count == 0)
328328
#expect(handler != nil)
329329
}
330330

331-
@Test("Find handler 2")
332-
func testFindHandler2() throws {
331+
@Test(
332+
"Find handler 2",
333+
arguments: [
334+
"/element3/value1/element4",
335+
"/element3/value2/element4",
336+
"/element3/value1/element4?param1=value1"
337+
]
338+
)
339+
func testFindHandler2(
340+
pathToTest: String
341+
) throws {
333342
// given
334343
let strMethod = "GET"
335344
let method = HTTPRequest.Method(strMethod)!
336345
let graph = prepareGraphForFind(for: method)
337-
let pathToTest = "/element3/value1/element4"
338346

339347
//when
340348
#expect(throws: Never.self) { try graph.find(method: method, path: pathToTest) }

0 commit comments

Comments
 (0)