Update enum generation to generate a map to validate enums.#2181
Closed
AndreasAbdi wants to merge 1 commit into
Closed
Update enum generation to generate a map to validate enums.#2181AndreasAbdi wants to merge 1 commit into
AndreasAbdi wants to merge 1 commit into
Conversation
Customers often need to validate whether a value is a legit enum value. We implement that validation by creating helper functions. With the helper function, customers no longer have to manually write their own version of the helper.
jamietanna
reviewed
Jan 9, 2026
Member
|
Can your problem be solved via request validation middleware? For example,
In all the servers that I've written, I've left the problem of validating inputs against schemas to other, excellent projects that already exist. I think oapi-codegen should be as narrowly focused as a code generator as possible. |
Member
Member
|
What do you guys think of doing it like this? #2227 We don't need a map, we've got a code generator that can generate a nice Valid() function. |
Member
|
Thanks for this PR, but I am closing it, because we have an alternate fix already merged. The Enum types have a Validate function now, which just uses a switch statement to check for valid values. |
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.
Customers often need to validate whether a value is a legit enum value.
We implement that validation by creating helper functions.
With the helper function, customers no longer have to manually write their own version of the helper.
i.e.
and then the customer uses it like: