Open theop-luma opened 3 weeks ago
Let me know if this is something expected by the spec. If not I have a fix I could submit.
You'll need to explicitly add the petType property to all 3 schemas. Either just the property, or use an allOf of a "PetCommon" schema that only has the type and the additional pet properties.
But OpenAPI doesn't automatically add the property like this. To the generator is behaving correctly according to the OpenAPI document.
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/swift-algorithms@1.2.0 │ └── swift-numericshttps://github.com/apple/swift-numerics.git@1.0.2 ├── openapikithttps://github.com/mattpolzin/OpenAPIKit@3.1.3 │ └── yamshttps://github.com/jpsim/Yams@5.1.2 ├── yamshttps://github.com/jpsim/Yams@5.1.2 ├── swift-argument-parserhttps://github.com/apple/swift-argument-parser@1.3.1 ├── swift-openapi-runtimehttps://github.com/apple/swift-openapi-runtime@1.4.0 │ └── swift-http-typeshttps://github.com/apple/swift-http-types@1.0.3 ├── swift-http-typeshttps://github.com/apple/swift-http-types@1.0.3 └── swift-docc-pluginhttps://github.com/apple/swift-docc-plugin@1.3.0 └── swift-docc-symbolkithttps://github.com/apple/swift-docc-symbolkit@1.0.0
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