Coverage for tests/test_openapi_schema_type.py: 100%
10 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
1from typing import List, Optional, Union 1abcdefg
3import pytest 1abcdefg
4from fastapi.openapi.models import Schema, SchemaType 1abcdefg
7@pytest.mark.parametrize( 1abcdefg
8 "type_value",
9 [
10 "array",
11 ["string", "null"],
12 None,
13 ],
14)
15def test_allowed_schema_type( 1abcdefg
16 type_value: Optional[Union[SchemaType, List[SchemaType]]],
17) -> None:
18 """Test that Schema accepts SchemaType, List[SchemaType] and None for type field."""
19 schema = Schema(type=type_value) 1hijklmn
20 assert schema.type == type_value 1hijklmn
23def test_invalid_type_value() -> None: 1abcdefg
24 """Test that Schema raises ValueError for invalid type values."""
25 with pytest.raises(ValueError, match="2 validation errors for Schema"): 1opqrstu
26 Schema(type=True) # type: ignore[arg-type] 1opqrstu