Skip to content

Support buf.validate.oneof for Valid Types#1372

Open
macalinao wants to merge 1 commit intobufbuild:mainfrom
macalinao:validate-one-of
Open

Support buf.validate.oneof for Valid Types#1372
macalinao wants to merge 1 commit intobufbuild:mainfrom
macalinao:validate-one-of

Conversation

@macalinao
Copy link
Copy Markdown

Summary

  • When (buf.validate.oneof).required = true is set on a oneof, the generated Valid type now excludes the { case: undefined; value?: undefined } variant from the discriminated union
  • Added isProtovalidateOneofRequired() helper and updated messageNeedsCustomValidType() to detect required oneofs
  • Messages with only a required oneof (no required fields) now correctly generate a Valid type

Closes #1171

Test plan

  • Added compile-time type tests verifying required oneof excludes undefined case in Valid type
  • Added compile-time type tests verifying optional oneof still includes undefined case
  • Added compile-time type tests verifying regular oneof is not assignable to required oneof Valid type
  • Added VTypes3 message testing a message with only a required oneof (no required fields)
  • All existing tests pass (2823 tests)

When `(buf.validate.oneof).required = true` is set on a oneof, the
generated Valid type now excludes the `{ case: undefined; value?: undefined }`
variant from the discriminated union, ensuring TypeScript enforces that
a case is always set.

Closes bufbuild#1171
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 23, 2026

CLA assistant check
All committers have signed the CLA.

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.

Support buf.validate.oneof for Valid Types

2 participants