softwaremill / softwaremill/tapir

Feature request: ability to override servers for concrete endpoint

Open
#648 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
1.5k
Forks
468
Avg merge
5h 37m
Merged PRs (30d)
34

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the Endpoint and EndpointServer entry points shown in the issue, then compare the requested behavior with the linked Swagger server semantics. The work is done when a concrete endpoint can override the default server while preserving the existing server and documentation behavior; the issue does not name tests or implementation files.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, scala
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.