softwaremill / softwaremill/tapir
Support encoding Pickler discriminator with oneOfWrapped
Open
Nobody has claimed this yet.
Pickler
- Dominant language
- Scala
- Stars
- 1.5k
- Forks
- 468
- Avg merge
- 5h 37m
- Merged PRs (30d)
- 34
Description
Similarly to Schema.oneOfWrapped, we want Pickler.oneOfWrapped for sealed hierarchies. This way, we'll get JSON encoding like
{"userStatus": { "Closed": { "description": "account deleted" } } }
instead of current
{"userStatus": { "$type": "Closed", "description" : "account deleted" } } }
for
sealed trait UserStatus
case class Closed(description: String) extends UserStatus
case class User(userStatus: UserStatus)
Challenges:
- Calling
Schema.oneOfWrapped[T]causes underlying macro to summon schemas for all child subtypes ofT. We would prefer passing these child schemas as a parameter, because they are available from child picklers. - In
Writestrait we should probably overridewrite0when creating a new coproduct writer, and detect there that we're dealing with a special type ofSubtypeDiscriminator. Then, the logic ofwrite0should be low-level uPickle code that writes the wrapper object.
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.oneOfWrapped and the Pickler.oneOfWrapped entry point, then inspect the Writes trait's coproduct-writer handling and SubtypeDiscriminator logic. Compare the resulting JSON with the requested wrapped form for the UserStatus example while preserving existing discriminator encoding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100