Scala, Tapir - implicit problem with oneOfVariantFromMatchType from tapir

251 Views Asked by At

I have created few own errors:

sealed trait Error
case class FirstError extends Error
case class SecondError extends Error

I added it to tapir:

  val firstError = oneOfVariantFromMatchType(StatusCode.BadRequest, jsonBody[FirstError].example(FirstError("first error"))

  val secondError = oneOfVariantFromMatchType(StatusCode.Unauthorized, jsonBody[SecondError].example(SecondError("second error"))

And I use it like this:

def errors: EndpointOutput.OneOf[Error, Error] = oneOf(firstError, secondError)

Added to endpoint:

endpoint.get.in(...).errorOut(errors)

But when I tried to run code, I got an error:

could not find implicit value for evidence parameter of type sttp.tapir.typelevel.MatchType[FirstError]

could not find implicit value for evidence parameter of type sttp.tapir.typelevel.MatchType[SecondError]

I don't know how to fix it. I used docs from here - https://tapir.softwaremill.com/en/latest/endpoint/oneof.html and my code is pretty the same as in the docs. How shoould I fix this?

EDIT: Imports:

import sttp.model.StatusCode
import sttp.tapir._
import sttp.tapir.generic.auto.SchemaDerivation
import sttp.tapir.json.circe.TapirJsonCirce
import io.circe.generic.auto._

When I used oneOfVariant I got an error for both error types:

Type FirstError is not the same as its erasure. Using a runtime-class-based check it won't be possible to verify that the input matches the desired type. Use other methods to match the input to the appropriate variant instead.
    oneOfVariant(
0

There are 0 best solutions below