Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose valid enum values as slice in Go SDKs #5512

Open
nyergler opened this issue Dec 31, 2024 · 0 comments
Open

Expose valid enum values as slice in Go SDKs #5512

nyergler opened this issue Dec 31, 2024 · 0 comments
Assignees
Labels
feature Requests for new features. go Pull requests that update Go code product/sdk-generator Fern's SDK Generator that outputs client libraries in 7 languages

Comments

@nyergler
Copy link

nyergler commented Dec 31, 2024

Feature Description

We use enumerations in several places in the Polytomic API in order to guide users toward valid values. Fern exposes these as a Go type (great!), but doesn't provide a way to get the full set of valid values. For example, the SyncMode type defined here defines constants for each valid value, but doesn't define a way to get the set of valid values. This would be useful when building other tools to drive the API using the SDK.

Proposed Generated Code (Optional)

Using the SyncMode example, I can imagine one of two approaches:

  • simply defining a slice of the valid modes (this would address the base issue)
var ValidSyncModes = []SyncMode{ ... }
  • defining a method on the type to get the valid modes
func (m *SyncMode) Values() []SyncMode {
    return []SyncMode{...}
}

The latter feels a tiny bit more useful, since it also allows us to describe the implementation as a generic interface:

type Enum[T any] interface {
    Values() []T
}

(Maybe the method should be ValidValues or EnumValues? I feel less invested in the spelling.)

@nyergler nyergler added feature Requests for new features. product/sdk-generator Fern's SDK Generator that outputs client libraries in 7 languages labels Dec 31, 2024
@dannysheridan dannysheridan added the go Pull requests that update Go code label Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Requests for new features. go Pull requests that update Go code product/sdk-generator Fern's SDK Generator that outputs client libraries in 7 languages
Development

No branches or pull requests

3 participants