swift-url-routing
swift-url-routing copied to clipboard
Weird compilation error on Route parsing
Hi, I was trying to model an existing API but I'm encountering a problem.
Example:
This is one of the urls: BASE_URL/somepath/SOME_STRING_VAR/ANOTHER_STRING_VAR.
The method is POST and it has a String body.
I was trying to model it like this:
enum SiteRoute {
case somepath(var1: String, var2: String, body: String)
}
...
let router = OneOf {
Route(.case(SiteRoute.somepath)) {
Method.post
Path {
"someroute"
Parse(.string)
Parse(.string)
}
Body(?) // I can't figure out what to put here.
}
}
If I define the model like this, instead:
enum SiteRoute {
case somepath(var1: String, var2: String, body: SomeModel)
}
...
let router = OneOf {
Route(.case(SiteRoute.somepath)) {
Method.post
Path {
"someroute"
Parse(.string)
Parse(.string)
}
Body(.json(SomeModel.self))
}
}
It throws me this compile error.

How can I solve this (theoretically shouldn't be) complicated task? I'm sure there's something I'm missing. Thanks in advance.