You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As suggested on gitter, it would be nice if there was a way to describe status code mappings. Currently, this is only available when interpreting as a server by providing implicit StatusMapper values for error and normal outputs; the openapi documentation always generates two responses: default (for errors) and 200 (for normal outputs). This can only be customised by hand after generating the openapi model.
It would be better if there was a way to capture status code mappings as part of the endpoint description.
import tapir._
import tapir.json.circe._
import io.circe.generic.auto._
trait ErrorInfo {
def z: Boolean
}
case class E1(x: String, z: Boolean) extends ErrorInfo
case class E2(y: Int, z: Boolean) extends ErrorInfo
implicit val c: CodecForOptional[ErrorInfo, MediaType.Json, _] = null
val ee = endpoint.out(
statusFrom(
jsonBody[ErrorInfo],
StatusCodes.InternalServerError,
whenClass[E1] -> StatusCodes.NotFound,
whenClass[E2] -> StatusCodes.BadRequest,
whenValue[ErrorInfo](_.z) -> StatusCodes.AlreadyReported
))
The server would then be able to generate a proper response code basing on the output value. The openapi docs could contain different output body schemas for different status codes. The client interpreter here wouldn't do anything with this kind of metadata, as the only thing it could do is validate that the status code matches the value received.
Outstanding problems:
for automatic codec derivation this relies on Support for sealed trait families #10: node the null codec in the example above to make the code compile. If there are multiple status codes, this usually means multiple subclasses of a class representing errors.
should statusFrom wrap any kind of input, or only bodies? I think it needs to be constrained to wrapping bodies only, so that we could require the schema of the subclasses, and use these schemas in documentation. This would mean we wouldn't support differentiating status codes on headers (which is the other output option)
The text was updated successfully, but these errors were encountered:
As suggested on gitter, it would be nice if there was a way to describe status code mappings. Currently, this is only available when interpreting as a server by providing implicit
StatusMapper
values for error and normal outputs; the openapi documentation always generates two responses:default
(for errors) and200
(for normal outputs). This can only be customised by hand after generating the openapi model.It would be better if there was a way to capture status code mappings as part of the endpoint description.
Possible API, in
Tapir.scala
:usage:
The server would then be able to generate a proper response code basing on the output value. The openapi docs could contain different output body schemas for different status codes. The client interpreter here wouldn't do anything with this kind of metadata, as the only thing it could do is validate that the status code matches the value received.
Outstanding problems:
null
codec in the example above to make the code compile. If there are multiple status codes, this usually means multiple subclasses of a class representing errors.statusFrom
wrap any kind of input, or only bodies? I think it needs to be constrained to wrapping bodies only, so that we could require the schema of the subclasses, and use these schemas in documentation. This would mean we wouldn't support differentiating status codes on headers (which is the other output option)The text was updated successfully, but these errors were encountered: