Skip to content

Support Validation of union types#423

Draft
steiler wants to merge 2 commits intomainfrom
supportunion
Draft

Support Validation of union types#423
steiler wants to merge 2 commits intomainfrom
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>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

❌ Patch coverage is 82.66667% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...kg/tree/ops/validation/validation_entry_leafref.go 70.00% 4 Missing and 2 partials ⚠️
pkg/tree/types/update.go 72.22% 5 Missing ⚠️
pkg/tree/ops/validation/validation_entry_length.go 87.50% 1 Missing ⚠️
...kg/tree/ops/validation/validation_entry_pattern.go 87.50% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@steiler steiler linked an issue May 4, 2026 that may be closed by this pull request
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