Skip to content

Commit e8d2887

Browse files
authored
Merge pull request #7395 from opsmill/pog-mark-display_labels-as-deprecated
Mark display_labels as deprecated in the YAML language server
2 parents 7c55624 + e42efb5 commit e8d2887

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

backend/infrahub/core/schema/basenode_schema.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import TYPE_CHECKING, Any, Callable, Iterable, Literal, overload
1010

1111
from infrahub_sdk.utils import compare_lists, intersection
12-
from pydantic import field_validator
12+
from pydantic import ConfigDict, field_validator
1313

1414
from infrahub.core.constants import HashableModelState, RelationshipCardinality, RelationshipKind
1515
from infrahub.core.models import HashableModel, HashableModelDiff
@@ -19,6 +19,7 @@
1919
from .relationship_schema import RelationshipSchema
2020

2121
if TYPE_CHECKING:
22+
from pydantic.config import JsonDict
2223
from typing_extensions import Self
2324

2425
from infrahub.core.schema import GenericSchema, NodeSchema
@@ -40,10 +41,38 @@
4041
]
4142

4243

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+
4370
class BaseNodeSchema(GeneratedBaseNodeSchema):
4471
_exclude_from_hash: list[str] = ["attributes", "relationships"]
4572
_sort_by: list[str] = ["namespace", "name"]
4673

74+
model_config = ConfigDict(extra="forbid", json_schema_extra=_json_schema_extra)
75+
4776
@property
4877
def is_schema_node(self) -> bool:
4978
"""Tell if this node represent a part of the schema. Not to confuse this with `is_node_schema`."""

0 commit comments

Comments
 (0)