datamodel-code-generator
datamodel-code-generator copied to clipboard
[feature] Support constrained lists and uniqueItems constraint
Is your feature request related to a problem? Please describe.
I need to generate a model for constrained lists in order to validate and enforce the list elements to be unique using the unique_items argument. I am using the OpenAPIParser as a python module to generate models from a spec.
I noticed that the imported pydantic types does not include conlist in the DataTypeManager class: https://github.com/koxudaxi/datamodel-code-generator/blob/381abc1946c088c99dc79bebc62b7e37a2d4b8d3/datamodel_code_generator/model/pydantic/types.py#L15-L19
And unique_items is not included in the constraints base class in the base model: https://github.com/koxudaxi/datamodel-code-generator/blob/381abc1946c088c99dc79bebc62b7e37a2d4b8d3/datamodel_code_generator/model/pydantic/base_model.py#L17-L27
Constrained lists is a supported field (conlist) in pydantic and the unique_items argument is supported in pydantic 1.9.0+.
Describe the solution you'd like
Add support for constrained lists (conlist) and the constraint, uniqueItems in the above base classes
Describe alternatives you've considered
Additional context Add any other context or screenshots about the feature request here.
I have released the feature. Thank you very much!!