Update the route parameter to resource

This commit is contained in:
Ailton Vieira Pinto Filho
2023-06-11 21:21:56 -03:00
committed by Ailton Vieira
parent 30e1dccc88
commit 6c3e36fffe
2 changed files with 4 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ public macro Service() = #externalMacro(module: "SwiftRequestMacros", type: "Ser
@attached(member, names: named(baseURL), named(session), named(init(baseURL:session:)))
@attached(conformance)
public macro Service(route: String) = #externalMacro(module: "SwiftRequestMacros", type: "ServiceMacro")
public macro Service(resource: String) = #externalMacro(module: "SwiftRequestMacros", type: "ServiceMacro")
@attached(peer, names: overloaded)
public macro GET<T: Decodable>(_ path: String, headers: [String: any CustomStringConvertible] = [:]) = #externalMacro(module: "SwiftRequestMacros", type: "GetRequestMacro")

View File

@@ -9,10 +9,10 @@ public struct ServiceMacro: MemberMacro {
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {
let attribute = Attribute(from: node)
let route = attribute.arguments.first?.value
let resource = attribute.arguments.first?.value
let baseUrlExpr = if let route {
"baseURL.appendingPathComponent(\"\(route)\")"
let baseUrlExpr = if let resource {
"baseURL.appendingPathComponent(\"\(resource)\")"
} else {
"baseURL"
}