by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 15:12
    devsprint commented #642
  • 14:50
    adamw commented #658
  • 13:02
    kubukoz commented #658
  • 08:18
    ghostbuster91 commented #658
  • 07:25
    adamw commented #658
  • Jul 13 14:00
    kubukoz edited #658
  • Jul 13 14:00
    kubukoz edited #658
  • Jul 13 13:59
    kubukoz opened #658
  • Jul 13 09:16
    ghostbuster91 opened #657
  • Jul 12 19:22

    mergify[bot] on master

    Update cats-effect to 2.1.4 Merge pull request #656 from sc… (compare)

  • Jul 12 19:22
    mergify[bot] closed #656
  • Jul 12 19:14
    scala-steward opened #656
  • Jul 12 18:27
    kciesielski labeled #655
  • Jul 12 18:26
    kciesielski labeled #655
  • Jul 12 18:25
    kciesielski opened #655
  • Jul 12 11:06

    mergify[bot] on master

    Update catbird-effect, catbird-… Merge pull request #654 from sc… (compare)

  • Jul 12 11:06
    mergify[bot] closed #654
  • Jul 12 10:58
    scala-steward opened #654
  • Jul 10 22:05

    mergify[bot] on master

    Update scalafmt-core to 2.6.3 Merge pull request #653 from sc… (compare)

  • Jul 10 22:05
    mergify[bot] closed #653
Yatheesha Lokesha
@yatheesha-agoda
@usommerl thanks for response, I wanted to display in swagger doc, I will go with stringbody

@usommerl is it possible to specify multiple Content-Type in header for octate-stream ? I tried adding

.out(header(HeaderNames.ContentType, "image/jpeg,application/pdf"))

it didnt work for me, The requirement is I need to stream binary of images and pdf in same endpoint

1 reply
Yatheesha Lokesha
@yatheesha-agoda

@usommerl is it possible to specify multiple Content-Type in header for octate-stream ? I tried adding

.out(header(HeaderNames.ContentType, "image/jpeg,application/pdf"))

it didnt work for me, The requirement is I need to stream binary of images and pdf in same endpoint

also image type can be either png or jpeg

Jakub Kozłowski
@kubukoz
Is there any work going on to support generating client code from tapir endpoints? I mean non-scala, like typescript
1 reply
I found tapir-gen but it seems to still be in the WIP phase
wookievx
@wookievx
Hello every one. Is there any-way currently to model API that either returns json body or no response body. I can handle this by catching: DecodeResult.Error(original, error), but this would be more of a hack then actual solution.
2 replies
sean
@nothergeek_twitter
Hi all 👋
Do tapir auth inputs interop with http4s' own auth middleware? Or are they completely separate things?
1 reply
Антон Войцишевский
@FunFunFine

Hello everyone!
Is it possible to define endpoint with some kind of pattern matching on the body of request?
Something like that

case class Request[A](method: String, body: A)

val myMatchingEndpoint = endpoint.post.in(jsonBody[Request[SomeClass]].when(_.method == "some_method")).out(plainText)

