Commit 4b72bdb
feat: add Valid() method to generated enum types (#2227)
* feat: add Valid() method to generated enum types
Generate a Valid() bool method on each enum type that returns true when
the receiver matches one of the defined enum constants and false
otherwise. This lets callers validate enum values at runtime with a
simple method call instead of hand-writing switch statements.
This is default-on because it only adds a new method to an already
generated type -- existing code that does not call Valid() is completely
unaffected, so this should be very unlikely to break anything.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Reduce complexity in enum validation
It turns out we don't need a sorted map of names, since we have
the same thing already present on the template context in a
different way.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent f4ac5df commit 4b72bdb
File tree
10 files changed
+342
-0
lines changed- internal/test
- components
- externalref/petstore
- issues
- issue-1189
- issue-1397
- issue-832
- issue-illegal_enum_names
- parameters
- schemas
- server
- pkg/codegen/templates
10 files changed
+342
-0
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments