tapir icon indicating copy to clipboard operation
tapir copied to clipboard

Support for plain JSON bodies from raw Strings

Open aartigao opened this issue 3 years ago • 2 comments

This PR adds support for using plain String with JSON body without needing specialized JSON codecs.

Sometimes I find myself repeating this piece of code across the projects I'm working on. There are cases where you already have in place a valid JSON String without needing to use a third party JSON codec. If you use stringBody the Content-Type header is set to text/plain while with this is set to application/json.

For example, my last use case: files generated with sbt-buildinfo have a val toJson: String field. But this can also apply to other patterns, like returning the contents of JSON files stored in the server or coming directly from DB (like PostgreSQL JSON columns).

Sorry I didn't create an Issue for this, but the changes are so little that I've preferred to open the PR directly. Feel free to comment here 🙏🏽

aartigao avatar Jul 08 '22 11:07 aartigao

Thanks, unfortunately this breaks bin compat (adding a method to a trait). I'll have to think if we can somehow ignore or fix this.

adamw avatar Jul 18 '22 11:07 adamw

Oh man... what a pity 😢 I feel that the life of a library maintainer is though if you can't evolve your interfaces 🤯

aartigao avatar Jul 19 '22 06:07 aartigao

It just dawned on me, that adding a field is a bin compat problem, not a method ;) better late than never!

adamw avatar Sep 23 '22 10:09 adamw