Skip to content

feat(go,cli): add Values helpers listing every known value of a generated enum - #235

Open
AshGodfrey wants to merge 5 commits into
mainfrom
ash/go-enum-values
Open

AshGodfrey wants to merge 5 commits into
mainfrom
ash/go-enum-values

Conversation

@AshGodfrey

@AshGodfrey AshGodfrey commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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 IsExact today 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.

// Before: constants and IsExact only.
// After:
func IconValues() []Icon {
	return []Icon{
		IconTick,
		IconThumbsUp,
		IconFire,
	}
}

Changes

  • templates/templates/go/enum.go.stmpl: emit <Enum>Values() after ToPointer.
  • templates/templates/go/includes/enums.ts: templateEnumValueNames helper that renders the constant names.
  • New primary Go test TestEnumValues covering a string enum, a closed enum, and that every integer enum value passes IsExact.
  • Test ID registered; skipped for every target except go.
  • Review SDKs regenerated for cli and go; only enum files and gen.lock checksums changed.

Testing

  • TARGET=primary make build-go, then go test -run TestEnumValues ./tests/ in the generated SDK.
  • TARGET=review make build-cli and TARGET=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

  • Applies to string, integer, open, and closed enums via the shared Go enum template, covering the go, cli, and terraform targets.
  • Adds a TestEnumValues primary 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.
  • Regenerated review SDKs and refreshed the error-message snapshot; only enum files, snapshot content, and gen.lock checksums changed.

Written for commit 6f113f0. Summary will update on new commits.

View guided diff Turn on auto-fix

…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.
@AshGodfrey
AshGodfrey requested a review from a team as a code owner November 23, 2026 11:12
@github-actions github-actions Bot added csharp Trigger (24) snapshot tests for csharp go Trigger (90) snapshot tests for go java Trigger (40) snapshot tests for java mcp-typescript Trigger (16) snapshot tests for mcp-typescript php Trigger (22) snapshot tests for php python Trigger (106) snapshot tests for python ruby Trigger (19) snapshot tests for ruby typescript Trigger (168) snapshot tests for typescript unity labels Nov 23, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread templates/templates/go/enum.go.stmpl Resolved
…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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@speakeasy-generator-bot

speakeasy-generator-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Generator Snapshot Testing

Selector(s) Result Summary
snapshot-csharp, snapshot-go, snapshot-java, snapshot-mcp-typescript, snapshot-php, snapshot-python, snapshot-ruby, snapshot-typescript ❌ Snapshot run failed

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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 2ynn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@AshGodfrey
AshGodfrey requested a review from 2ynn November 24, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

csharp Trigger (24) snapshot tests for csharp go Trigger (90) snapshot tests for go java Trigger (40) snapshot tests for java mcp-typescript Trigger (16) snapshot tests for mcp-typescript php Trigger (22) snapshot tests for php python Trigger (106) snapshot tests for python ruby Trigger (19) snapshot tests for ruby typescript Trigger (168) snapshot tests for typescript unity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants