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
4 changes: 3 additions & 1 deletion src/marvin/utilities/jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def create_array_type(
item_types = [schema_to_type(s, schemas) for s in items]
from typing import Union

combined = Union[tuple(item_types)]
combined = Union[tuple(item_types)] if item_types else Any
base = list[combined]
else:
# Handle single item schema
Expand Down Expand Up @@ -296,6 +296,8 @@ def schema_to_type(
types.append(schema_to_type(type_schema, schemas))
has_null = type(None) in types
types = [t for t in types if t is not type(None)]
if not types:
return type(None)
if has_null:
from typing import Union

Expand Down
11 changes: 11 additions & 0 deletions tests/basic/utilities/test_jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,17 @@ def test_mixed_type_array(self):
result = validator.validate_python(["test", 123, True])
assert result == ["test", 123, True]

def test_null_only_type_list_returns_none_type(self):
# {"type": ["null"]} previously raised IndexError after filtering out NoneType
result = jsonschema_to_type({"type": ["null"]})
assert result is type(None)

def test_array_with_empty_items_list_does_not_crash(self):
# {"type": "array", "items": []} previously raised TypeError in Union
result = jsonschema_to_type({"type": "array", "items": []})
validator = TypeAdapter(result)
assert validator.validate_python([]) == []


class TestNameHandling:
"""Test suite for schema name handling."""
Expand Down
Loading