Skip to content

Commit

Permalink
Fix min_items in choice list (#17)
Browse files Browse the repository at this point in the history
* Fix min_items in choice list

* Fix unit test

* Fix mypy

* Fix mypy

* Bump version

---------

Co-authored-by: Maurits Rijk <[email protected]>
  • Loading branch information
mrijk and Maurits Rijk authored Dec 19, 2023
1 parent fa9630d commit 813da48
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.0rc1
current_version = 1.0.0rc2
commit = False
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)((\-rc)(?P<build>\d+))?
Expand Down
2 changes: 1 addition & 1 deletion pydantic_forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

"""This is the pydantic-forms engine."""

__version__ = "1.0.0rc1"
__version__ = "1.0.0rc2"
12 changes: 10 additions & 2 deletions pydantic_forms/validators/components/choice_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# limitations under the License.
from typing import Annotated, Optional, TypeVar

from annotated_types import Len
from annotated_types import MaxLen, MinLen

from pydantic_forms.validators.components.choice import Choice

Expand All @@ -31,7 +31,15 @@ def choice_list(

return unique_conlist(item_type, min_items=min_items, max_items=max_items)

# Note: min_items always need to be there to remain backward compatible with frontend components
if max_items:
return Annotated[ # type: ignore[return-value]
list[item_type], # type:ignore[valid-type]
MinLen(min_items or 0),
MaxLen(max_items),
]

return Annotated[ # type: ignore[return-value]
list[item_type], # type:ignore[valid-type]
Len(min_items or 0, max_items),
MinLen(min_items or 0),
]
2 changes: 2 additions & 0 deletions tests/unit_tests/test_choice_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ class Form(FormPage):
"properties": {
"choices": {
"items": {"$ref": "#/$defs/LegChoice"},
"minItems": 0,
"type": "array",
"title": "Choices",
},
"choices_with_labels": {
"items": {"$ref": "#/$defs/LegChoiceLabel"},
"minItems": 0,
"type": "array",
"title": "Choices With Labels",
},
Expand Down

0 comments on commit 813da48

Please sign in to comment.