Skip to content

Commit

Permalink
fix: Correct test for pre-2.10 Pydantic.
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-oakley committed Dec 3, 2024
1 parent 40236fd commit d6d6bb9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions openapi_pydantic/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
]

PYDANTIC_MAJOR_VERSION = int(PYDANTIC_VERSION.split(".", 1)[0])
PYDANTIC_MINOR_VERSION = int(PYDANTIC_VERSION.split(".")[1])
PYDANTIC_V2 = PYDANTIC_MAJOR_VERSION >= 2

if TYPE_CHECKING:
Expand Down
12 changes: 11 additions & 1 deletion tests/util/test_pydantic_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
Response,
Schema,
)
from openapi_pydantic.compat import DEFS_KEY, PYDANTIC_V2, models_json_schema, v1_schema
from openapi_pydantic.compat import (
DEFS_KEY,
PYDANTIC_MINOR_VERSION,
PYDANTIC_V2,
models_json_schema,
v1_schema,
)
from openapi_pydantic.util import PydanticSchema, construct_open_api_with_schema_class


Expand Down Expand Up @@ -67,6 +73,10 @@ def test_pydantic_discriminator_schema_generation() -> None:
# In Pydantic v2, string literal types are mapped to consts.
a_kind["const"] = "a"
b_kind["const"] = "b"
if PYDANTIC_MINOR_VERSION < 10:
# Prior to 2.10, string literal types are also mapped to enums with a single entry.
a_kind["enum"] = ["a"]
b_kind["enum"] = ["b"]
else:
json_schema = v1_schema([RequestModel])
# In Pydantic v1, string literal types are mapped to enums with a single entry.
Expand Down

0 comments on commit d6d6bb9

Please sign in to comment.