sttp-apispec icon indicating copy to clipboard operation
sttp-apispec copied to clipboard

Add support for server variables

Open ghostbuster91 opened this issue 6 years ago • 2 comments

This is a part of softwaremill/tapir#11

I decided to extract it since it is a big feature.

ghostbuster91 avatar Feb 02 '19 22:02 ghostbuster91

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) 

ghostbuster91 avatar Feb 04 '19 22:02 ghostbuster91

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).

adamw avatar Feb 07 '19 15:02 adamw