What's Changed
- pyproject: correct poetry-core package name by @ConnorBaker in #1374
- Support pydantic v2 in runtime by @koxudaxi in #1392
- Add pydantic v2 as output model type by @koxudaxi in #1391
- Add --use-unique-items as set by @koxudaxi in #1400
New Contributors
- @ConnorBaker made their first contribution in #1374
What is the difference between pydantic v1 and v2 output model?
Summary
datamodel-code-generator supports Pydantic v1 and v2 as output model type.
Pydantic v2 is a major release with many breaking changes. See the migration guide for more information:
https://docs.pydantic.dev/2.0/migration/
What's changes in v2 output?
__root__
field (a.k.a Custom Root Types)
__root__
field (a.k.a Custom Root Types) is removed in pydantic v2.
The model is changed to RootModel
pydantic.Field
https://docs.pydantic.dev/2.0/migration/#changes-to-pydanticfield
- const -> removed
- min_items (use min_length instead)
- max_items (use max_length instead)
- unique_items -> removed and the list type will be replaced by
typing.Set
. this feature is discussed in pydantic/pydantic-core#296 - allow_mutation (use frozen instead)
- regex (use pattern instead)
Model Config
pydantic.Config
->pydantic.ConfigDict
- allow_mutation —> frozen (inverse value for getting same behavior).
- allow_population_by_field_name → populate_by_name
Full Changelog: 0.20.0...0.21.0