tapir icon indicating copy to clipboard operation
tapir copied to clipboard

Exhaustivity check?

Open Lermex opened this issue 4 years ago • 5 comments

What's the recommended way to turn missing server and/or client routes into compilation errors?

Lermex avatar May 15 '21 00:05 Lermex

How would you define a missing server/client route?

adamw avatar May 15 '21 06:05 adamw

A missing server route would be a route that the client calls but the server does not implement.

I'm not sure if the reverse, routes that exist on the server but not on the client, is a useful thing to check, but I'm just including it for symmetry.

For comparison, this kind of guarantee is something that type-based API description libraries provide, e.g. Servant in Haskell or typedapi / Typed Schema in Scala (see the line Note that now you must implement aloha method in your handler or compile error will be raised in the MkRoute application in Typed Schema docs).

Lermex avatar May 15 '21 10:05 Lermex

Ah, I think I understand what you mean, but that won't be possible here. The individual endpoints don't have unique types, but rather the general Endpoint[I, E, O, R]. And when working with multiple endpoints, we use List[Endpoint[_, _, _, _]] or similar, instead of a fully type-safe tuple.

adamw avatar May 17 '21 10:05 adamw

@adamw I'm currently exploring some ways of doing this using macros / generic programming. I think it could be a great opt-in feature on top of Tapir. Maybe as a separate module? I'll share my results if I get something good.

Lermex avatar May 17 '21 10:05 Lermex

@Lermex sure, though I'd have to see some specific code examples, even if it's just a sketch of the API, to say anything more :). I'll keep this open then.

adamw avatar May 17 '21 10:05 adamw