Skip to content

Show enum values and API types in resource command help#1501

Merged
bernerd-stripe merged 5 commits intomasterfrom
bernerd/fix-enum-values-in-resource-commands
Mar 23, 2026
Merged

Show enum values and API types in resource command help#1501
bernerd-stripe merged 5 commits intomasterfrom
bernerd/fix-enum-values-in-resource-commands

Conversation

@bernerd-stripe
Copy link
Copy Markdown
Contributor

Reviewers

r?
cc @stripe/developer-products

Summary

  • Show API types (<string>, <integer>, etc.) for all request parameters in resource command help
  • Extract enum values from the OpenAPI spec and display them inline (e.g. active|canceled)
  • Add enum extraction for GET/DELETE query parameters (previously only POST was handled)
  • Split generated mega-functions into per-namespace helpers to fix a Go arm64 linker crash

Before

Request parameters showed only flag names with no type information, accepted values, or usage hints:

Request Parameters:
      --account
      --collect
      --collection-options.fields
      --collection-options.future-requirements
      --refresh-url
      --return-url
      --type

After

Each parameter now shows its API type in angle brackets, enum values are displayed inline with |, booleans show true|false, and arrays indicate repeatability.

POST with enums (stripe account_links create --help):

Request Parameters:
      --account <string>
      --collect currently_due|eventually_due
      --collection-options.fields <string>
      --collection-options.future-requirements <string>
      --refresh-url <string>
      --return-url <string>
      --type account_onboarding|account_update

GET with types and enums (stripe checkout sessions list --help):

Request Parameters:
      --created <integer>
      --customer <string>
      --customer-account <string>
      --ending-before <string>
      --limit <integer>
      --payment-intent <string>
      --payment-link <string>
      --starting-after <string>
      --status complete|expired|open
      --subscription <string>

Booleans, arrays, numbers, and enums (stripe tax_rates create --help):

Request Parameters:
      --active true|false
      --country <string>
      --description <string>
      --display-name <string>
      --inclusive true|false
      --jurisdiction <string>
      --percentage <number>
      --state <string>
      --tax-type amusement_tax|communications_tax|gst|hst|igst|...

Arrays (stripe accounts create --help, excerpt):

      --documents.company-license.files <string>  [can be specified multiple times]

Short enums (stripe customers create --help, excerpt):

      --tax-exempt exempt|none|reverse
      --validate true|false

Details

Enum extraction from OpenAPI spec: The Stripe API spec supports an x-stripeEnum extension with rich enum metadata (values + descriptions), but this extension is explicitly excluded from the CLI's version of the spec and has never been present in it. The generator already had code to read x-stripeEnum but it was always empty. This change adds a fallback to the standard JSON Schema enum arrays, which are present in the CLI spec. Enum extraction was also added for GET/DELETE query parameters, which was previously missing entirely.

Display formatting: Types use angle brackets (<string>) to visually distinguish them from literal enum values (active|canceled|expired). Enums with more than 5 values are truncated with |.... Empty string enum values (used in the Stripe API to mean "unset this field") are filtered out at code generation time.

Simplified enum type: Since the CLI spec only provides plain enum arrays (not the richer x-stripeEnum), the enum parameter was simplified from map[string][]spec.StripeEnumValue to map[string][]string. Enum values and API types are stored as flag annotations for the display layer.

Linker crash fix: Adding enum data to the generated code pushed addV1ResourcesCmds() to 6,076 lines with 570 NewOperationCmd calls, each containing inline map literals. This caused a Go 1.26 arm64 linker crash (go#77593) when building with CGO_ENABLED=1 (required for -race tests). The fix restructures the code generation template to emit one function per namespace instead of one mega-function per API version. The coordinator addV1ResourcesCmds() now calls ~17 per-namespace helpers (e.g. addV1NsBillingResourcesCmds, addV1NsIssuingResourcesCmds), with the largest (root namespace) at ~3,768 lines — roughly 62% of the original.

Test plan

  • go vet ./... passes
  • go test ./pkg/cmd/... ./pkg/stripe/... passes
  • CGO_ENABLED=1 go test -race ./pkg/cmd/ passes (previously crashed)
  • Verify help output: stripe account_links create --help (POST with enums)
  • Verify help output: stripe checkout sessions list --help (GET with enum)
  • Verify help output: stripe accounts create --help (boolean, array, number types)
  • Verify help output: stripe tax_rates create --help (long enum truncation)
  • Verify help output: stripe customers create --help (no leading pipe on tax-exempt)
  • Verify help output: stripe billing meters list --help (namespaced command still works)

🤖 Generated with Claude Code

bernerd-stripe and others added 4 commits March 19, 2026 17:13
Extract enum values from standard JSON Schema `enum` arrays in the
OpenAPI spec (in addition to the existing `x-stripeEnum` support) and
display them in operation help output. Also extract enums from GET/DELETE
query parameters, which were previously missing.

Help output now shows:
- Enum flags as literal values: --status complete|expired|open
- Booleans as: --requested true|false
- Typed params in angle brackets: --amount <integer>
- Arrays as: --files <string>  [can be specified multiple times]
- Long enums truncated at 5 values: --type a|b|c|d|e|...

The enum parameter type was simplified from map[string][]spec.StripeEnumValue
to map[string][]string since the spec only provides plain value lists.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Committed-By-Agent: claude
Some OpenAPI spec enums include "" (empty string) to represent
"clear/unset this field". This caused a rendering bug with a leading
pipe in help output (e.g. --tax-exempt |exempt|none|reverse). Filter
these out at code generation time.

Affects: account_holder_type, tax_exempt, setup_future_usage

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Committed-By-Agent: claude
The generated addV1ResourcesCmds() was a 6,076-line function that caused
a Go arm64 linker crash (go#77593) when building with CGO_ENABLED=1
(required for -race tests). The crash occurs in gensymlate when a
function's compiled code/data exceeds internal limits.

Restructure the template to generate one function per namespace instead
of one mega-function per API version. This splits addV1ResourcesCmds
into a coordinator calling ~17 per-namespace helpers, with the largest
(root namespace) at ~3,768 lines — roughly 62% of the original size.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Committed-By-Agent: claude
Trim whitespace in the coordinator function template loop to prevent
a blank line before the closing brace, which triggered golangci-lint
"unnecessary trailing newline" errors.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Committed-By-Agent: claude
@bernerd-stripe bernerd-stripe requested a review from a team as a code owner March 20, 2026 21:38
@bernerd-stripe bernerd-stripe merged commit aaaa984 into master Mar 23, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants