Repository navigation
feat(go,cli): add Values helpers listing every known value of a generated enum - #235
AshGodfrey wants to merge 5 commits into
Conversation
…ated enum Each generated Go enum type gains a package-level <Enum>Values() function returning its known values in schema order, so callers can build help text and validation hints from the schema instead of hardcoding value lists.
There was a problem hiding this comment.
All reported issues were addressed across 56 files
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
…erate the terraform review provider When a schema in the same package is already named <Enum>Values, the helper falls back to <Enum>EnumValues so the generated package still compiles.
There was a problem hiding this comment.
0 issues found across 24 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would require human review. Adds generated Go enum Values() helpers, a new primary Go test, and regenerated SDK outputs. Human review is needed because the disputed P1 about the new test referencing shared.Kind and possibly not compiling is unverified: the test template diff is omitted.
View guided diff | Turn on auto-fix | Re-trigger cubic
Generator Snapshot Testing
Snapshot results: https://github.com/speakeasy-api/openapi-generation-snapshots/issues/176#issuecomment-7136048703 Snapshot results are summarized above. Additional run context is linked for maintainers with access. |
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would require human review. Adds generated Go enum Values helpers, a primary test, and regenerated SDKs. The dismissed P1 that the test references shared.Kind is unverifiable because the test template diff is omitted; a human must confirm the generated Go test suite compiles.
View guided diff | Turn on auto-fix | Re-trigger cubic
2ynn
left a comment
There was a problem hiding this comment.
Generated Go packages fail to compile when an enum helper name collides with an enum constant or another helper; details inline.
…ng enums and union constructors Allocate the helper name once per package, in sorted enum order, against every type name, enum constant, union constructor and already-allocated helper. Match union constructor names exactly instead of by prefix, which looped forever when an enum's name started with a union's constructor prefix. Add a fragment covering a member literally named values and two enums competing for the same helper name, and assert the full ordered lists in the primary test.
There was a problem hiding this comment.
All reported issues were addressed across 3 files (changes from recent commits).
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
…elpers Per-operation server ids render as package-level constants in the operations package, so an enum sharing that prefix could redeclare one. Add them to the taken set, and assert the full HeroWidth list so the integer-backed helper stays covered.
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would require human review. Adds generated Go enum-value helpers and collision handling. A human should approve the new exported SDK API and its naming contract before it ships to consumers.
View guided diff | Turn on auto-fix | Re-trigger cubic
Summary
Every generated Go enum type gains a package-level
<Enum>Values()function that returns its known values in schema order. Open and closed enums both get it, including integer-typed enums. The CLI target picks it up through the shared Go enum template.Generated SDKs that expose string enums with
IsExacttoday give callers no way to enumerate the valid values, so CLIs and wrappers built on them end up hardcoding value lists in help text and validation hints. With this helper those lists come from the schema and update on regeneration.Changes
templates/templates/go/enum.go.stmpl: emit<Enum>Values()afterToPointer.templates/templates/go/includes/enums.ts:templateEnumValueNameshelper that renders the constant names.TestEnumValuescovering a string enum, a closed enum, and that every integer enum value passesIsExact.cliandgo; only enum files and gen.lock checksums changed.Testing
TARGET=primary make build-go, thengo test -run TestEnumValues ./tests/in the generated SDK.TARGET=review make build-cliandTARGET=review make build-go(compile + staticcheck).make lint,make check-template-go.Summary by cubic
Adds a package-level
<Enum>Values()function to every generated Go enum type, returning its known values in schema order. Callers that build help text and validation hints can now pull those lists from the schema instead of hardcoding them.Helper names are allocated per package in sorted enum order so they never collide with type names, enum constants, union constructors, operation server constants, or other helpers; when a collision is detected the helper falls back to
<Enum>EnumValues, then<Enum>EnumValues2, and so on, so the generated package still compiles.Notes
go,cli, andterraformtargets.TestEnumValuesprimary test covering string, closed, and integer enums, registered as skipped for non-Go targets, plus a fragment exercising member, sibling-name, and server-constant collisions.gen.lockchecksums changed.Written for commit 6f113f0. Summary will update on new commits.