|
9 | 9 | from typing import TYPE_CHECKING, Any, Callable, Iterable, Literal, overload |
10 | 10 |
|
11 | 11 | from infrahub_sdk.utils import compare_lists, intersection |
12 | | -from pydantic import field_validator |
| 12 | +from pydantic import ConfigDict, field_validator |
13 | 13 |
|
14 | 14 | from infrahub.core.constants import HashableModelState, RelationshipCardinality, RelationshipKind |
15 | 15 | from infrahub.core.models import HashableModel, HashableModelDiff |
|
19 | 19 | from .relationship_schema import RelationshipSchema |
20 | 20 |
|
21 | 21 | if TYPE_CHECKING: |
| 22 | + from pydantic.config import JsonDict |
22 | 23 | from typing_extensions import Self |
23 | 24 |
|
24 | 25 | from infrahub.core.schema import GenericSchema, NodeSchema |
|
40 | 41 | ] |
41 | 42 |
|
42 | 43 |
|
| 44 | +def _json_schema_extra(schema: JsonDict) -> None: |
| 45 | + """ |
| 46 | + Mutate the generated JSON Schema in place to: |
| 47 | + - allow `null` for `display_labels` |
| 48 | + - mark the non-null branch as deprecated |
| 49 | + """ |
| 50 | + props = schema.get("properties") |
| 51 | + if not isinstance(props, dict): |
| 52 | + return |
| 53 | + dl = props.get("display_labels") |
| 54 | + if not isinstance(dl, dict): |
| 55 | + return |
| 56 | + |
| 57 | + if "anyOf" in dl: |
| 58 | + dl["anyOf"] = [ |
| 59 | + { |
| 60 | + "type": "array", |
| 61 | + "items": { |
| 62 | + "type": "string", |
| 63 | + "deprecationMessage": "display_labels are deprecated use display_label instead", |
| 64 | + }, |
| 65 | + }, |
| 66 | + {"type": "null"}, |
| 67 | + ] |
| 68 | + |
| 69 | + |
43 | 70 | class BaseNodeSchema(GeneratedBaseNodeSchema): |
44 | 71 | _exclude_from_hash: list[str] = ["attributes", "relationships"] |
45 | 72 | _sort_by: list[str] = ["namespace", "name"] |
46 | 73 |
|
| 74 | + model_config = ConfigDict(extra="forbid", json_schema_extra=_json_schema_extra) |
| 75 | + |
47 | 76 | @property |
48 | 77 | def is_schema_node(self) -> bool: |
49 | 78 | """Tell if this node represent a part of the schema. Not to confuse this with `is_node_schema`.""" |
|
0 commit comments