Coverage for tests / test_openapi_schema_type.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1from typing import Optional, Union 1abcd

2 

3import pytest 1abcd

4from fastapi.openapi.models import Schema, SchemaType 1abcd

5 

6 

7@pytest.mark.parametrize( 1abcd

8 "type_value", 

9 [ 

10 "array", 

11 ["string", "null"], 

12 None, 

13 ], 

14) 

15def test_allowed_schema_type( 1abcd

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) 1efg

20 assert schema.type == type_value 1efg

21 

22 

23def test_invalid_type_value() -> None: 1abcd

24 """Test that Schema raises ValueError for invalid type values.""" 

25 with pytest.raises(ValueError, match="2 validation errors for Schema"): 1hij

26 Schema(type=True) # type: ignore[arg-type] 1hij