1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
import pytest
from pydantic import ValidationError
from openapi_pydantic.v3.v3_1 import Schema
@pytest.mark.parametrize(
"datatype",
(
"string",
"number",
"integer",
"boolean",
"array",
"object",
"null",
),
)
def test_good_types_parse_and_equate(datatype: str) -> None:
assert Schema(type=datatype).type == datatype
def test_bad_types_raise_validation_errors() -> None:
with pytest.raises(ValidationError):
Schema(type="invalid")
with pytest.raises(ValidationError):
Schema(anyOf=[{"type": "invalid"}])
with pytest.raises(ValidationError):
Schema(
properties={
"a": Schema(type="invalid"),
},
)
|