Open j-f1 opened 4 years ago
Great point. What do you think about doing something like CodingKey
?
enum AppRoutes: Routes {
case firstRoute
case secondRoute(arg: Int)
enum RoutingKeys: String, RoutingKey {
case firstRoute = "first-route"
case secondRoute = "second-route"
}
}
And maybe a RouteEncodingStrategy
for common ones:
enum AppRoutes: Routes {
static let encodingStrategy = .snakeCase
// Or
static let encodingStrategy = SnakeCaseRouteEncodingStrategy()
case firstRoute
case secondRoute(arg: Int)
}
How about a combination of the two?
enum AppRoutes: Routes {
static let encodingStrategy = .snakeCase
// Or
static let encodingStrategy = Routes.Strategy { route in
switch route {
case firstRoute: return "first_route"
case secondRoute: return "second_route"
}
}
case firstRoute
case secondRoute(arg: Int)
}
Ok, I got something implemented in abe322a & fa4374f:
enum AppRoutes: Routes {
static let codingStrategy = KebabCaseRouteCodingStrategy()
...
}
A custom RouteCodingStrategy
could be made as well:
struct CustomRouteCodingStrategy: RouteCodingStrategy {
init() {}
public func encode(_ components: [String]) -> String {
// Join with a separator or do something fancier.
}
}
Default is CamelCaseRouteCodingStrategy
and enum cases are expected to be camelCase. We could probably check if they are snake_case/PascalCase though.
The standard for names in Swift is camelCase, but most websites use kebab-case for URL components. I see three different ways to reconcile this:
I think a combination of 2 and 3 would be best, providing sensible defaults while allowing users to potentially port existing URLs over to Tokamak, but I’m willing to have my mind changed!