swift-url-routing icon indicating copy to clipboard operation
swift-url-routing copied to clipboard

Weird compilation error on Route parsing

Open rcasula opened this issue 3 years ago • 0 comments

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. Screenshot 2022-09-13 at 11 11 41

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

rcasula avatar Sep 13 '22 09:09 rcasula