feat(go,cli): add Values helpers listing every known value of a generated enum
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()afterToPointer.templates/templates/go/includes/enums.ts:templateEnumValueNameshelper that renders the constant names.- New primary Go test
TestEnumValuescovering a string enum, a closed enum, and that every integer enum value passesIsExact. - Test ID registered; skipped for every target except go.
- Review SDKs regenerated for
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
- Applies to string, integer, open, and closed enums via the shared Go enum template, covering the
go,cli, andterraformtargets. - Adds a
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. - Regenerated review SDKs and refreshed the error-message snapshot; only enum files, snapshot content, and
gen.lockchecksums changed.