Coverage for tests/test_openapi_schema_type.py: 100%
10 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-09-22 00:03 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-09-22 00:03 +0000
1from typing import List, Optional, Union 1abcdef
3import pytest 1abcdef
4from fastapi.openapi.models import Schema, SchemaType 1abcdef
7@pytest.mark.parametrize( 1abcdef
8 "type_value",
9 [
10 "array",
11 ["string", "null"],
12 None,
13 ],
14)
15def test_allowed_schema_type( 1abcdef
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) 1ghijkl
20 assert schema.type == type_value 1ghijkl
23def test_invalid_type_value() -> None: 1abcdef
24 """Test that Schema raises ValueError for invalid type values."""
25 with pytest.raises(ValueError, match="2 validation errors for Schema"): 1mnopqr
26 Schema(type=True) # type: ignore[arg-type] 1mnopqr