feat(generators): validate non-string enums and consts (#137) - #325
Merged
Merged
Conversation
Enum and const validation directives were only generated when every value was a string; integer and boolean enums/consts produced no validation tag at all. Generate `oneof`/`eq` directives for numeric and boolean scalars too, keeping string values single-quoted as before. Fixes #137 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Issue
Fixes #137 — enum validation was only emitted when all enum values were strings; integer and boolean enums (and consts) produced no
validatetag, so out-of-enum values were never rejected.Change
appendEnumDirectivesand the const handling now format numeric (float64/int/int64) and boolean scalars in addition to strings, producingoneof=1 2 3/oneof=true false/eq=42. String values stay single-quoted to preserve space handling. If any enum element is a non-scalar (object/array), the directive is skipped as before.Test
pkg/codegen/generators/helpers_test.goexercisesGenerateValidateTagswith string, integer and boolean enums plus a numeric const. The integer/boolean/const cases fail before the change (no directive emitted) and pass after.go generate ./...produces no golden-file diff (no existing spec uses non-string enums).🤖 Generated with Claude Code