Skip to content

Commit

Permalink
fix: Correct expected literal schema for Pydantic 2.7.
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-oakley committed Jun 15, 2024
1 parent 896435b commit dd01614
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions tests/util/test_pydantic_field.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Union
from typing import Union

from pydantic import BaseModel, Field
from typing_extensions import Literal
Expand Down Expand Up @@ -59,17 +59,16 @@ def construct_base_open_api() -> OpenAPI:
def test_pydantic_discriminator_schema_generation() -> None:
"""https://github.com/kuimono/openapi-schema-pydantic/issues/8"""

a_kind: Dict[str, Any]
b_kind: Dict[str, Any]
a_kind = {"const": "a", "enum": ["a"], "title": "Kind", "type": "string"}
b_kind = {"const": "b", "enum": ["b"], "title": "Kind", "type": "string"}

if PYDANTIC_V2:
_key_map, json_schema = models_json_schema([(RequestModel, "validation")])
a_kind = {"const": "a", "title": "Kind"}
b_kind = {"const": "b", "title": "Kind"}
else:
json_schema = v1_schema([RequestModel])
a_kind = {"enum": ["a"], "title": "Kind", "type": "string"}
b_kind = {"enum": ["b"], "title": "Kind", "type": "string"}
a_kind.pop("const")
b_kind.pop("const")

assert json_schema == {
DEFS_KEY: {
"DataAModel": {
Expand Down

0 comments on commit dd01614

Please sign in to comment.