jni
1
Hi, I have an endpoint that looks like this: /foo/<param>.json
.
I am not sure how to describe path components not separated by a / ?
I used this workaround but it’s a bit ugly:
val ep = endpoint.in("foo" / pathWithSuffix[LocalDate]("bar", ".json"))
def pathWithSuffix[T](name: String, suffix: String)(using c: PlainCodec[T]): EndpointInput.PathCapture[T] =
path[String](name)
.map(_.stripSuffix(suffix))(_ + suffix)
.mapDecode(c.rawDecode)(c.encode)
adamw
2
Path segments are always separated by a /
- I think your solution is the correct one from tapir’s point of view.
jni
3
OK, do you think it is worth an addition to the tapir DSL ? Maybe I can come up with some syntax on PathCapture
to end up like:
endpoint.in("foo" / path[T]("bar").withPrefix("baz"))
endpoint.in("foo" / path[T]("bar").withSuffix(".json"))
endpoint.in("foo" / path[T]("bar").surroundedBy("baz", ".json"))
Or in the style of scodec:
endpoint.in("foo" / "baz" ~ path[T]("bar"))
endpoint.in("foo" / path[T]("bar") ~ ".json")
endpoint.in("foo" / "baz" ~ path[T]("bar") ~ ".json")
adamw
4
Sure, this might be a good idea I think I prefer the named variants much more (withPrefix
etc.). The withSuffix
should be especially useful.