anyOf encoder does not include discriminator's parameterName
leading to incorrect encoding
#568
Labels
kind/bug
Feature doesn't work as expected.
status/triage
Collecting information required to triage the issue.
Description
When defining a Schema as the anyOf of a number of other schemas and use a discriminator, the discriminator key is not encoded, leading to a failure if you attempt to later decode it. The alternative is to store the discriminator property on each of the individual objects in anyOf, which is redundant and forces these objects to know about the discriminator.
Reproduction
Take for example this case:
Produces the following Swift entity:
encode()
does not encode thepetType
property, which means that thePet
entity will not be encoded correctly, and will rely in the individual anyOf cases to specify a redundantpetType
property instead, which would in turn mean thatDog
,Cat
,Lizard
need to "know" aboutPet
.We could store the discriminator Name directly on the
encode
function to makePet
self-contained:Package version(s)
.
├── swift-algorithmshttps://github.com/apple/[email protected]
│ └── swift-numericshttps://github.com/apple/[email protected]
├── openapikithttps://github.com/mattpolzin/[email protected]
│ └── yamshttps://github.com/jpsim/[email protected]
├── yamshttps://github.com/jpsim/[email protected]
├── swift-argument-parserhttps://github.com/apple/[email protected]
├── swift-openapi-runtimehttps://github.com/apple/[email protected]
│ └── swift-http-typeshttps://github.com/apple/[email protected]
├── swift-http-typeshttps://github.com/apple/[email protected]
└── swift-docc-pluginhttps://github.com/apple/[email protected]
└── swift-docc-symbolkithttps://github.com/apple/[email protected]
Expected behavior
Ideally we should be able to encode & decode these objects correctly.
Environment
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
Additional information
No response
The text was updated successfully, but these errors were encountered: