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

enh: Add optional enum prefix separator setting #1502

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/codegen/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ type CompatibilityOptions struct {
// When set to true, always prefix enum values with their type name instead of only
// when typenames would be conflicting.
AlwaysPrefixEnumValues bool `yaml:"always-prefix-enum-values,omitempty"`
// When prefixing enum values with typename, this specifies an optional separator string to include for improving
// readability. By default, the empty string is used (i.e., no separator).
EnumPrefixSeparator string `yaml:"enum-prefix-separator,omitempty"`
// Our generated code for Chi has historically inverted the order in which Chi middleware is
// applied such that the last invoked middleware ends up executing first in the Chi chain
// This resolves the behavior such that middlewares are chained in the order they are invoked.
Expand Down
2 changes: 1 addition & 1 deletion pkg/codegen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (e *EnumDefinition) GetValues() map[string]string {
// If we do have conflicts, we will prefix the enum's typename to the values.
newValues := make(map[string]string, len(e.Schema.EnumValues))
for k, v := range e.Schema.EnumValues {
newName := e.TypeName + UppercaseFirstCharacter(k)
newName := e.TypeName + globalState.options.Compatibility.EnumPrefixSeparator + UppercaseFirstCharacter(k)
newValues[newName] = v
}
return newValues
Expand Down