softwaremill / softwaremill/tapir
Schema for `Nothing`
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 1.5k
- Forks
- 468
- Avg merge
- 5h 37m
- Merged PRs (30d)
- 34
Description
I have the following generic model of responses from a server API:
sealed trait Status[+E, +A]
final case class Error[E](error: E) extends Status[E, Nothing]
final case class Fatal(reason: String) extends Status[Nothing, Nothing]
final case class Success[A](a: A) extends Status[Nothing, A]
final case class Timeout() extends Status[Nothing, Nothing]
implicit def statusSchema[A, E](implicit es: Schema[E], as: Schema[A]): Schema[Status[E, A]] =
Schema.derived
It works fine if an API method returns something like Status[String, Unit]. But what if some method demoMethod is known not to respond with Error case? It could be encoded as Status[Nothing, Unit]:
val demoMethod: PublicEndpoint[Args, Unit, Status[Nothing, Unit], Any] =
basepoint
.post
.in("demo-method")
.in(jsonBody[Args])
.out(jsonBody[Status[Nothing, Unit]])
For this to work we need a shema for Nothing, in other words the absence of a value.
Currently I use Schema.any as a workaround:
implicit val nothingSchema: Schema[Nothing] =
Schema.any
But of course any has not the same meaning as we want.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing Schema.derived for the Status[E, A] model and the jsonBody[Status[Nothing, Unit]] usage shown in the report. Compare the current Schema.any workaround with the intended representation of Nothing, and verify that an endpoint returning Status[Nothing, Unit] can derive and use its schema correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100