Fix leafref path resolution under choice/case YANG nodes#234
Open
Fix leafref path resolution under choice/case YANG nodes#234
Conversation
YANG `choice` and `case` nodes are structural — they exist in the AST for
conditional branching but are absent from the effective instance-data path.
`GetEntry()` flattens through them, so any reconstructed lookup path that
includes their names fails with "entry not found".
`relativeToAbsPath()` was walking the parent chain one step per `..` token
without skipping these structural nodes. For a leaf nested under `choice`/`case`
ancestors, the reconstructed absolute path included those names, breaking schema
initialization and live schema queries for the affected leafrefs.
### Changes
- **`relativeToAbsPath()`** — skips `IsChoice()`/`IsCase()` nodes during both
the `..` traversal and the upward prefix reconstruction.
- **`buildReferences()` and `toSchemaType()`** — `GetEntry()` errors now include
the original leafref path and the normalized path slice for actionable
diagnostics.
- **`references_test.go`** — added:
- Integration fixture (synthetic YANG, no vendor deps) reproducing the
choice/case/list/leafref topology; verifies schema init succeeds and `REF_`
annotation is attached to the resolved target.
- `normalizePath()` matrix covering: relative with choice/case ancestors,
relative without, absolute path, module-prefixed segments.
- Error-format assertions for both `buildReferences()` and `toSchemaType()`
call paths.
### Out of scope
- No `GetEntry()` strip-pass for choice/case labels (would silently mask
malformed paths).
- `relativeToAbsPathKeys()` key-annotation fix is deferred (metadata only, not
resolution correctness).
- Absolute leafref paths that name choice/case labels are invalid YANG
(RFC 7950 §9.9.5) — vendor issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
YANG
choiceandcasenodes are structural — they exist in the AST for conditional branching but are absent from the effective instance-data path.GetEntry()flattens through them, so any reconstructed lookup path that includes their names fails with "entry not found".relativeToAbsPath()was walking the parent chain one step per..token without skipping these structural nodes. For a leaf nested underchoice/caseancestors, the reconstructed absolute path included those names, breaking schema initialization and live schema queries for the affected leafrefs.Changes
relativeToAbsPath()— skipsIsChoice()/IsCase()nodes during both the..traversal and the upward prefix reconstruction.buildReferences()andtoSchemaType()—GetEntry()errors now include the original leafref path and the normalized path slice for actionable diagnostics.references_test.go— added:REF_annotation is attached to the resolved target.normalizePath()matrix covering: relative with choice/case ancestors, relative without, absolute path, module-prefixed segments.buildReferences()andtoSchemaType()call paths.Out of scope
GetEntry()strip-pass for choice/case labels (would silently mask malformed paths).relativeToAbsPathKeys()key-annotation fix is deferred (metadata only, not resolution correctness).