Support Validation of union types#423
Draft
steiler wants to merge 4 commits into
Draft
Conversation
This PR fixes validation gaps for YANG leaves defined as union types. Today, union branch selection happens at import time (XML/JSON/proto): the server tries branches in order and stores the first successfully parsed TypedValue. Later, validation runs against the outer union schema type instead of the specific matched branch type. Because the outer union type does not carry branch-specific constraints, several validators can no-op unexpectedly. Problem For union-typed leaves, the current validation path can miss real violations: Pattern and length checks read constraints from the outer union type, which has none. Range checks read constraints from the outer union type, which has none. Leafref checks look for a leafref path on the outer union type, which is empty. This means values that actually matched a leafref branch can bypass live-tree reference validation, allowing dangling references to pass undetected.
Apply EffectiveLeafType in navigateLeafRef so FollowLeafRef matches validateLeafRefs for union+leafref leaves. Document leaf-list union range limitation. Add optional-instance union leafref tests, internal navigateLeafRef/FollowLeafRef test, and Update Equal/String coverage. Regenerate sdcio ygot for unionoptionalleafreftest. Refs: #177 Co-authored-by: Cursor <cursoragent@cursor.com>
InferUnionMemberFromTypedValue narrows unions from wire TypedValues (lexical re-parse + structural fallback); proto and XML importers and leaf defaults attach the matched branch so validation and EffectiveLeafType align. Adds ingress/parity tests and schema fixtures; drops the PR #423 supplement note.
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.
This PR fixes validation gaps for YANG leaves defined as union types.
Today, union branch selection happens at import time (XML/JSON/proto): the server tries branches in order and stores the first successfully parsed TypedValue. Later, validation runs against the outer union schema type instead of the specific matched branch type. Because the outer union type does not carry branch-specific constraints, several validators can no-op unexpectedly.
Problem
For union-typed leaves, the current validation path can miss real violations:
Pattern and length checks read constraints from the outer union type, which has none.
Range checks read constraints from the outer union type, which has none.
Leafref checks look for a leafref path on the outer union type, which is empty.
This means values that actually matched a leafref branch can bypass live-tree reference validation, allowing dangling references to pass undetected.