Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 10:52
    mergify[bot] labeled #1557
  • 10:51
    scala-steward opened #1557
  • 09:31

    adamw on master

    Remove unused Adjust exception handling (compare)

  • 09:28

    mergify[bot] on CVE-2021-41084-test

    (compare)

  • 09:28

    adamw on master

    Test to verify invulnerability … actual test to verify broken ht… some backends are vulnerable and 12 more (compare)

  • 09:28
    adamw closed #1508
  • 08:24
    micossow synchronize #1508
  • 08:24

    micossow on CVE-2021-41084-test

    remove the first test case (compare)

  • Oct 26 22:01
    tomasherman commented #1526
  • Oct 26 21:59
    tomasherman synchronize #1526
  • Oct 26 21:41
    tomasherman commented #1526
  • Oct 26 21:34
    tomasherman synchronize #1526
  • Oct 26 13:55
    adamw commented #1167
  • Oct 26 13:45
    adamw commented #1167
  • Oct 26 13:16

    adamw on master

    Fix link to the schema derivati… Fix link to the schema derivati… Regenerate site docs and 1 more (compare)

  • Oct 26 13:16
    adamw closed #1556
  • Oct 26 13:16
    adamw commented #1556
  • Oct 26 13:09
    danicheg opened #1556
  • Oct 26 09:41
    micossow synchronize #1508
  • Oct 26 09:41

    micossow on CVE-2021-41084-test

    Vertx - use their own logging A… (compare)

heksesang
@heksenlied:matrix.org
[m]
The type signature would be more accurate that way – it's a bit confusing that the capability parameter does not reflect the actual required capabilities of the endpoint. Because I am not actually using WebSockets, there should be no problem handing the endpoints to an interpreter that does not support WebSockets, but that is the case now because of how this is done. Unless there is some huge disadvantage from fixing it, I'd say adding that type parameter would be the correct approach.
1 reply
LUC DUZAN
@strokyl
Hi I am using tapir since a while, and it's really but recently I really went to improve the generated openapi documentation.
I just read about the @description annotation that is really useful to add description to generated schema.
But my case class are defined outside my web module and I don't want to leak dependencies of tapir-core to all my other module. I know I could derive the schema automatically and then modify it using the copy technique.
But I was wondering if others would also think it would be great to have a minimal tapir jar with just schema annotation inside it, so we could use them without having to depend on tapir core?
11 replies
Bárður Viberg Dam
@bardurdam
Hi. Is there any way to explicitly set the charset in the Content-Type header in json responses? I have a consumer that if no charset is provided, falls back to another charset than utf-8.
4 replies
Mouafak Mkhallalati
@moafak

How do I create an optional file part?

case class MyPayload(file: Option[Part[java.io.File]])

endpoint.post
    .in(multipartBody[MyPayload])

Results in this error

Cannot find a codec between a List[T] for some basic type T and: Option[sttp.model.Part[java.io.File]]

Note that the following works fine
case class MyPayload(file: Option[java.io.File])
but I lose the metadata (filename)

And if I use
case class MyPayload(file: Part[java.io.File])
It shows up as required in the docs

5 replies
David Leonhardt
@LeonhardtDavid
Hi!
Is there a way to have different input based on content type like it's possible for outputs?
Something like this:
.in(
  oneOf(
    multipartBody[SessionPayloadUnified],
    jsonBody[SessionPayload]
  )
)
3 replies
Carlos Martin
@butcherless

Hi! I have updated Tapir to version 0.19.0-M5 and some dependencies are missing in the maven repo. For instance: https://repo1.maven.org/maven2/com/softwaremill/sttp/tapir/tapir-swagger-ui-akka-http_2.13/0.19.0-M5/tapir-swagger-ui-akka-http_2.13-0.19.0-M5.pom

In the log of the publish job (gh action) I have not found errors neither the log of the artifact to be published. Thanks!

4 replies
Alex Henning Johannessen
@ahjohannessen
@adamw Seems that the unification of swagger ui does not work for index.html in that it falls back to .getOrElse(MediaType.ApplicationOctetStream) and causing the browser to download the index file
31 replies
Gwenael Cholet
@gwenaelcholet
Dear all, I am just new with tapir and trying the first example from github page. Here is the example:
2 replies
val booksListing: Endpoint[(BooksFromYear, Limit, AuthToken), String, List[Book], Any] =
endpoint
.get
.in(("books" / pathString / pathInt).mapTo[BooksFromYear])
.in(queryLimit.description("Maximum number of books to retrieve"))
.in(headerAuthToken)
.errorOut(stringBody)
.out(jsonBody[List[Book]])
I ran error with the jsonBody
Which librairy is supposed to bring it?
tolikbotov
@tolikbotov

