Skip to content

Support Validation of union types#423

Draft
steiler wants to merge 4 commits into
mainfrom
supportunion
Draft

Support Validation of union types#423
steiler wants to merge 4 commits into
mainfrom
supportunion

Conversation

@steiler
Copy link
Copy Markdown
Collaborator

@steiler steiler commented May 4, 2026

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.

steiler and others added 2 commits May 4, 2026 12:23
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.
Co-authored-by: Copilot <copilot@github.com>
@steiler steiler linked an issue May 4, 2026 that may be closed by this pull request
steiler and others added 2 commits May 12, 2026 16:53
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validation - Union Types are not taken into account yet

1 participant