Skip to content

Commit c410c4c

Browse files
Fix trailing quotes
1 parent 1db40a0 commit c410c4c

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

PapyrusPlugin/Sources/APIAttribute.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ enum APIAttribute {
4242
return nil
4343
}
4444

45-
self = .http(method: name, path: firstArgument)
45+
self = .http(method: name, path: firstArgument.withoutQuotes)
4646
case "HTTP":
4747
guard let firstArgument, let secondArgument else {
4848
return nil
4949
}
5050

51-
self = .http(method: secondArgument.withoutQuotes, path: firstArgument)
51+
self = .http(method: secondArgument.withoutQuotes, path: firstArgument.withoutQuotes)
5252
case "Body":
5353
self = .body
5454
case "Field":

PapyrusPlugin/Sources/APIMacro.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ extension ProtocolDeclSyntax {
6868
extension FunctionDeclSyntax {
6969
fileprivate func apiFunction() throws -> String {
7070
let (method, path) = try apiMethodAndPath()
71+
try validateSignature()
72+
7173
let pathParameters = path.components(separatedBy: "/")
7274
.compactMap { component in
7375
if component.hasPrefix(":") {
@@ -79,14 +81,12 @@ extension FunctionDeclSyntax {
7981
}
8082
}
8183

82-
try validateSignature()
83-
8484
let attributes = parameters.compactMap({ $0.apiAttribute(httpMethod: method, pathParameters: pathParameters) })
8585
try validateAttributes(attributes)
8686

8787
let decl = parameters.isEmpty && apiAttributes.count <= 1 ? "let" : "var"
8888
var buildRequest = """
89-
\(decl) req = builder(method: "\(method)", path: \(path))
89+
\(decl) req = builder(method: "\(method)", path: "\(path)")
9090
"""
9191

9292
for statement in apiAttributes.compactMap({ $0.apiBuilderStatement() }) {

PapyrusPlugin/Tests/APIMacroTests.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,4 +377,44 @@ final class APIMacroTests: XCTestCase {
377377
"""
378378
}
379379
}
380+
381+
func testMultiplePaths() {
382+
assertMacro(["API": APIMacro.self]) {
383+
"""
384+
@API
385+
protocol MyService {
386+
@GET("users/:foo/:b_ar/{baz}/{z_ip}")
387+
func getUser(foo: String, bAr: String, baz: Int, zIp: Int) async throws
388+
}
389+
"""
390+
} expansion: {
391+
"""
392+
protocol MyService {
393+
@GET("users/:foo/:b_ar/{baz}/{z_ip}")
394+
func getUser(foo: String, bAr: String, baz: Int, zIp: Int) async throws
395+
}
396+
397+
struct MyServiceAPI: MyService {
398+
private let provider: PapyrusCore.Provider
399+
400+
init(provider: PapyrusCore.Provider) {
401+
self.provider = provider
402+
}
403+
404+
func getUser(foo: String, bAr: String, baz: Int, zIp: Int) async throws {
405+
var req = builder(method: "GET", path: "users/:foo/:b_ar/{baz}/{z_ip}")
406+
req.addParameter("foo", value: foo)
407+
req.addParameter("b_ar", value: bAr)
408+
req.addParameter("baz", value: baz)
409+
req.addParameter("z_ip", value: zIp)
410+
try await provider.request(req).validate()
411+
}
412+
413+
private func builder(method: String, path: String) -> RequestBuilder {
414+
provider.newBuilder(method: method, path: path)
415+
}
416+
}
417+
"""
418+
}
419+
}
380420
}

0 commit comments

Comments
 (0)