I have the following endpoint:
val myEndpoint: PublicEndpoint[Unit, ErrorResponse, Entity, Any] = endpoint.get
.in("test")
.out(jsonBody[Entity])
.errorOut(jsonBody[ErrorResponse])
Where Entity and ErrorResponse are:
sealed trait ErrorResponse
object ErrorResponse {
final case class NotFound(id: String) extends ErrorResponse
final case class UnknownError(error: String) extends ErrorResponse
implicit val notFoundSchema: Schema[NotFound] = Schema.derived
implicit val unknownErrorSchema: Schema[UnknownError] = Schema.derived
implicit val errorResponseSchema: Schema[ErrorResponse] = Schema.derived
}
Then I convert the endpoints to akka routes:
val myEndpointRoute: Route = AkkaHttpServerInterpreter().toRoute(myEndpoint.serverLogic { _ =>
val result: Either[ErrorResponse, Entity] = Right(Entity("some data of the entity"))
Future.successful(result)
})
val swaggerEndpoint = SwaggerInterpreter().fromEndpoints[Future](List(myEndpoint), "Tapir Demo", "1.0")
val swaggerRoutes: Route = AkkaHttpServerInterpreter().toRoute(swaggerEndpoint)
And run the server:
Http()
.newServerAt("localhost", 8080)
.bind(myEndpointRoute ~ swaggerRoutes)
.onComplete {
case Success(_) =>
println(s"Started on port 8080")
case Failure(e) =>
println("Failed to start ... ", e)
}
The issue I have is when browsing the schema for ErrorResponse I see an hierarchy of objects (#0 and #1) instead of subtypes like NotFound, UnknownError.
How should I define the schema for ErrorResponse?
PS: dependencies:
"com.softwaremill.sttp.tapir" %% "tapir-core" % "1.9.6",
"com.softwaremill.sttp.tapir" %% "tapir-json-circe" % "1.9.6"
"com.softwaremill.sttp.tapir" %% "tapir-swagger-ui-bundle" % "1.9.6",
"com.softwaremill.sttp.tapir" %% "tapir-akka-http-server" % "1.9.6"

That is how swagger UI renders oneOf in OpenAPI Spec 3.1.0, which is the one that tapir uses as the default version. If you change it to OpenAPI Spec 3.0.3 or any 3.x.x you will get the result you expect. Here you have a POC that reproduce your case (I used pekko-http instead of akka-http, but it's the same)
Once you start the server with
sbt runyou can check the endpoints for OpenAPI Spec3.1.0and3.0.3A similar issue was reported in Swagger. The suggestion was add the property title with the same name of the object.
For tapir 1.9.6 which is the version you are using and the latest one released up to now, you can get the same result changing the schemas defined to something like
doing that, will produce the result you are looking for (the hash with the number stills there but now it also adds the description you want)