sttp-apispec
sttp-apispec copied to clipboard
Add support for server variables
This is a part of softwaremill/tapir#11
I decided to extract it since it is a big feature.
So I was thinking about possible dsl for server variables and we cannot use endpoint dsl here because of two reasons:
- variables can be anywhere e.g. schema could be a variable.
- variables must have a default value and optionally possible values
I came up with sth like this:
val v1 = Variable("v1", defaultValue=123).values(123, 456)
val server = Server(v"https://api.${v1}.io")
where v"" is a custom interpolator which does sth like that:
import tapir.docs.openapi.StringInterpolation._
val serverVariable = Variable("v1", defaultValue = 5)
val result = v"kasper/$a"
result shouldBe List(Constant("kasper/"), serverVariable)
To be honest, I don't think it's a frequently used swagger feature (at least in my impression, I might be wrong of course). So I think it would be more than enough to just allow adding server variables to a model generated by tapir (but here just using case classes copy + possible quicklens might be enough).