I want this endpoint only to accept requests when Request.method is "some_method".
Of course I can define custom Validator, but I have plenty of those pattern-matching endpoints (it's JSON RPC) so it wouldn't work well

2 replies

I know about status code mapping, so it would be nice to have something like that for input

endpoint.in(oneOf[Request[A]](
    bodyMapping(_.method == "some_method", jsonBody[Request[SomeClass]].description("some method")),
    bodyMapping(_.method == "other_method", jsonBody[Request[OtherMethod]].description("other method"))
 )

Is there a way this can be implemented if not already?

Brian Kent
@bdkent

Hello! I am trying to define a Schema.oneOf and am getting a macro error. Is there something obvious I am donig wrong?

I have tried to narrow down to a simple case:

sealed trait Thing
case class ThingSimple(s: String) extends Thing
trait ThingSchemas {
  def toKind(t: Thing): String = {
    t match {
      case _: ThingSimple => "simple"
    }
  }
  implicit val ThingSimpleSchema = implicitly[Schema[ThingSimple]]
  implicit val ThingSchema: Schema[Thing] = Schema.oneOf[Thing, String](toKind, identity)(
    "simple" -> ThingSimpleSchema,
  )
}

results in:

exception during macro expansion: 
 java.lang.ClassCastException: scala.reflect.internal.Trees$Block cannot be cast to scala.reflect.api.Trees$FunctionApi
     at sttp.tapir.generic.internal.OneOfMacro$.oneOfMacro(OneOfMacro.scala:46)
   implicit val ThingSchema: Schema[Thing] = Schema.oneOf[Thing, String](toKind, identity)(
Brian Kent
@bdkent
hmmmm, so if I change toKind to toKind _ or t => toKind(t), then it compiles.
1 reply
Brian Kent
@bdkent

That was actually not my main question. My main issue is that I am unable to define a oneOf schema that is recursive on the trait when the recursion is in a container like Option/List/etc.
If we expand the Thing type above to:

sealed trait Thing
case object ThingObject extends Thing
case class ThingSimple(s: String) extends Thing
case class ThingSingle(thing: Thing) extends Thing
case class ThingMaybe(thing: Option[Thing]) extends Thing
case class Things(things: List[Thing]) extends Thing

as soon as I add the equivalent mapping for ThingMaybe or Things I get an NPE, either:

Caused by: java.lang.NullPointerException
     at sttp.tapir.Schema$.schemaForOption(Schema.scala:111)

or

Caused by: java.lang.NullPointerException
     at sttp.tapir.Schema$.schemaForIterable(Schema.scala:115)

Is this a known limitation? Is there a work around?

5 replies
Pascal Mengelt
@pme123

How to provide Layers for toRoutesR:

lazy val deployCreateLogic: URIO[Logging, HttpRoutes[Task]] =
    deployCreate.toRoutesR[Logging](dm =>
      deployMultipart(dm)
    )

I tried something like this: deployCreateLogic.provideCustomLayer(loggingLayer)

1 reply
Bartosz Bąbol
@BBartosz
I have created bug report, not sure its tapir or circe: softwaremill/tapir#606 but definetely some non deterministic behavior
Alexander Van Hecke
@alexandervanhecke
Hi all, I was taking my first steps with tapir ... seems very interesting. I tried to get a minimal example going, but keep getting NoSuchMethodErrors
2 replies
object Test extends IOApp {
  implicit val customServerOptions: Http4sServerOptions[IO] = Http4sServerOptions.default[IO]

  private val happyEndPoint = endpoint.get
    .in("happy" / "status")
    .errorOut(
      oneOf(
        statusMapping(StatusCodes.InternalServerError, plainBody[String])
      )
    )
    .out(plainBody[String])

  val service: HttpRoutes[IO] = happyEndPoint.toRoutes(_ => doHappy)

  val doHappy: IO[Either[String, String]] = "I am so happy right now".asRight[String].pure[IO]

  def run(args: List[String]): IO[ExitCode] =
    for {
      pnoService <- service.pure[IO]
      server <- BlazeServerBuilder[IO](ExecutionContext.global)
                 .bindHttp(8088, "0.0.0.0")
                 .withHttpApp(Router("/po" -> pnoService).orNotFound)
                 .serve
                 .compile
                 .drain
                 .as(ExitCode.Success)
    } yield server

}
this doesnt start :
Exception in thread "main" java.lang.NoSuchMethodError: org.http4s.HttpRoutes$.apply(Lscala/Function1;Lcats/effect/Sync;)Lcats/data/Kleisli;
    at tapir.server.http4s.EndpointToHttp4sServer.toRoutes(EndpointToHttp4sServer.scala:22)
    at tapir.server.http4s.TapirHttp4sServer$RichHttp4sHttpEndpoint.toRoutes(TapirHttp4sServer.scala:18)
    at ....mocksupport.po.Test$.<clinit>(FakePno.scala:207)
    at ....mocksupport.po.Test.main(FakePno.scala)
I'm using tapir v 0.11.11, scala 2.13, and explicitly managed versions of of cats (2.1.1) and circe (0.13.0)
  val tapirExclusions = List(
    ExclusionRule().withOrganization("org.typelevel"),
    ExclusionRule().withOrganization("io.circe")
  )
  val tapirCore      = "com.softwaremill.tapir" %% "tapir-core"               % tapirVersion excludeAll (tapirExclusions: _*)
  val tapirHttp4s    = "com.softwaremill.tapir" %% "tapir-http4s-server"      % tapirVersion excludeAll (tapirExclusions: _*)
  val tapirSwaggerUI = "com.softwaremill.tapir" %% "tapir-swagger-ui-http4s"  % tapirVersion excludeAll (tapirExclusions: _*)
  val tapirOpenApi   = "com.softwaremill.tapir" %% "tapir-openapi-docs"       % tapirVersion excludeAll (tapirExclusions: _*)
  val tapirCirceYaml = "com.softwaremill.tapir" %% "tapir-openapi-circe-yaml" % tapirVersion excludeAll (tapirExclusions: _*)
  val tapirCirce     = "com.softwaremill.tapir" %% "tapir-json-circe"         % tapirVersion excludeAll (tapirExclusions: _*)
I feel like I'm missing something very obvious here ... any thoughts?
Per Øyvind Kanestrøm
@perok
Hi! Is there a reason for PartialServerEndpoint to not extend EndpointErrorOutputsOps?
5 replies
vonchav
@voonchav_gitlab
Hi @adamw, the latest Tapir release 0.15.4 is still using sttp-client 2.1.5 and yet they were both updated and released today. I suppose another Tapir release is already in the works :) It'd be nice that I upgrade both to the latest and greatest :)
9 replies
BTW, I assume Tapir 0.15.4 is a minor release. And sttp-client 2.2.0 is a bigger release to deserve the version bump. So what's new in sttp-client?
1 reply
Nick Childers
@Voltir
@adamw I spent more time continuing my foray into multipartBodies and one problem im running in to is supporting streaming body types as part of a multipart body. It looks like there are only a finite number of allowed types per how RawBodyType is implemented, and they all materialize the body into memory - I was looking for something like a Part[Source[ByteString, Any]], which seems like it should be easy to implement from the perspective of the akka-tapir integration (its just the entity.dataBytes after all), but threading that type through the rest of the sttp machinery seems.. complicated.
10 replies
maybe RawBodyType could take a second parameter (the backend's stream type), but that might open pandora's box
Denis Novac
@DenisNovac
Hi everyone. I just wanted to push branch to tapir, but got "ERROR: Permission to softwaremill/tapir.git denied to DenisNovac.". Is tapir closed for PRs?
Denis Novac
@DenisNovac
Oh, it is done through fork, now i get it
dharm82465
@dharm82465
Hello, I am curious if it is possible to create Tapir endpoint that matches either path /userId or /accountId. Something similar to pipe operator (|) used in Akka-Http
1 reply
Антон Войцишевский
@FunFunFine

Hi!
How can I access URI of called method in the handler?
Http4s allows me to call uri on request like that:

case req @ GET -> Root =>  Ok(req.uri.toString)

Is it possible to do the same with tapir?

3 replies
Uwe Sommerlatt
@usommerl

Hi. I'm getting the following exception when I run a service that is using tapir, and that was packaged as a fat jar:

java.lang.NullPointerException
    at sttp.tapir.swagger.http4s.SwaggerHttp4s.<init>(SwaggerHttp4s.scala:36)

I use sbt assembly for packaging. The service is working fine if I don't use a fat jar. Has anyone here encountered this issue? I would be glad for any pointers!

edit: I'm using tapir v0.15.4 and sbt-assembly v0.14.0

7 replies
Mateusz Ligęza
@mrForest13
Hello, is there any reason why SwaggerHttp4s has "redirectQuery" and SwaggerAkka not? version 0.16.1
1 reply
Mateusz Wójcik
@matwojcik
@adamw Are there any plans to start keeping brief release notes for both tapir and sttp (at least for major/minor version updates)? I believe it would make more people aware of new features and places that could break after release :)
4 replies
Gergő Törcsvári
@tg44
hy! can sb help me with a snippet?
https://gist.github.com/tg44/8649649b01dfefde2c55428f40d29bf3
(pbpaste > script.sc && amm script.sc)
It compiles, but runtime I get Error during processing of request: 'Outputs and output values don't match in output I think this is bcs of the val emptyResponse, but I think I use that right.
3 replies
Антон Войцишевский
@FunFunFine

Hi!
How to correctly define custom schemas for cases of Enumeratum's enum?

I have this enum and a schema for it defined as in documentation here:

sealed trait RuleInspectType extends EnumEntry

object RuleInspectType extends Enum[RuleInspectType] with CirceEnum[RuleInspectType] with Uppercase {
  case object Probe extends RuleInspectType
  case object Manual extends RuleInspectType
  case object Wait extends RuleInspectType
  implicit val sEntity: Schema[RuleInspectType] =
    Schema.oneOf[RuleInspectType, String](_.entryName, identity)(
      "PROBE" -> Schema(SchemaType.SString).description(
        "probe decr"
      ),
      "MANUAL" -> Schema(SchemaType.SString).description(
        "manual descr."
      ),
      "WAIT" -> Schema(SchemaType.SString).description(
        "wait descr."
      )
    )

  override def values: IndexedSeq[RuleInspectType] = findValues
}

I am also using tapir-enumeratum integration, but at the start of application I get weird runtime error:

java.lang.ClassCastException: sttp.tapir.SchemaType$SString$ cannot be cast to sttp.tapir.SchemaType$SObject
1 reply
Jules Ivanic
@guizmaii

Hi everyone,

I’m trying to use Scala-newtype with Tapir.

If replace some types (String) by some newtypes in my request datatype, then I have this error:

Cannot find a codec for type: Request, formatted as: sttp.tapir.CodecFormat.Json.
Did you define a codec for: Request?
Did you import the codecs for: sttp.tapir.CodecFormat.Json?
Is there an implicit schema for: Request, and all of its components?
(codecs are looked up as implicit values of type Codec[Request, sttp.tapir.CodecFormat.Json, _];
schemas are looked up as implicit values of type Schema[Request])

I’m still using Tapir 0.12.

Does anyone know how to fix that?

14 replies
vonchav
@voonchav_gitlab
@adamw I suppose a release with ZIO RC21 is already in the works? :)
4 replies
vonchav
@voonchav_gitlab
Hello all, has anyone ever tried, with Tapir, setting the outgoing header to some cache-control? I suppose it'd be something like .out(header[String]("cache-control: ???") This seems to mess up Tapir's serverLogic signature. @adamw, any example of setting headers when returning?
1 reply
PawelJ-PL
@PawelJ-PL
Hi. I'm trying to migrate to serverLogicForCurrent from andThenFirstE (because it's deprecated now). But I have no idea, how to turn PartialServerEndpoint[_, _, _, _] back to Endpoint[_, _, _, _]. I need Endpoint, because it's required by toOpenApi extension method.
2 replies
Jakub Kozłowski
@kubukoz
Hi, is there any automatic derivation for TextPlain codecs for, let's say, value classes?
1 reply
fjbenitog
@fjbenitog
Hi, I have an issue after updating to version 0.13.2,
[error] scala.reflect.macros.TypecheckException: could not find implicit value for parameter e: sttp.tapir.Schema[MyClass]
The error is happening when the case class has more than 7 fields
17 replies
profic
@profic
Hi, is there an option to add an example to Schemas? I have following open API peace and seems like sttp.tapir.Schema does not have a field "example", but there is sttp.tapir.openapi.Schema#example
client_id:
    type: string
    description: Unique ID of the client
    example: my_unique_id
