Skip to content

feat(generators): validate non-string enums and consts (#137) - #325

Merged
lerenn merged 1 commit into
mainfrom
feat/137-enum-validation
Jun 12, 2026
Merged

lerenn merged 1 commit into
mainfrom
feat/137-enum-validation

Conversation

@lerenn

@lerenn lerenn commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Issue

Fixes #137 — enum validation was only emitted when all enum values were strings; integer and boolean enums (and consts) produced no validate tag, so out-of-enum values were never rejected.

Change

appendEnumDirectives and the const handling now format numeric (float64/int/int64) and boolean scalars in addition to strings, producing oneof=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.go exercises GenerateValidateTags with 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

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>
@lerenn
lerenn merged commit 46104c3 into main Jun 12, 2026
5 checks passed
@lerenn
lerenn deleted the feat/137-enum-validation branch June 12, 2026 15:08
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.

AsyncAPI v2 & v3: add validation on enumerations

1 participant