From 36a40eec08702003a5e7578b2211d7083a21d224 Mon Sep 17 00:00:00 2001 From: Mihaela Mihaljevic Date: Tue, 9 Jun 2026 08:57:33 +0200 Subject: [PATCH] fix(xsd): locate identity-constraint errors at the offending node Refine the identity-constraint path: rather than locating at the element that declares the key, walk from the constraint-bearing element down to the selected target and report the actual offender, so a duplicate key renders "at path: list/item[2]" and a dangling keyref "at path: orders/line". Also locate the "no element declaration for the root" XSD error at the root element, matching the namespace check beside it that already did so. Lock both with coding-path assertions in the identity tests. --- CHANGELOG.md | 2 +- Sources/Schema/IdentityValidator.swift | 33 +++++++++++++++++++++++--- Sources/Schema/SchemaDocument.swift | 2 +- Tests/XSDIdentityTests.swift | 11 ++++++--- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 433f10f..2669131 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- XSD identity-constraint errors (`key`, `keyref`, `unique`) now carry a coding path locating the constraining element, instead of always rendering "at root of document". The `IdentityValidator` walk threads a `[PathKey]` the same way the content-model validator does, so a duplicate-key or dangling-keyref failure reports "... at path: list" rather than an empty path. This brings the identity-constraint rule into line with the validation framework's path-carrying contract, which every other rule already honored. +- XSD identity-constraint errors (`key`, `keyref`, `unique`) now carry a coding path locating the actual offending element, instead of always rendering "at root of document". The `IdentityValidator` walk threads a `[PathKey]` the same way the content-model validator does, and each error is located at the selected target node, so a duplicate-key failure reports "... at path: list/item[2]" and a dangling keyref "... at path: orders/line" rather than an empty path. This brings the identity-constraint rule into line with the validation framework's path-carrying contract, which every other rule already honored. The "no element declaration for the root" XSD error is likewise located at the root element, matching the namespace check beside it. - A `