Skip to content

Validator generator [WiP] - #10200

Closed
stephanos wants to merge 10 commits into
mainfrom
stephanos/protobuf-validate-gen
Closed

Validator generator [WiP]#10200
stephanos wants to merge 10 commits into
mainfrom
stephanos/protobuf-validate-gen

Conversation

@stephanos

@stephanos stephanos commented May 8, 2026

Copy link
Copy Markdown
Contributor

What changed?

Opt-in validator that exhaustively validate all protobuf fields in 1 place.

Why?

Adds semantic validation for protobufs as a thin layer before the proto request reaches actual business logic.

How did you test it?

  • built
  • run locally and tested manually
  • covered by existing tests
  • added new unit test(s)
  • added new functional test(s)

@stephanos
stephanos force-pushed the stephanos/protobuf-validate-gen branch 6 times, most recently from 0fc7732 to e10b967 Compare May 8, 2026 02:43
Comment thread tests/validators_test.go
"go.uber.org/fx"
)

type ValidatorsSuite struct {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test detects if a validator has a missing field validator.

@stephanos
stephanos force-pushed the stephanos/protobuf-validate-gen branch 5 times, most recently from 637a3c3 to c42f6af Compare May 8, 2026 02:49
@long-nt-tran
long-nt-tran self-requested a review May 8, 2026 18:46
@long-nt-tran
long-nt-tran force-pushed the stephanos/protobuf-validate-gen branch 4 times, most recently from 298af06 to aa2af8f Compare June 2, 2026 16:43
@long-nt-tran
long-nt-tran force-pushed the stephanos/protobuf-validate-gen branch from aa2af8f to fc4fbf2 Compare July 13, 2026 22:22
stephanos added a commit that referenced this pull request Jul 14, 2026
Replace the presence-only, predicate-based validator with the typed design
from PR #10200:

- api/protohelpers/validation: FieldValidator[T,V] func(*T, fieldName, V) error
  + Field/Optional/NestedFieldValidator helpers, a ValidatorRegistry for
  type-based dispatch, and an fx Module. Testify-free (prod-safe).
- Generated api/protohelpers/validate now emits a typed <Msg>FieldValidators
  struct (one FieldValidator per field), ValidateAndNormalize (invokes each in
  order, can mutate for normalization), and RegisterValidator. Field validators
  receive the parent message (cross-field checks) and typed value; every field
  must be assigned (nil panics), preserving exhaustiveness.
- Matcher keeps the thin predicate vocabulary; validator no longer shares it.
  The two now share only the field model + exhaustiveness.

Frontend StartWorkflowExecution uses the typed validator (non-preempting:
message-presence required, fields with specific downstream errors Optional).

Also: activity_test example now omits every field with a testvar default,
relying on env.Requests() defaults; eager suite asserts the response with the
generated matcher.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@long-nt-tran
long-nt-tran force-pushed the stephanos/protobuf-validate-gen branch from fc4fbf2 to fdda0b6 Compare July 14, 2026 15:24
@long-nt-tran
long-nt-tran force-pushed the stephanos/protobuf-validate-gen branch 2 times, most recently from 01d700b to d1fb599 Compare July 23, 2026 16:23
stephanos and others added 6 commits August 12, 2026 16:56
The nested ValidateAndNormalize now takes a fieldPrefix string so
sub-field errors render as "user_metadata.summary" rather than
just "summary".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
long-nt-tran and others added 3 commits August 12, 2026 17:05
- Drop `req *T` from NestedFieldValidator signature; the parent context
  is never needed since namespace is already passed explicitly.
- Add NoOp[T,V]() and NestedNoOp[T,V]() helpers to replace verbose
  inline no-op closures throughout validator.go.
- Generator auto-wires nested proto types: fields whose Go type matches
  a `nested:` entry are emitted as an embedded `{prefix}FieldValidators`
  struct and their ValidateAndNormalize call is forwarded automatically,
  removing the hand-written bridging closure in validator.go.
- Regenerate validator_gen.go to reflect all of the above.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@long-nt-tran
long-nt-tran force-pushed the stephanos/protobuf-validate-gen branch from 48f3f26 to 415452d Compare August 13, 2026 01:34
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@stephanos stephanos closed this Aug 27, 2026
@stephanos
stephanos deleted the stephanos/protobuf-validate-gen branch August 27, 2026 22:06
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.

2 participants