New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comma separated values only works on scala 2.13+ #3343
Comments
I'm aware that this is a Scala 2.13/3-only feature, and this was a conscious decision (Scala 2.12 users are about 9% of tapir's downloads). Unfortunately breaking changes are not possible - we could only do that when bumping the major version of |
Yep, that's what I did indeed. Thanks for the quick answer, then unless this really gets traction I guess it is what it is. What do you think of adding a quick note in the docs ? I could open a PR later today if you think it's a good idea |
Ah yes sure, updating the docs is always good :) |
thanks! |
As mentioned on #3343, Tapir only supports comma-separated values (out of the box, that is) on Scala 2.13+. This small PR makes that explicit in the main documentation, as it would've personally saved me a few minutes. For good measure, I also added a complete runnable example. To be fair, the existing doc page already includes clear code, but I thought a complete example could still be useful. Wdyt? p.s. It's my first contribution to Tapir. It's a very small one and only touches documentation, but still, I'd be extra careful in case I missed something :)
Tapir version: 1.9.2
Hi peps!
Context
A very common use case when defining an endpoint is adding an (optional) filter of "categories".
One way of doing so is as a list of comma-separated values, like
GET /tapirs?cute=true&breed=malayan,baird
Tapir, after this discussion, provides the handy CommaSeparatedValues.
This work perfectly, and the openapi documentation is generated as one would expect in the case of enumerations (with
allowedValues
).The problem
The issue with this is that
CommaSeparated
is defined astype CommaSeparated[T] = Delimited[",", T]
Unfortunately, type literals are only supported in Scala 2.13+. Which means, people using previous versions of Scala can't use this feature :(
One possible solution
The most trivial solution is just to hard-code the comma in CommaSeparated, of course
The disadvantage is that we'd not be reusing the exact same code we use for
Delimited
.What to do next?
I personally see a few options
CommaSeparated
is available for everyone andDelimited
only for Scala 2.13+Delimited
altogether and only keepCommaSeparated
The third option is quite extreme and causes a breaking change of course.
On the other hand, I don't see a real use case for anything other than comma (though clearly you do, so perhaps it's just inexperience on my part), and by making this more generic we're sacrificing the functionality for an interesting portion of Scala users (according to this 2022 survery, about 40% of Scala users still use 2.12 in some projects).
Do we have any kind of metric about how needed this functionality is?
Thanks for reading!
The text was updated successfully, but these errors were encountered: