-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for discriminated Union
types
#7
Comments
@bruno-f-cruz we should confirm whether pydantic discriminated unions generate OpenAPI 3 compatible schemas. It looks like they should according to this PR: pydantic/pydantic#619 This is important because OpenAPI 3 discriminators are what is supported by NJsonSchema according to their wiki: https://github.com/RicoSuter/NJsonSchema/wiki/Inheritance Assuming this is the case, adding support for discriminators might still require a bit of work, since we ultimately need to support both JSON and YAML serialization. It looks like in both cases this will require generating additional helper code to help marshal types around:
|
After further analysis there now seems to be an easier (in terms of infrastructure) option for YamlDotNet polymorphic deserialization: aaubry/YamlDotNet#774 As for Newtonsoft.Json the best option for leveraging infrastructure would be to leverage JsonSubTypes. This would require consumers to take in an extra dependency, but it seems to be the default choice as reusable infrastructure helper to implement discriminator based deserialization (40M+ downloads and long maintenance history). |
Union
present a particular challenge during deserialization as the type can only be inferred at runtime. Moreover, Json does not include a spec for the type of the object being deserialized and must often be inferred.The suggestion is to leverage
discriminated unions
and attempt to deserialize in runtime the objects. In order to integrate this strategy seamlessly with bonsai, an operator must be added that filters/convert each object in the collection to a specific given type thus allowing for polymorphic deserialization but maintaining the sequence data type.The text was updated successfully, but these errors were encountered: