Repository navigation
fix(gen): generate valid code for object-level x-ogen-validate - #1772
Merged
ernado merged 2 commits intoNov 13, 2026
Merged
Conversation
Object-level validators were generated as calls to validate.ValidateWith, which does not exist, so the generated package did not compile. Call validate.Ogen with the struct value instead, the same way field and map validators receive their values. Since the struct's Validate() now runs object-level validators, skip them in the generic validate template for struct types. Otherwise every request/response validation would call them twice, once from Validate() and once at the call site, with the value passed as a pointer in one place and by value in the other.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Object-level
x-ogen-validate(set on an object schema rather than on a property) generated a call tovalidate.ValidateWith, which doesn't exist, so the generated package didn't build:Changes:
Validate()now callsvalidate.Ogen(name, *s, params). The validator receives the struct value, the same way field- and map-level validators receive their values.validatetemplate no longer emitsvalidate.Ogenfor struct types at call sites, becauseValidate()already runs these validators. Without this, every request/response validation would call the validator twice: once fromValidate()with*T, and once at the call site withTon the server (or*Ton the client). A validator that type-asserts either type would then reject valid input.Field-level and map-level validators are unchanged. The generated code is in a separate
chore: commit generated filescommit, and the only generated file that changes istest_ogen_validate/oas_validators_gen.go.Testing:
minAge) to_testdata/positive/ogen_validate.yaml. Inogen_validate_test.go, it type-assertsUser, and I added a failing-input case plus a server request that checks the validator runs exactly once.go test ./...,go test ./...inexamples,go vet ./...andgolangci-lint runpass (Go 1.26).make generate examplesproduces no other diff.Fixes #1718