Skip to content

Commit 0cbba08

Browse files
committed
Add required change for object templates
1 parent f470cc2 commit 0cbba08

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

infrahub_sdk/schema/__init__.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
RelationshipSchemaAPI,
3535
SchemaRoot,
3636
SchemaRootAPI,
37+
TemplateSchemaAPI,
3738
)
3839

3940
if TYPE_CHECKING:
@@ -58,6 +59,7 @@
5859
"RelationshipSchemaAPI",
5960
"SchemaRoot",
6061
"SchemaRootAPI",
62+
"TemplateSchemaAPI",
6163
]
6264

6365

@@ -78,8 +80,10 @@ class EnumMutation(str, Enum):
7880

7981

8082
MainSchemaTypes: TypeAlias = Union[NodeSchema, GenericSchema]
81-
MainSchemaTypesAPI: TypeAlias = Union[NodeSchemaAPI, GenericSchemaAPI, ProfileSchemaAPI]
82-
MainSchemaTypesAll: TypeAlias = Union[NodeSchema, GenericSchema, NodeSchemaAPI, GenericSchemaAPI, ProfileSchemaAPI]
83+
MainSchemaTypesAPI: TypeAlias = Union[NodeSchemaAPI, GenericSchemaAPI, ProfileSchemaAPI, TemplateSchemaAPI]
84+
MainSchemaTypesAll: TypeAlias = Union[
85+
NodeSchema, GenericSchema, NodeSchemaAPI, GenericSchemaAPI, ProfileSchemaAPI, TemplateSchemaAPI
86+
]
8387

8488

8589
class InfrahubSchemaBase:
@@ -417,6 +421,10 @@ async def fetch(
417421
profile = ProfileSchemaAPI(**profile_schema)
418422
nodes[profile.kind] = profile
419423

424+
for template_schema in data.get("templates", []):
425+
template = TemplateSchemaAPI(**template_schema)
426+
nodes[template.kind] = template
427+
420428
return nodes
421429

422430

@@ -621,6 +629,10 @@ def fetch(
621629
profile = ProfileSchemaAPI(**profile_schema)
622630
nodes[profile.kind] = profile
623631

632+
for template_schema in data.get("templates", []):
633+
template = TemplateSchemaAPI(**template_schema)
634+
nodes[template.kind] = template
635+
624636
return nodes
625637

626638
def load(

infrahub_sdk/schema/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class RelationshipKind(str, Enum):
3131
GROUP = "Group"
3232
HIERARCHY = "Hierarchy"
3333
PROFILE = "Profile"
34+
TEMPLATE = "Template"
3435

3536

3637
class RelationshipDirection(str, Enum):
@@ -290,6 +291,7 @@ class BaseNodeSchema(BaseSchema):
290291
branch: BranchSupportType | None = None
291292
default_filter: str | None = None
292293
generate_profile: bool | None = None
294+
generate_template: bool | None = None
293295
parent: str | None = None
294296
children: str | None = None
295297

@@ -308,6 +310,10 @@ class ProfileSchemaAPI(BaseSchema, BaseSchemaAttrRelAPI):
308310
inherit_from: list[str] = Field(default_factory=list)
309311

310312

313+
class TemplateSchemaAPI(BaseSchema, BaseSchemaAttrRelAPI):
314+
inherit_from: list[str] = Field(default_factory=list)
315+
316+
311317
class NodeExtensionSchema(BaseModel):
312318
model_config = ConfigDict(use_enum_values=True)
313319

@@ -341,3 +347,4 @@ class SchemaRootAPI(BaseModel):
341347
generics: list[GenericSchemaAPI] = Field(default_factory=list)
342348
nodes: list[NodeSchemaAPI] = Field(default_factory=list)
343349
profiles: list[ProfileSchemaAPI] = Field(default_factory=list)
350+
templates: list[TemplateSchemaAPI] = Field(default_factory=list)

0 commit comments

Comments
 (0)