Hello. I have server http4s , tapir as api description and zio as server interpreter.

I want to log user id after auth.bearer[String]() passed. But i log incoming request in http4s.

Is there any example, how can i log request with authorization?

4 replies
Daria
@brainsap

Hi, guys! I have a question about openapi yaml generation -
I've changed one of my case class fields in api response from Map[String, MyClass] to a List[MyClass], and now it is not marked as a required property (as Map object was).
For example, this:

case class MyResponse(
      @description("String field") myString: String = "Hello",
      @description("List field") myList: List[String] = Nil
)

Leads to the result -

MyResponse:
    required:
    - myString
    type: object
    properties:
      MyList:
        type: array

It seems like an array type fields are not marked by Tapir as required properties by default, is this true?
If so, is there an easy (or the preferred = ) way to do this?)
Thanks!

8 replies
vonchav
@voonchav_gitlab
Hi @adamw, it doesn't seem like tapir-swagger-ui-zio-http_2.13:0.19.0-M7 is published.
2 replies
heksesang
@heksenlied:matrix.org
[m]
I was just about to say the same – tried to upgrade, but ran into that issue.
1 reply
allawala
@allawala
hey guys, is this "com.softwaremill.sttp.tapir" %% "tapir-json-zio" % "0.19.0-M7" not available for scala 3? It cant seem to download it.
luping.qiu
@lupingqiu
I use play framework, is there a way to get the play Route documentation? or is there an easy way to build the documentation?
1 reply
Anton Solovyev
@Rosteelton
Hi! Is there some implementations for micrometer or some plans? (like, tapir-prometheus-metrics)
1 reply
Gwenael Cholet
@gwenaelcholet

Dear @Adamw, I am trying the following example to expose a route to serve svg file content:

import akka.http.scaladsl.server.Route
import sttp.tapir._
import sttp.tapir.server.akkahttp.AkkaHttpServerInterpreter

import scala.concurrent.Future

val filesRoute: Route = AkkaHttpServerInterpreter().toRoute(
filesServerEndpointFuture("/home/static/data")
)

Despite I have tapir-core i am unable to import filesServerEndpoint. Always unknow.
Also how can I add a route to render the file name. Thanks in advance for you answer.

2 replies
filesServerEndpoint[Future]
is used
with ("site" / "static")("/home/static/data")
Gwenael Cholet
@gwenaelcholet
How can we make a swagger UI route def for filesServerEndpoint?
Christopher London
@chrisjl154

Does anyone know how I can make a query param of Option[List[A]] work? I keep getting Codec errors?

[error] Did you define a codec for: Option[List[String]]? [error] Did you import the codecs for: sttp.tapir.CodecFormat.TextPlain? [error] query[Option[List[String]]]("id_types")

4 replies
tolikbotov
@tolikbotov
Hello. Can i exclude some header("x-id") from openApi documentation?
Maybe there is .ignore method?
2 replies
Gwenael Cholet
@gwenaelcholet
Does someone knows how to use the very useful method getFromFile within tapir route/endpoint system? Thanks in advance
Gwenael Cholet
@gwenaelcholet
For example if I want to download any file - xlsx, xml, xtx - and to answer it as byte array$
2 replies
Gwenael Cholet
@gwenaelcholet
I am also trying the example MultipartFormUploadAkkaServer with object case class UserProfile(name: String, hobby: Option[String], age: Int, photo: Part[File])
2 replies
But I cannot find codec for the Part[File]
could not find implicit value for evidence parameter of type Titi.this.JF[sttp.model.Part[java.io.File]]
implicit val tt: JsonFormat[UserProfile] = jsonFormat4(UserProfile.apply)
Uwe Reimann
@shagoon
Hi. I'm trying to use a base endpoint for authorization. The base endpoint set E to ErrorInfo as described in https://tapir.softwaremill.com/en/latest/endpoint/statuscodes.html. Is it possible to provide additional error mappings in the secured endpoint (like ValidationError), or do I have to provide the error mappings of any specific (secured) endpoint in the base endpoint?
2 replies
Bill Frasure
@swoogles
Hi, I've got a list of ServerEndpoints in my ApplicationLoader, and my colleague is asking for a basic list of all the corresponding URLs.
Any tips for how to get only the hard String values and pathParam values?
The closest I've come so far is serverEndpoint.info.show, but that includes QueryParams, POST payloads, etc
Bill Frasure
@swoogles
Okay I figured it out. Wasn't too hard, but it does rely on internal methods-
import sttp.tapir.EndpointInput.{FixedPath, PathCapture}
import sttp.tapir.internal.RichEndpointInput

