Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions infrahub_sdk/schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
RelationshipSchemaAPI,
SchemaRoot,
SchemaRootAPI,
TemplateSchemaAPI,
)

if TYPE_CHECKING:
Expand All @@ -58,6 +59,7 @@
"RelationshipSchemaAPI",
"SchemaRoot",
"SchemaRootAPI",
"TemplateSchemaAPI",
]


Expand All @@ -78,8 +80,10 @@


MainSchemaTypes: TypeAlias = Union[NodeSchema, GenericSchema]
MainSchemaTypesAPI: TypeAlias = Union[NodeSchemaAPI, GenericSchemaAPI, ProfileSchemaAPI]
MainSchemaTypesAll: TypeAlias = Union[NodeSchema, GenericSchema, NodeSchemaAPI, GenericSchemaAPI, ProfileSchemaAPI]
MainSchemaTypesAPI: TypeAlias = Union[NodeSchemaAPI, GenericSchemaAPI, ProfileSchemaAPI, TemplateSchemaAPI]
MainSchemaTypesAll: TypeAlias = Union[
NodeSchema, GenericSchema, NodeSchemaAPI, GenericSchemaAPI, ProfileSchemaAPI, TemplateSchemaAPI
]


class InfrahubSchemaBase:
Expand Down Expand Up @@ -417,6 +421,10 @@
profile = ProfileSchemaAPI(**profile_schema)
nodes[profile.kind] = profile

for template_schema in data.get("templates", []):
template = TemplateSchemaAPI(**template_schema)
nodes[template.kind] = template

Check warning on line 426 in infrahub_sdk/schema/__init__.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/schema/__init__.py#L425-L426

Added lines #L425 - L426 were not covered by tests

return nodes


Expand Down Expand Up @@ -621,6 +629,10 @@
profile = ProfileSchemaAPI(**profile_schema)
nodes[profile.kind] = profile

for template_schema in data.get("templates", []):
template = TemplateSchemaAPI(**template_schema)
nodes[template.kind] = template

Check warning on line 634 in infrahub_sdk/schema/__init__.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/schema/__init__.py#L633-L634

Added lines #L633 - L634 were not covered by tests

return nodes

def load(
Expand Down
7 changes: 7 additions & 0 deletions infrahub_sdk/schema/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class RelationshipKind(str, Enum):
GROUP = "Group"
HIERARCHY = "Hierarchy"
PROFILE = "Profile"
TEMPLATE = "Template"


class RelationshipDirection(str, Enum):
Expand Down Expand Up @@ -290,6 +291,7 @@ class BaseNodeSchema(BaseSchema):
branch: BranchSupportType | None = None
default_filter: str | None = None
generate_profile: bool | None = None
generate_template: bool | None = None
parent: str | None = None
children: str | None = None

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


class TemplateSchemaAPI(BaseSchema, BaseSchemaAttrRelAPI):
inherit_from: list[str] = Field(default_factory=list)


class NodeExtensionSchema(BaseModel):
model_config = ConfigDict(use_enum_values=True)

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