Skip to content

Validate selected union branches before checking fields - #4070

Merged
raphael merged 1 commit into
v3from
union-value-validation
Oct 23, 2026
Merged

raphael merged 1 commit into
v3from
union-value-validation

Conversation

@raphael

@raphael raphael commented Oct 23, 2026

Copy link
Copy Markdown
Member

Generated Goa validation could accept a union with an unknown branch kind or a selected object branch whose value was nil. When the branch fields had no constraints, validation could succeed even though encoding rejected the same value. Invalid typed values could therefore pass the checks callers use before conversion or encoding.

Both planned and legacy validation now call the generated union's existing Validate method before checking the selected branch's fields, including when those fields have no constraints. Optional value unions with no selection and nil optional pointers remain absent; a present pointer must contain a valid selection. Allocated empty collections still follow their declared length rules. Named and derived union roots use the methods of their underlying generated union.

Generated runtime fixtures verify invalid selections, optional absence, empty collections, named roots, and unchanged inputs. Focused validation, view, HTTP, WebSocket, and gRPC checks and affected-package lint passed. Race detection covered the outer generator fixture package; child generated-module checks ran normal tests. The full repository suite was not run. Regenerate affected code to receive the checks.

@raphael
raphael merged commit 4611c10 into v3 Oct 23, 2026
5 checks passed
@raphael
raphael deleted the union-value-validation branch October 23, 2026 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant