Questions tagged [tapir]

Tapir is a declarative, type-safe web endpoints library, written in Scala. The endpoints can be interpreted as a server (integrating with akka http, http4s, play, finatra, vertx and others), as a client (using sttp client) or as openapi / asyncapi documentation.

The tapir source code is available on GitHub. Usage documentation is also available.

Tapir endpoints are described as values, using a Scala API. Thanks to Scala's type system, a number of properties are checked at compile-time.

35 questions
1
vote
2 answers

Compilation problem between HttpRoutes[RIO[E, *]] and HttpRoutes[zio.Task]

Trying to compile this small ZIO friendly Tapir/Http4s Endpoint description import io.circe.generic.auto._ import org.http4s.HttpRoutes import sttp.tapir.json.circe import sttp.tapir.ztapir._ import sttp.tapir.server.http4s.ztapir._ import…
arinray
  • 178
  • 1
  • 12
1
vote
0 answers

Status field in json with Tapir

How could I add status field into json response in Tapir? Assume, I have endpoint which looks like this: private lazy val endpoint = endpoint .post .in(jsonBody[Entity]) .out(jsonBody[ChangedEntity]) .errorOut(jsonBody[Error]) …
1
vote
1 answer

Tapir, Circe, Snakecase

I have a code below import io.circe.generic.auto._ import io.circe.Encoder import io.circe.generic.extras._, io.circe.syntax._ implicit val config: Configuration = Configuration.default.withSnakeCaseMemberNames case class User(firstName: String,…
Arjun Karnwal
  • 379
  • 3
  • 13
1
vote
1 answer

Scala - tapir dynamic status codes type mismatching

I am creating an endpoint in tapir that requires dynamic status codes for the error out. I have declared a seal trait FailureResponse and i have created case classes that extends this trait. Similar to the example shown…
Kay
  • 17,906
  • 63
  • 162
  • 270
0
votes
1 answer

Ignore empty fields in jsonBody request and response parsing | sttp.tapir.json.circe.jsonBody

In the below example if i miss any field in the request body than it is giving the error in parsing as missing field. Can we anyway ignore it if the field is not present than it should not give error while parsing request. Also in response if the…
0
votes
1 answer

Tapir seperate static file endpoint description and server logic

I need to serve a small set of static files using tapir with http4s as the implementation. All endpoint definitions are in their own files and exposed using swagger. The documentation has lots of good examples on serving static files, but without…
jen
  • 357
  • 2
  • 10
0
votes
1 answer

Constructing a Tapir Endpoint from a URL String that Includes query parameters

I need to use an API that returns a url to the next page in its response. My code is written in a way that I need to construct tapir endpoint to make http call. But I don't see a way to transform url string into EndpointInput. The url contains query…
Awethon
  • 144
  • 1
  • 9
0
votes
0 answers

Scala, ZIO, ZStream - how to stream custom data object to endpoint?

I want to stream data from Zstream with some repeat time. I have my main function which returns ZIO: def processData(request: MyRequest): Task[Seq[SomePayload]] I also call this method for every element in my list requests. Now I would like to take…
Developus
  • 1,400
  • 2
  • 14
  • 50
0
votes
1 answer

Tapir custom http code in successful response

I'm using Tapir library for endpoint definition but I need to provide custom http code in a successful response (not to map error to error code). I've found something in the documentation but it's not really useful to me. Could somebody give me…
martyn
  • 136
  • 1
  • 8
0
votes
1 answer

How to get access to the request payload in Tapir/ZIOHttp DefaultServerLog?

We build a REST microservice with Scala 3, ZIO 2, ZIO logging and Tapir. For context specific logging we want to use the MDC and set an attribute there which is taken from the request payload. Is it possible to get access to the request payload in…
Chris W.
  • 2,266
  • 20
  • 40
0
votes
2 answers

Scala, ZIO, Tapir - how to retrieve authorization token from header?

I have created tapir endpoint: val getEndpoint = endpoint.get .securityIn(auth.bearer[String]()) .in("players" / path[PlayerId]("playerId")) .in(query[PlayerRequest]("query")) .errorOut(someErrors) Now, I would like to read all passed…
Developus
  • 1,400
  • 2
  • 14
  • 50
0
votes
2 answers

Scala, ZIO - how to return custom error from ZIO

I have a simple code which using tapir sttp.client3.json._: def method(...): Task[MyResponse] = someLogic().response(asJson[MyResponse]).flatMap(res => ZIO.fromEither(res.body)) But now I want to add here some logic to use custom errors when…
Developus
  • 1,400
  • 2
  • 14
  • 50
0
votes
2 answers

How better organize tapir endpoints?

I am developing a scala web application with http4s and use tapir for endpoints. I am new in it, and now I am looking for a better way to organize my project. Now I have different classes with endpoints description and server logic in one. They have…
Post Cat
  • 1
  • 1
0
votes
0 answers

Scala, ZIO, Tapir - zio-http and tapir, how to create rejection/error handler on API side?

I have a weird problem with error middleweare or I'm using it in wrong way. I would like to add error middleware to my tapir routes and catch all errors from "inside" application. I have simple tapir route: object SomeApi{ val zServerLogic =…
Developus
  • 1,400
  • 2
  • 14
  • 50
0
votes
1 answer

Use tapir router with play-framework without jsr330

I use play framework with tapir. My usage similar to sample https://github.com/gaeljw/tapir-play-sample And we define router like this: @Singleton class ApiRouter @Inject() (apiController: BookController, apiDocumentation: ApiDocumentation,…
zella
  • 4,645
  • 6
  • 35
  • 60