tapir
tapir copied to clipboard
Feature request: ability to override servers for concrete endpoint
With swagger we can override default server for concrete endpoint: https://swagger.io/docs/specification/api-host-and-base-path/
WDYT about adding special syntax to ServerEndpoint ? Out use-case: We have one application server based on tapir which also serves documentation. We also have proxy for application with authorization logic and two domains: secured-api.domain.com and api.domain.com. So most of our method hosted on api.domain.com but few hosted on secured-api.domain.com
case class Endpoint[I, E, O, +S](input: EndpointInput[I], errorOutput: EndpointOutput[E], output: EndpointOutput[O], info: EndpointInfo) {
...
...
def server(server: EndpointServer): Endpoint[I, E, O, S]
def servers(server: EndpointServer, servers: EndpointServer*): Endpoint[I, E, O, S]
}
case class EndpointServer(url: String,
description: Option[String] = None,
variables: Option[ListMap[String, EndpointServer.Variable]] = None) {
def description(d: String): EndpointServer = copy(description = Some(d))
def variables(vars: (String, EndpointServer.Variable)*): EndpointServer = copy(variables = Some(ListMap(vars: _*)))
}
object EndpointServer {
case class Variable(enum: Option[List[String]], default: String, description: Option[String]) {
require(`enum`.fold(true)(_.contains(default)), "ServerVariable#default must be one of the values in enum if enum is defined")
}
}
and we can use it as:
endpoint.get.in("foo" / "bar").server(ServerEndpoint("secured-api.domain.com"))
This refers to softwaremill/sttp-apispec#3