1

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(
Developus
  • 1,400
  • 2
  • 14
  • 50
  • Why not use `oneOfVariant`? – Gaël J Oct 10 '22 at 11:02
  • Anyway, I think you're issue just relates to missing `import` statements. Can you share the whole code with imports? – Gaël J Oct 10 '22 at 11:03
  • 1
    It might be unrelated but I would change `case class FirstError` to either `case object FirstError` or `case class FirstError()`, parenthesisless case classes are problematic. Same with `SecondError`. – Mateusz Kubuszok Oct 10 '22 at 11:04
  • @GaëlJ - updated post with imports. I don't think I missed any of them – Developus Oct 10 '22 at 11:11
  • @GaëlJ - I also added error wneh I changed to `oneOfVariant` – Developus Oct 10 '22 at 11:22
  • Do you have parameterless `FirstError` and `SecondError` classes in your example as well? The match type variant is only needed when generics are involved - here I don't see any - but maybe the first/second error classes are nested in some other class, that is generic? – adamw Oct 10 '22 at 11:23

0 Answers0