diff --git a/openapi_pydantic/compat.py b/openapi_pydantic/compat.py index 1eb0b50..840089b 100644 --- a/openapi_pydantic/compat.py +++ b/openapi_pydantic/compat.py @@ -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: diff --git a/tests/util/test_pydantic_field.py b/tests/util/test_pydantic_field.py index c0c7598..2d9e583 100644 --- a/tests/util/test_pydantic_field.py +++ b/tests/util/test_pydantic_field.py @@ -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 @@ -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.