koxudaxi / datamodel-code-generator

Pydantic model and dataclasses.dataclass generator for easy conversion of JSON, OpenAPI, JSON Schema, and YAML data sources.
https://koxudaxi.github.io/datamodel-code-generator/
MIT License
2.65k stars 296 forks source link

Union modes in Pydantic V2 #1989

Closed pmbrull closed 1 month ago

pmbrull commented 3 months ago

Is your feature request related to a problem? Please describe.

With pydantic V2, union modes behave different by default from pydantic V1. We have issues with the default setup and would like to use union_mode='left_to_right'.

Describe the solution you'd like An argument for the CLI. Something like --union-mode XYZ.

Describe alternatives you've considered I tried playing with the templates. Updating the Union.jinja2. I guess I am doing something wrong there. If it is "as simple" as templating it out, happy to get it sorted that way as well.

Additional context

Using datamodel-code-generator==0.25.6 and Pythong 3.10.12

Thanks!!