Skip to content

Commit 1b67b25

Browse files
committed
Ignore ids in free-form values
An id inside a custom property value, property examples, or quality arguments or implementation is the user's own data, so repeating it no longer fails the contract.
1 parent 31f2adf commit 1b67b25

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎datacontract/lint/constraints.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ def collect_ids(node, path):
123123
collect_ids(item, item_path)
124124
elif isinstance(node, dict):
125125
for key, child in node.items():
126-
collect_ids(child, f"{path}.{key}" if path else key)
126+
# These hold the user's own data, where an id is not an ODCS stable id
127+
if key not in ("value", "examples", "arguments", "implementation"):
128+
collect_ids(child, f"{path}.{key}" if path else key)
127129

128130
collect_ids(contract, "")
129131
return errors

‎tests/test_lint_duplicates.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ def test_same_id_in_different_arrays_is_valid():
9696
assert lint(doc).result == "passed"
9797

9898

99+
@pytest.mark.parametrize(
100+
"overrides",
101+
[
102+
{"customProperties": [{"property": "related", "value": [{"id": "x", "v": 1}, {"id": "x", "v": 2}]}]},
103+
{"schema": [{"name": "o", "properties": [{"name": "a", "examples": [{"id": "x"}, {"id": "x"}]}]}]},
104+
],
105+
)
106+
def test_repeated_id_in_free_form_values_is_valid(overrides):
107+
assert lint(document(**overrides)).result == "passed"
108+
109+
99110
def test_names_are_case_sensitive():
100111
assert lint(document(schema=[{"name": "Orders"}, {"name": "orders"}])).result == "passed"
101112

0 commit comments

Comments
 (0)