serverEndpoint.input.traverseInputs {
        case path: FixedPath[_] => Vector(path.s)
        case pathCapture: PathCapture[_] => Vector (pathCapture.name.map("$" + _) .getOrElse("$unnamedPathVariable") )
      }
1 reply
heksesang
@heksenlied:matrix.org
[m]
@adamw I am trying to derive a Schema[Map[User.Id, User]] where User.Id is defined as a newtype (using zio.prelude) with java.util.UUID as the underlying type and I have mapped the Schema[UUID] instance to define the Schema[User.Id] instance. When I use Schema.schemaForMap[User.Id, User] the name of the component in the OpenAPI documentation becomes Map_<refinement>_User. Is there anything I can do to make the macro use a proper name for the newtype? Where would the macro be getting the name <refinement> from in this case?
2 replies
sebarys
@sebarys

hello,
Is it possible to define endpoint that return Seq[T] and response status code different than default?
I would like in case of processing request success return 201 Created together with Seq[MyCustomType] MyCustomType has circe Encoder/Decoder and Schema

Still I'm not able to define it because of type erasure, in docu I see an exaple with Either, but I'm not able to align it for Seq[T] https://tapir.softwaremill.com/en/latest/endpoint/statuscodes.html

6 replies
Thanks in advance for any suggestions :)
basically in case of success I have one scenario: return 201 Created together with Seq[MyCustomType] - is it simple way to express it?
tolikbotov
@tolikbotov

Hello. Is there any way to describe in docs parameters of SeeOther.
I return this:

.out(oneOf(
        oneOfMapping(
          SeeOther,
          header[String]("Location")
            .description("Redirect address \n params: `status` - success or fail")
        )
      ))

I want to write in docs queryParameter status.

1 reply
Stanislav Bolsun
@stanislav3316
Hello, I have tapir Schema for some type A and want to generate open-api doc for the type A only. Can I do it? (without generation whole documentation, I need only yaml with single A type description as object).
thanks!
4 replies
yurique
@yurique:nowhere.chat
[m]

hi everyone!
I've stumbled upon this: I have this in the endpoint definition:

      .in(jsonBody[List[MyData])

and in the openapi spec it generates it as optional:

"requestBody": {
  "content": {
    "application/json": {
      "schema": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/MyData"
        }
      }
    }
  },
  "required": false
},

is there a reason for this or is it a bug? can I somehow tell tapir that it's not optional?

3 replies
yurique
@yurique:nowhere.chat
[m]

@ex0ns: hi! :)

I think the reason is that the array is required by default as it's top level, but the array might be empty

that's what I want, but "required": false says it's not even required, and openapi generator for typescript generates the body as optional

and if someone sends a POST request with body=undefined, the backend will try to parse the body as a JSON array and will fail because it will be empty (empty body)

heksesang
@heksenlied:matrix.org
[m]
@yurique Iterables are rendered as optional in the documentation because tapir has the opinion that there isn't really any difference between an empty array and an undefined array in JSON. And in most cases that's true, for example with your List[MyData] the codec should generate an empty list if there isn't defined one in the JSON which will fulfill the requirements of the spec.
ex0ns
@ex0ns
I agree with Yurique that in some condition, it does cause issue, as for the empty body instead of body with empty list

In the meantime a solution might be to have a fallback when parsing a List in the backend, where you would return an empty list in case of failure, that is far from perfect, but would not be too hard to implement (custom encoder), or you could wrap the list in an object and use it in the json body

final case class RequestBodyData(data: List[MyData])
....
.in(jsonBody[RequestBodyData])

But the resulting JSON would look like

{
  "data": [ ] 
}
yurique
@yurique:nowhere.chat
[m]
well, circe doesn't think an empty string is parseable as an empty list ;)
scala> import io.circe.parser._
import io.circe.parser._

scala> parse("")
val res0: Either[io.circe.ParsingFailure,io.circe.Json] = Left(io.circe.ParsingFailure: exhausted input)
@ex0ns: I was thinking about wrapping that list into a case class, the best I could think of

but this doesn't seem right:

tapir has the opinion that there isn't really any difference between an empty array and an undefined array

to be sure I sent an empty body to that endpoint (with http4s backend), got a Bad Request with a message from circe:
"Invalid value for: body (DecodingFailure at : C[A])"
Patrick Roemer
@sangamon
I'm trying to get a query parameter with a default value. What I have is this:
implicit val xyzSchema: Schema[XYZ] =
  Schema.string
    .validate(Validator.derivedEnumeration[XYZ].encode(_.tag))
    .default(XYZ.X, Some(XYZ.X.tag))

implicit val xyzCodec: PlainCodec[XYZ] =
  Codec.string
    .mapDecode(s => DecodeResult.fromOption(XYZ(s)))(_.tag)
    .schema(xyzSchema)
5 replies