Background
YANG when statements contain an xpath expression that may include quoted string literals of the form 'prefix:identity-value'. When a module imports an identity module under a local alias that differs from the imported module's declared prefix, the raw xpath stored at schema compile time contains the local alias rather than the declared prefix.
This causes the xpath evaluator to fail to match identity values — the node is incorrectly treated as non-existent even for valid config.
This is the same root cause as the must statement prefix mismatch (already fixed for must via normalizeXPathLiterals in pkg/schema/leaf.go).
What needs to happen
Wherever the schema-server serialises a when xpath string into the proto, apply the same literal-prefix rewrite:
- Scan quoted string literals (
'...' and "...") in the xpath
- For each
'alias:name' literal: look up alias in the entry's module import table via yang.FindModuleByPrefix
- If found and
alias != importedModule.GetPrefix(): rewrite to 'declaredPrefix:name'
- Otherwise leave unchanged
normalizeXPathLiterals(xpath string, e *yang.Entry) in pkg/schema/leaf.go already implements this logic and is directly reusable — this is purely a call-site addition wherever e.When.Name is consumed.
Notes
when is simpler than must: single xpath string, no sub-statements (RFC 7950 §7.21.5)
- Unlike
must, when lives on yang.Entry.When.Name directly (not in e.Extra)
- Testdata from the
must fix (pkg/schema/testdata/must-alias/) can be extended with when statements
- Idempotent and unknown-prefix cases must remain unchanged (same invariants as
must)
Background
YANG
whenstatements contain an xpath expression that may include quoted string literals of the form'prefix:identity-value'. When a module imports an identity module under a local alias that differs from the imported module's declared prefix, the raw xpath stored at schema compile time contains the local alias rather than the declared prefix.This causes the xpath evaluator to fail to match identity values — the node is incorrectly treated as non-existent even for valid config.
This is the same root cause as the
muststatement prefix mismatch (already fixed formustvianormalizeXPathLiteralsinpkg/schema/leaf.go).What needs to happen
Wherever the schema-server serialises a
whenxpath string into the proto, apply the same literal-prefix rewrite:'...'and"...") in the xpath'alias:name'literal: look upaliasin the entry's module import table viayang.FindModuleByPrefixalias != importedModule.GetPrefix(): rewrite to'declaredPrefix:name'normalizeXPathLiterals(xpath string, e *yang.Entry)inpkg/schema/leaf.goalready implements this logic and is directly reusable — this is purely a call-site addition wherevere.When.Nameis consumed.Notes
whenis simpler thanmust: single xpath string, no sub-statements (RFC 7950 §7.21.5)must,whenlives onyang.Entry.When.Namedirectly (not ine.Extra)mustfix (pkg/schema/testdata/must-alias/) can be extended withwhenstatementsmust)