Skip to content

Conversation

@leonhfr
Copy link
Member

@leonhfr leonhfr commented Mar 10, 2025

No description provided.

Copy link

@benjajaja benjajaja left a comment

Choose a reason for hiding this comment

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

I would just like to be able to set the default value, and also the suffix: we use "not_set" or similar in our codebase, but also probably not 100% consistently.

Also in general I would be inclined to call it "default" instead of unknown.

lowercaseLookup bool
caseInsensitive bool
marshal bool
unknownCase bool

Choose a reason for hiding this comment

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

Suggested change
unknownCase bool
unknownCase string
unknownCaseValue string
unknownCaseSuffix string

I would make this as customizable as possible here. Allow setting a default value, and the suffix. For example in re:cap BE, the value is usually NOT_SET.

(We can't just use unknownCase string, in case someone wants to use an empty string as default).

Copy link
Member Author

@leonhfr leonhfr Mar 10, 2025

Choose a reason for hiding this comment

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

I thought about this, but was wondering how to have a different syntax between renaming and setting the default case:

type Gender string

// This renames between type and value:
// ENUM(male, female, unknown=not_set)

// Maybe something like this?
// ENUM(male, female) default=not_set

This is a bit more work because we need to have extra parsing but doable.

What difference do you make between unknownCase and unknownCaseValue? And by suffix you mean the naming of the default type value right?

Copy link

@benjajaja benjajaja Mar 11, 2025

Choose a reason for hiding this comment

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

You could just add it to the CLI args for now.

  • unknownCase:bool -> enable if true
  • unknownCaseValue:*string -> set default value if not nil
  • unknownCaseSuffix:*string -> replace the Unknown suffix if not nil

Actually, the args would have to be *string, as "" would be a valid use case for the value, and unknownCaseSuffix is optional.

I'm not sure if "suffix" is actually needed, what we need (would be great) to make work is our use case that we have elsewhere:

// ENUM(first_item)

// should produce:
const OurEnumFirstItem OutEnum = "first_item"
const OurEnumNotSet OutEnum = "NOT_SET"

mixed upper/lower, and snake_case for the values.

Choose a reason for hiding this comment

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

But anyway don't let me drag this out too much, we can also change this later.

Copy link
Member Author

Choose a reason for hiding this comment

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

The CLI args apply for all enums defined in the file though, so I think if we have customization of the value and suffix, I think we should do it at the enum level 🤔

Copy link

@benjajaja benjajaja Mar 11, 2025

Choose a reason for hiding this comment

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

Right, that way it's more flexible and the //go generate ... trigger can be the same across files 👍

@benjajaja
Copy link

Overall this looks great! Looking forward to using it elsewhere in our codebase.

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.

4 participants