Skip to content

Commit 15eafef

Browse files
committed
add the "ordered" schema attribute property
1 parent e0c27a1 commit 15eafef

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

infrahub_sdk/schema/export.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def to_dict(self) -> dict[str, dict[str, list[dict[str, Any]]]]:
4949
_ATTR_EXPORT_DEFAULTS: dict[str, Any] = {
5050
"read_only": False,
5151
"optional": False,
52+
"ordered": True,
5253
}
5354

5455
# Relationship field values that match schema loading defaults — omitted for cleaner output

infrahub_sdk/schema/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class AttributeSchema(BaseModel):
111111
min_length: int | None = None
112112
regex: str | None = None
113113
order_weight: int | None = None
114+
ordered: bool = True
114115

115116

116117
class AttributeSchemaAPI(AttributeSchema):

tests/unit/sdk/test_schema_export.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
SchemaExport,
1414
TemplateSchemaAPI,
1515
)
16+
from infrahub_sdk.schema.export import schema_to_export_dict
1617

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

193194

195+
def test_export_preserves_non_default_ordered_flag() -> None:
196+
"""`ordered: false` survives the fetch -> export round-trip; the default `true` is omitted."""
197+
node = NodeSchemaAPI(
198+
**{
199+
**_BASE_NODE,
200+
"namespace": "Infra",
201+
"name": "Device",
202+
"attributes": [
203+
{"name": "tags_unordered", "kind": "List", "ordered": False},
204+
{"name": "tags_ordered", "kind": "List"},
205+
],
206+
}
207+
)
208+
exported = schema_to_export_dict(node)
209+
attrs = {attr["name"]: attr for attr in exported["attributes"]}
210+
assert attrs["tags_unordered"]["ordered"] is False
211+
assert "ordered" not in attrs["tags_ordered"]
212+
213+
194214
# ---------------------------------------------------------------------------
195215
# Integration tests for export() method on client.schema
196216
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)