Skip to content

Commit fe45f77

Browse files
committed
another
1 parent 19ae3f2 commit fe45f77

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

‎src/ga4gh/core/metadata.py‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
from enum import Enum
44
from typing import Any, ClassVar
55

6+
import pydantic
7+
from packaging.version import Version
68
from pydantic.json_schema import GenerateJsonSchema, JsonSchemaMode
79
from typing_extensions import deprecated
810

11+
# Need to support the union_format parameter that was introduced in https://pydantic.dev/docs/validation/latest/get-started/changelog/#v2120-2025-10-07
12+
PYDANTIC_HAS_UNION_FORMAT = Version(pydantic.__version__) >= Version("2.12.0")
13+
914

1015
class Maturity(str, Enum):
1116
"""Maturity levels for GA4GH product features."""
@@ -86,21 +91,29 @@ def model_json_schema(
8691
ref_template: str = "#/$defs/{model}",
8792
schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema,
8893
mode: JsonSchemaMode = "validation",
94+
*,
95+
union_format: str = "smart",
8996
) -> dict[str, Any]:
9097
"""Generate JSON Schema with GKM metadata.
9198
9299
:param by_alias: Whether to use field aliases.
93100
:param ref_template: Template for schema references.
94101
:param schema_generator: Pydantic schema generator class.
95102
:param mode: Pydantic schema generation mode.
103+
:param union_format: How to represent unions in the generated schema.
96104
:returns: JSON Schema annotated with GKM metadata.
97105
"""
98-
schema = super().model_json_schema(
99-
by_alias=by_alias,
100-
ref_template=ref_template,
101-
schema_generator=schema_generator,
102-
mode=mode,
103-
)
106+
schema_kwargs: dict[str, Any] = {
107+
"by_alias": by_alias,
108+
"ref_template": ref_template,
109+
"schema_generator": schema_generator,
110+
"mode": mode,
111+
}
112+
113+
if PYDANTIC_HAS_UNION_FORMAT:
114+
schema_kwargs["union_format"] = union_format
115+
116+
schema = super().model_json_schema(**schema_kwargs) # pyright: ignore[reportAttributeAccessIssue]
104117

105118
return cls.apply_schema_metadata(cls, schema)
106119

0 commit comments

Comments
 (0)