Skip to content
Open
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
1 change: 1 addition & 0 deletions infrahub_sdk/schema/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def to_dict(self) -> dict[str, dict[str, list[dict[str, Any]]]]:
_ATTR_EXPORT_DEFAULTS: dict[str, Any] = {
"read_only": False,
"optional": False,
"ordered": True,
}

# Relationship field values that match schema loading defaults — omitted for cleaner output
Expand Down
1 change: 1 addition & 0 deletions infrahub_sdk/schema/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class AttributeSchema(BaseModel):
min_length: int | None = None
regex: str | None = None
order_weight: int | None = None
ordered: bool = True


class AttributeSchemaAPI(AttributeSchema):
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/sdk/test_schema_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
SchemaExport,
TemplateSchemaAPI,
)
from infrahub_sdk.schema.export import schema_to_export_dict

if TYPE_CHECKING:
from pytest_httpx import HTTPXMock
Expand Down Expand Up @@ -191,6 +192,25 @@ def test_to_dict(self) -> None:
assert len(as_dict["Infra"]["generics"]) == 1


def test_export_preserves_non_default_ordered_flag() -> None:
"""`ordered: false` survives the fetch -> export round-trip; the default `true` is omitted."""
node = NodeSchemaAPI(
**{
**_BASE_NODE,
"namespace": "Infra",
"name": "Device",
"attributes": [
{"name": "tags_unordered", "kind": "List", "ordered": False},
{"name": "tags_ordered", "kind": "List"},
],
}
)
exported = schema_to_export_dict(node)
attrs = {attr["name"]: attr for attr in exported["attributes"]}
assert attrs["tags_unordered"]["ordered"] is False
assert "ordered" not in attrs["tags_ordered"]


# ---------------------------------------------------------------------------
# Integration tests for export() method on client.schema
# ---------------------------------------------------------------------------
Expand Down