softwaremill / softwaremill/tapir

[BUG] Mismatch between open-api and JSON

Open
#2,461 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
1.5k
Forks
468
Avg merge
5h 37m
Merged PRs (30d)
34

Description

Tapir version: ***
1.0.6 and above

Scala version: ***
2.13
Describe the bug

https://github.com/softwaremill/tapir/pull/2403 is creating mismatch between openapi and json (using upickle)
I kinda disagree with the behavior expected here https://github.com/softwaremill/tapir/issues/2358 I don't know which json lib was used, but a least with upickle, if you define a @upickle.implicits.key(Person) and convert to json as a Person or as an Entity, in both case you'll have the discriminator.
This might not be an issue in case of a GET, but if in the example above we need to POST a Person, if we don't give the discriminator : "Person", the json deserialization will fail.
How to reproduce?

At alephium we are happily using tapir, I created this commit where I updated to 1.0.6, we can see the new type Name1 being created.
I concentrate my example on the AssetOutput
as I'm using it directly and not as an Output it creates the AssetOutput1 schema.
I don't have yet an endpoint where I POST an AssetOutput, but I can already tell that upickle won't be able to read it if there are no discriminator, shown in this commit
you can run

app/testOnly org.alephium.explorer.api.model.ApiModelSpec -- -z "AssetOutput"

IMO this is an issue, we have a front-end team that is generating there TypeScript types from the open-api file and in that above case, they will need to used AssetOutput1 to POST and it will fail.

Additional information

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 reviewing PR #2403 and issue #2358, then inspect the linked AssetOutput and Transaction examples in the reproduction commits. Run app/testOnly org.alephium.explorer.api.model.ApiModelSpec -- -z "AssetOutput" to compare the generated OpenAPI schema with upickle JSON behavior. Done means the schema and serialization/deserialization expectations agree for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, scala
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.