softwaremill / softwaremill/tapir

Support encoding Pickler discriminator with oneOfWrapped

Open
#3,170 0 comments 0 reactions 0 assignees View on GitHub

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:

  1. Calling Schema.oneOfWrapped[T] causes underlying macro to summon schemas for all child subtypes of T. We would prefer passing these child schemas as a parameter, because they are available from child picklers.
  2. In Writes trait we should probably override write0 when creating a new coproduct writer, and detect there that we're dealing with a special type of SubtypeDiscriminator. Then, the logic of write0 should be low-level uPickle code that writes the wrapper object.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.