2 replies
Michał Pawlik
@majk-p

Hi,
I have an endpoint, something like:

baseEndpoint
    .in("api")
    .in(path[String]("item"))
    .in("delete")
    .out(jsonBody[Unit])
    .description("deletes the item")

This endpoint doesn't require any json body, but I'd like it to require Content-Type: application/json header.
Is there any simple way to do this in tapir?

3 replies
Henry
@hygt
Hello, I use a custom failure handler with badRequestOnPathErrorIfPathShapeMatches = true as suggested by the documentation, it's working as expected for endpoints like /foo/{path-param} but not with something like /foo/{path-param}?{queryParam} where I get 404 for anything that doesn't get validated by the path param codec
3 replies
Yatheesha Lokesha
@yatheesha-agoda
could anyone help how I can use existing authentication feature available in akka
def authenticateOAuth2Async[T](realm: String, authenticator: AsyncAuthenticator[T]): AuthenticationDirective[T]
1 reply
ionutioio
@ionutioio

Hello, in one of my exposed objects I have Set[Enum] as an attribute.
The swagger isn't generated correctly:

myAttribute:
          type: array
          items:
            type: string
            enum:
            - ENUM1
            - ENUM2
            - ENUM3
            - ENUM4
          enum:
          - ENUM1
          - ENUM2
          - ENUM3
          - ENUM4

