Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/anthropic/lib/_parse/_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def transform_schema(
strict_schema["items"] = transform_schema(items)

min_items = json_schema.pop("minItems", None)
if min_items is not None and min_items == 0 or min_items == 1:
if min_items is not None and (min_items == 0 or min_items == 1):
strict_schema["minItems"] = min_items
elif min_items is not None:
# add it back so its treated as an extra property and appended to the description
Expand Down
32 changes: 32 additions & 0 deletions tests/lib/_parse/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,38 @@ def test_array_schema():
)


def test_array_schema_min_items_zero():
schema = {
"type": "array",
"items": {"type": "string"},
"minItems": 0,
}
result = transform_schema(schema)
assert result == snapshot(
{
"type": "array",
"items": {"type": "string"},
"minItems": 0,
}
)


def test_array_schema_min_items_one():
schema = {
"type": "array",
"items": {"type": "string"},
"minItems": 1,
}
result = transform_schema(schema)
assert result == snapshot(
{
"type": "array",
"items": {"type": "string"},
"minItems": 1,
}
)


def test_string_schema_with_format_and_default():
schema = {
"type": "string",
Expand Down