Skip to content

Commit d6d6bb9

Browse files
committed
fix: Correct test for pre-2.10 Pydantic.
1 parent 40236fd commit d6d6bb9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

openapi_pydantic/compat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
]
1818

1919
PYDANTIC_MAJOR_VERSION = int(PYDANTIC_VERSION.split(".", 1)[0])
20+
PYDANTIC_MINOR_VERSION = int(PYDANTIC_VERSION.split(".")[1])
2021
PYDANTIC_V2 = PYDANTIC_MAJOR_VERSION >= 2
2122

2223
if TYPE_CHECKING:

tests/util/test_pydantic_field.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
Response,
1616
Schema,
1717
)
18-
from openapi_pydantic.compat import DEFS_KEY, PYDANTIC_V2, models_json_schema, v1_schema
18+
from openapi_pydantic.compat import (
19+
DEFS_KEY,
20+
PYDANTIC_MINOR_VERSION,
21+
PYDANTIC_V2,
22+
models_json_schema,
23+
v1_schema,
24+
)
1925
from openapi_pydantic.util import PydanticSchema, construct_open_api_with_schema_class
2026

2127

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

0 commit comments

Comments
 (0)