What can I do about it? The enum uses TapirCodecEnumeratum

4 replies
Loránd Szakács
@lorandszakacs

folks, does anyone have a nice pattern of working with tapir and http4s' AuthMiddleware? I'm trying to incrementally rewrite endpoint definitions in tapir, and honestly, keeping the logic in AuthMiddleware is a tad bit essential. Honestly, I don't even mind if tapir doesn't know about the auth token and it doesn't show up in documentation. I care more about authentication working exactly as it did before.

I'll figure it out eventually, but if I don't have to reinvent the wheel, then even better

2 replies
dadanoq
@lp33pp66

Hello, I have an Enum as an attribute.
When I give an implicit value for naming policy,
The swagger isn’t generated correctly:

object MyEnum extends Enumeration with EnumHelper {
    type Type = Value
    val aaa = Value("AAA")
    val bbb = Value("BBB")
  }

  case class MyClass(myAttribute: MyEnum.Type)

  implicit val customConfiguration: Configuration =
    Configuration.default.withSnakeCaseMemberNames

  val baseEndpoint = endpoint.post.in(jsonBody[MyClass])

toYaml:

```yaml =
schemas:
MyClass:
required:

  - my_attribute
  type: object
  properties:
    my_attribute:
      type: string

```
What can I do about it?

1 reply
Srepfler Srdan
@schrepfler
hi folks, is there any extension to Tapir to support Lagom services? Or if not, how can one go about to implement one?
Stefanqn
@Stefanqn
Hi, is it possible to create tapir Endpoints from an openAPI-spec? (start from an openAPI definition)