datamodel-code-generator
datamodel-code-generator copied to clipboard
Support for Pydantic discriminator
Describe the solution you'd like The ability to use pydantic discriminator when defining the field schema.
https://pydantic-docs.helpmanual.io/usage/types/#discriminated-unions-aka-tagged-unions
Describe alternatives you've considered The alternative is always to ensure that all subtypes have a unique and required field so that pydantic generates the correct type instead of using a common field and using the value as the discriminator.
Additional context
https://pydantic-docs.helpmanual.io/usage/types/#discriminated-unions-aka-tagged-unions
I hacked the code a little bit and managed to make it work the way I want by adding discriminator to this list: https://github.com/koxudaxi/datamodel-code-generator/blob/master/datamodel_code_generator/parser/jsonschema.py#L274 is that an acceptable implementation?