Skip to content

Flagify enum validator generation#2334

Merged
mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:feat/flagify-enum-validate
Apr 23, 2026
Merged

Flagify enum validator generation#2334
mromaszewicz merged 1 commit into
oapi-codegen:mainfrom
mromaszewicz:feat/flagify-enum-validate

Conversation

@mromaszewicz

Copy link
Copy Markdown
Member

Add an output-options.skip-enum-validate flag that suppresses the Valid() method generated on enum types. The method is still emitted by default; users whose code defines its own Valid() on the same type can now opt out instead of seeing a compile-time conflict.

Relates to PR #2227, which introduced the Valid() method.

Add an `output-options.skip-enum-validate` flag that suppresses the
`Valid()` method generated on enum types. The method is still emitted
by default; users whose code defines its own `Valid()` on the same type
can now opt out instead of seeing a compile-time conflict.

Relates to PR oapi-codegen#2227, which introduced the `Valid()` method.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mromaszewicz mromaszewicz requested a review from a team as a code owner April 23, 2026 17:07
@mromaszewicz mromaszewicz added this to the v2.7.0 milestone Apr 23, 2026
@mromaszewicz mromaszewicz added the enhancement New feature or request label Apr 23, 2026
@mromaszewicz

Copy link
Copy Markdown
Member Author

@greptileai

@greptile-apps

greptile-apps Bot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds a new output-options.skip-enum-validate flag that conditionally suppresses the Valid() bool method on generated enum types. The change is minimal and well-contained: a boolean field added to OutputOptions and Constants, propagated through GenerateEnums, and gated in constants.tmpl with {{if not $.SkipEnumValidate}}. The JSON schema is kept in sync. No tests are included for the new flag.

Confidence Score: 5/5

Safe to merge; all remaining feedback is P2 style/test suggestions with no correctness concerns.

The change is additive, opt-in (defaults to false, preserving existing behaviour), and touches only the enum-generation path. The only gap is the absence of a regression test for the new flag, which is a P2 concern and does not block merge.

No files require special attention.

Important Files Changed

Filename Overview
pkg/codegen/templates/constants.tmpl Wraps the Valid() method generation in {{if not $.SkipEnumValidate}} guard inside the existing enum range loop; logic is correct.
pkg/codegen/configuration.go Adds SkipEnumValidate bool field to OutputOptions with proper yaml tag and doc comment; consistent with existing skip-* fields.
pkg/codegen/schema.go Adds SkipEnumValidate bool to Constants struct for passing the flag to the template.
pkg/codegen/codegen.go Populates Constants.SkipEnumValidate from globalState.options.OutputOptions in GenerateEnums; consistent with how the codebase reads global config.
configuration-schema.json Adds skip-enum-validate boolean field to JSON schema, keeping it in sync with the Go struct.

Reviews (1): Last reviewed commit: "Flagify enum validator generation" | Re-trigger Greptile

@mromaszewicz mromaszewicz merged commit dd7d133 into oapi-codegen:main Apr 23, 2026
19 checks passed
@mromaszewicz mromaszewicz deleted the feat/flagify-enum-validate branch April 23, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants