Invoke Validate() on embedded structs and plugin elements#607
Merged
alecthomas merged 1 commit intoJun 26, 2026
Merged
Conversation
Context.Validate iterated c.Path and called isValidatable on each entry's target. Fields tagged embed:"" are flattened into their parent at build time and have no path entry, so any Validate() method on the embedded struct itself was never invoked. The same issue affects kong.Plugins, whose elements are also flattened. Extracts the embedded-field walk that already existed in getMethods into a shared walkEmbedded helper, used by both hooks (getMethods) and validators (new getValidators), so the rules for "what counts as embedded" live in one place. walkEmbedded also descends into Plugins elements, matching what flattenedFields does in build.go — this incidentally fixes the same latent bug for hooks on plugin structs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Jun 20, 2026
Contributor
Author
|
@alecthomas Thanks for the quick merge! 🙏 🚀 If it's not too much to ask, it would be great if we could also get a tag with it? 😇 |
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.
Summary
Context.Validateiteratesc.Pathand callsisValidatableon each entry's target. Fields taggedembed:""are flattened into their parent at build time and have no path entry, so anyValidate()method on the embedded struct itself was never invoked. The same issue affectskong.Plugins, whose elements are also flattened.getMethodsinto a sharedwalkEmbeddedhelper, used by both hooks (getMethods) and validators (newgetValidators), so the rules for "what counts as embedded" live in one place.walkEmbeddedalso descends intoPluginselements, matching whatflattenedFieldsdoes inbuild.go. This incidentally fixes the same latent bug for hooks on plugin structs.Test plan
TestValidateEmbed—Validate()on a struct taggedembed:""at the app rootTestValidateEmbedOnCommand— same, nested under a command (verifies thecmd:prefix)TestValidateNestedEmbed— recursive embed-within-embedTestExtendedValidateEmbed— theValidate(kctx *Context) errorvariantTestValidatePlugin—Validate()on a struct registered viakong.Pluginsgo test ./...andgolangci-lint runpassThis fixes #554