| 1 |
import pytest |
| 2 |
from fastapi.openapi.models import Schema, SchemaType |
| 3 |
|
| 4 |
|
| 5 |
@pytest.mark.parametrize( |
| 6 |
"type_value", |
| 7 |
[ |
| 8 |
"array", |
| 9 |
["string", "null"], |
| 10 |
None, |
| 11 |
], |
| 12 |
) |
| 13 |
def test_allowed_schema_type( |
| 14 |
type_value: SchemaType | list[SchemaType] | None, |
| 15 |
) -> None: |
| 16 |
"""Test that Schema accepts SchemaType, List[SchemaType] and None for type field.""" |
| 17 |
schema = Schema(type=type_value) |
| 18 |
assert schema.type == type_value |
| 19 |
|
| 20 |
|
| 21 |
def test_invalid_type_value() -> None: |
| 22 |
"""Test that Schema raises ValueError for invalid type values.""" |
| 23 |
with pytest.raises(ValueError, match="2 validation errors for Schema"): |
| 24 |
Schema(type=True) # type: ignore[arg-type] # ty: ignore[invalid-argument-type] |