committed by
GitHub
4 changed files with 57 additions and 4 deletions
@ -1,3 +1,13 @@ |
|||
from typing import Literal |
|||
|
|||
from typing_extensions import Annotated |
|||
|
|||
METHODS_WITH_BODY = {"GET", "HEAD", "POST", "PUT", "DELETE", "PATCH"} |
|||
REF_PREFIX = "#/components/schemas/" |
|||
REF_TEMPLATE = "#/components/schemas/{model}" |
|||
|
|||
|
|||
TypeValue = Annotated[ |
|||
Literal["array", "boolean", "integer", "null", "number", "object", "string"], |
|||
"Allowed type values of an object as specified in the JSON Schema https://json-schema.org/draft/2020-12/json-schema-validation#section-6.1.1", |
|||
] |
|||
|
@ -0,0 +1,27 @@ |
|||
from typing import List, Optional, Union |
|||
|
|||
import pytest |
|||
from fastapi.openapi.constants import TypeValue |
|||
from fastapi.openapi.models import Schema |
|||
|
|||
|
|||
@pytest.mark.parametrize( |
|||
"type_value", |
|||
[ |
|||
"array", |
|||
["string", "null"], |
|||
None, |
|||
], |
|||
) |
|||
def test_allowed_schema_type( |
|||
type_value: Optional[Union[TypeValue, List[TypeValue]]], |
|||
) -> None: |
|||
"""Test that Schema accepts TypeValue, List[TypeValue] and None for type field.""" |
|||
schema = Schema(type=type_value) |
|||
assert schema.type == type_value |
|||
|
|||
|
|||
def test_invalid_type_value() -> None: |
|||
"""Test that Schema raises ValueError for invalid type values.""" |
|||
with pytest.raises(ValueError, match="2 validation errors for Schema"): |
|||
Schema(type=True) # type: ignore[arg-type] |
Loading…
Reference in new issue