Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuawright11 committed May 26, 2024
1 parent 030108b commit 926b2ef
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion PapyrusCore/Sources/Macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public macro Routes() = #externalMacro(module: "PapyrusPlugin", type: "RoutesMac
@attached(peer, names: suffixed(Mock))
public macro Mock() = #externalMacro(module: "PapyrusPlugin", type: "MockMacro")

// MARK: Function or Protocol attributes
// MARK: Protocol or Function attributes

@attached(peer)
public macro Headers(_ headers: [String: String]) = #externalMacro(module: "PapyrusPlugin", type: "DecoratorMacro")
Expand Down
12 changes: 6 additions & 6 deletions PapyrusPlugin/Sources/Macros/APIMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ extension API {
// 2. builder used by all live endpoint functions

Declaration("func builder(method: String, path: String) -> RequestBuilder") {
if modifiers.isEmpty {
if attributes.isEmpty {
"provider.newBuilder(method: method, path: path)"
} else {
"var req = provider.newBuilder(method: method, path: path)"

for modifier in modifiers {
for modifier in attributes {
modifier.builderStatement()
}

Expand All @@ -63,10 +63,10 @@ extension API.Endpoint {

"var req = builder(method: \(method.inQuotes), path: \(path.inQuotes))"

// 1. add function scope modifiers
// 1. add function scope attributes

for modifier in modifiers {
modifier.builderStatement()
for attribute in attributes {
attribute.builderStatement()
}

// 2. add parameters
Expand Down Expand Up @@ -108,7 +108,7 @@ extension EndpointParameter {
}
}

extension EndpointModifier {
extension EndpointAttribute {
fileprivate func builderStatement() -> String {
switch self {
case .json(let encoder, let decoder):
Expand Down
14 changes: 7 additions & 7 deletions PapyrusPlugin/Sources/Models/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import SwiftSyntax

struct API {
struct Endpoint {
/// Modifiers to be applied to this endpoint. These take precedence
/// over modifiers at the API scope.
let modifiers: [EndpointModifier]
/// Attributes to be applied to this endpoint. These take precedence
/// over attributes at the API scope.
let attributes: [EndpointAttribute]
let method: String
let path: String
let pathParameters: [String]
Expand All @@ -18,8 +18,8 @@ struct API {
let name: String
/// The access level of the API (public, internal, etc).
let access: String?
/// Modifiers to be applied to every endpoint of this API.
let modifiers: [EndpointModifier]
/// Attributes to be applied to every endpoint of this API.
let attributes: [EndpointAttribute]
let endpoints: [Endpoint]
}

Expand All @@ -32,7 +32,7 @@ extension API {
return API(
name: proto.protocolName,
access: proto.access,
modifiers: proto.protocolAttributes.compactMap { EndpointModifier($0) },
attributes: proto.protocolAttributes.compactMap { EndpointAttribute($0) },
endpoints: try proto.functions.map( { try parse($0) })
)
}
Expand All @@ -44,7 +44,7 @@ extension API {

let (method, path, pathParameters) = try parseMethodAndPath(function)
return API.Endpoint(
modifiers: function.functionAttributes.compactMap { EndpointModifier($0) },
attributes: function.functionAttributes.compactMap { EndpointAttribute($0) },
method: method,
path: path,
pathParameters: pathParameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SwiftSyntax

/// To be parsed from protocol and function attributes. Modifies requests /
/// responses in some way.
enum EndpointModifier {
enum EndpointAttribute {
case json(encoder: String, decoder: String)
case urlForm(encoder: String)
case multipart(encoder: String)
Expand Down
6 changes: 3 additions & 3 deletions PapyrusPlugin/Sources/Models/EndpointParameter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ struct EndpointParameter {
} else if type.hasPrefix("Query<") {
.query
} else if pathParameters.contains(name) {
// if name matches a path param, assume this belongs in path
// if name matches a path param, infer this belongs in path
.path
} else if ["GET", "HEAD", "DELETE"].contains(httpMethod) {
// if method is GET, HEAD, DELETE, assume query
// if method is GET, HEAD, DELETE, infer query
.query
} else {
// otherwise assume it's a body field
// otherwise infer it's a body field
.field
}
}
Expand Down

0 comments on commit 926b2ef

Please sign in to comment.