Comments (3)
Thank you for pointing to https://tapir.softwaremill.com/en/latest/endpoint/schemas.html#wrapper-object-discriminators.
Schema.oneOfWrapped
takes an implicit sttp.tapir.generic.Configuration
, but (understandably) ignores its .withDiscriminator
setting. On the other hand, Schema.derivedSchema
does not ignore the .withDiscriminator
setting. This means, that the schema configuration logic is split in 2 places: sttp.tapir.generic.Configuration
and invocation of either Schema.oneOfWrapped
or Schema.derivedSchema
.
It looks like the most 2 common semi-automatic schema types (and Json codecs) for coproducts are
- wrapper object discriminators, or
- field dicriminators.
Arguably, the default tapir schema (no wrapper object discriminators, no field discriminators) does not reflect the default for most common codecs (circe and jsoniter-scala for sure).
Proposition: Schema.oneOfWrapped
behavior could be the default behavior for union types (like in circe), changeable to discriminator fields via .withDiscriminator
setting in the Configuration
. Schema.oneOfWrapped
method could be removed altogether, Schema.derivedSchema
could be used instead, tapping into the single source of truth via implicit Configuration
.
from tapir.
As I understand the problem is that there's a mismatch between the generated schema, and the way an object is serialised to JSON. As tapir doesn't know what's your JSON library of configuration, you have to configure it separately (unless you're using pickler).
So in this case, you'll have to provide the schemas by hand, see: https://tapir.softwaremill.com/en/latest/endpoint/schemas.html#wrapper-object-discriminators
from tapir.
I'm afraid we can't really change the default strategy for schemas generation for coproducts - even though binary compatible, it would be a breaking change in the core
module. Although, I agree that the current situation is not perfect - but I think we'll have to resort to having this properly documented, at least in the 1.x versions.
The situation is different with pickler
, where we are free to define the configuration and serialization. That's still very much in the works (cc @kciesielski), so maybe there we can improve basing on your input.
(btw. the defaults on how coproducts are serialised are different for each json library, so it's hard to pick a good candidate ;) but that also would be fixed by pickler, which derives both json codecs & schemas in one go)
from tapir.
Related Issues (20)
- High latency for netty-loom POST processing HOT 4
- Let serverSecurityLogic access path values HOT 3
- [BUG] Hidden body schema appears in OpenAPI specs
- JSON codec maps None to empty body, keeps content type
- Rename NettyIdServer to NettySyncServer
- Move IntersectionTypeMirror & UnionTypeMirror to the iron integration
- Validation of endpoints against a given OpenAPI schema HOT 4
- [BUG] CORSInterceptor doesn't work with Vert.x server
- [BUG] Tapir Endpoint Incorrectly Merging Set-Cookie Headers in HTTP Response HOT 3
- [BUG] .corsInterceptor throws overloaded method with alternatives error HOT 4
- Schema of `oneOf` variants with same status code and content-type HOT 5
- Web Sockets for netty-server-loom
- [BUG] WebSocket routes always trigger error when using as part of an existing Play Application HOT 1
- tapir server to ignore any validations HOT 11
- [BUG] Websockets with zio-http can fail on too early messages on slow hosts
- [BUG] ClosedChannelException when consuming stream response body with Fs2Streams HOT 1
- Issue with Recognition of API path in Tapir version 10.4.1 HOT 5
- Relaxed enumeratum codecs HOT 2
- [BUG] Can no longer return 304 with empty string as body - get 500 internal server error HOT 4
- [Feature] Semi-auto enum schema derivation configuration
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tapir.