You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 6.1.0 builds
* update README for 0.3
* API changes
- rename $Routing.prefix to $Routing.$prefix to avoid collision with a route named prefix
- rename resolvedPath to path (path can be a string or a function, depending on the route definition, now)
- add prefixedPath to work like rawPath but with the routing prefix
- remove path from- and add prefixedPath to MacroRoutingRoute (protocol)
+ Update tests
* don't escape arguments unless they need it
Copy file name to clipboardExpand all lines: README.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -96,7 +96,7 @@ The main benefits to this approach are:
96
96
- route lookup with `Controller.$Routing.routeName` where `routeName` is the function name (or declared route name)
97
97
- If you have a `@MacroRouting` controller, a `$Routing` property is synthesized (this is a controller-specific struct, which includes routing info for each of your declared routes), so you can look up routes progrmamatically, and at compile time (so you also get code completion, and you can change route paths by changing the value in `@GET("/login")`, seamlessly, if you don't change the name of `AuthController.logIn`, and you'll get help from the compiler if you *do* rename the `logIn` function.
98
98
- you can still use the normal routing methods, including the documented [`RouteCollection`](https://docs.hummingbird.codes/2.0/documentation/hummingbird/routerguide#Route-Collections) + `addRoutes(…)` based approach
99
-
-`hummingbird-macroroutes` provides a `RouteCollectionContainer` that wraps these to help hint that you shouldn't use the `atPath` signature (see below)
99
+
-`hummingbird-MacroRouting` provides a `RouteCollectionContainer` that wraps these to help hint that you shouldn't use the `atPath` signature (see below)
100
100
- a `.$routes` var is synthesized on the controller to contain this `RouteCollectionContainer`
101
101
- you can construct route paths based on path arguments, all statically, so if anything changes, the compiler will warn you
102
102
@@ -105,7 +105,7 @@ The main benefits to this approach are:
105
105
In your `Package.swift`, put this into your `.dependencies`:
@@ -182,19 +182,19 @@ Additionally, route paths with arguments can be resolved through the synthesized
182
182
}
183
183
```
184
184
185
-
Where you might normally get the logs path with `ApiController.$Routing.logs.path`, here, the path has arguments. `.path` would return `/api/logs/{userId}/{timing}`, which isn't exactly useful for passing to a client if you want them to fetch "my logs for today", for example.
185
+
Where you might normally get the logs path with `ApiController.$Routing.logs.path`, here, the path has arguments. If MacroRouting were to supply `.path` as a `String`, it would return `/api/logs/{userId}/{timing}`, which isn't exactly useful for passing to a client if you want them to fetch "my logs for today", for example.
186
186
187
-
This is where `.resolvedPath` comes in:
187
+
This is where `.path()` comes in:
188
188
189
189
```swift
190
-
let logsPath = ApiController.$Routing.logs.resolvedPath(userId: "123", timing: "2025-05-27")
190
+
let logsPath = ApiController.$Routing.logs.path(userId: "123", timing: "2025-05-27")
191
191
```
192
192
193
193
This will return: `/api/logs/123/2025-05-27`.
194
194
195
-
The argument names are synthesized by the HummingbirdMacroRouting, so they're available to well-behaving editors/IDEs:
195
+
The argument names are synthesized by MacroRouting, so they're available to well-behaving editors/IDEs:
196
196
197
-

197
+

static let prefix: String? = \(prefix ==nil?"nil":"\"\(prefix!)\"")
170
+
static let $prefix: String? = \(prefix ==nil?"nil":"\"\(prefix!)\"")
171
171
"""
172
172
173
173
forroutein routes {
@@ -195,17 +195,25 @@ public struct RoutingMacro: ExtensionMacro {
195
195
struct `\(route.name)`: MacroRoutingRoute {
196
196
private init() {}
197
197
static let method: HTTPRequest.Method = .\(route.method.rawValue.lowercased())
198
-
static let rawPath: String = "\(route.path)"
199
198
static let handler: String = "\(route.handler)"
200
199
static let name: String = "\(route.name)"
200
+
static let prefixedPath: String = "\(prefixedPath)"
201
+
static let rawPath: String = "\(route.path)"
201
202
"""
202
203
203
204
if captured.count >0{
204
-
// for routes that have captured arguments, mark path as deprecated, and provide resolvedPath
205
+
// for routes that have captured arguments, provide path(…) (formerly resolvedPath(…))
205
206
code +="""
206
-
@available(*, deprecated, renamed: "rawPath", message: "path will be removed for routes that have captured arguments; you probably want resolvedPath(…)")
207
-
static let path: String = "\(prefixedPath)"
207
+
@available(*, deprecated, renamed: "path", message: "resolvedPath(…) has been renamed to path(…)")
0 commit comments