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

Feature request: generate enums #428

Open
EduardoLaranjo opened this issue Aug 7, 2024 · 4 comments
Open

Feature request: generate enums #428

EduardoLaranjo opened this issue Aug 7, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@EduardoLaranjo
Copy link

EduardoLaranjo commented Aug 7, 2024

Hi,

I've noticed that the enums are not being generated in the schema. Is it possible to enable the generation of enums?

Thank you

@EduardoLaranjo EduardoLaranjo changed the title Feature request: Generate Enums Feature request: generate enums Aug 7, 2024
@nrwiersma
Copy link
Member

Can you give an example of what you would expect it to generate?

@EduardoLaranjo
Copy link
Author

EduardoLaranjo commented Aug 8, 2024

hi @nrwiersma thanks for prompt reply

So with gogen-avro any schema with an enum is gonna be generated like so:

{
    "name": "status",
    "type": {
        "name": "status",
        "type": "enum",
        "symbols": [
        "undefined",
        "pending",
        "confirmed",
        "failed"
        ]
    }
}
type Status int32

const (
	StatusUndefined Status = 0
	StatusPending   Status = 1
	StatusConfirmed Status = 2
	StatusFailed    Status = 3
)

func (e Status) String() string {
	switch e {
	case StatusUndefined:
		return "undefined"
	case StatusPending:
		return "pending"
	case StatusConfirmed:
		return "confirmed"
	case StatusFailed:
		return "failed"
	}
	return "unknown"
}

The approach taken to generate the enum is not important to me. It could be like the example above or a group of string constants. The important thing is to have access to the values in the generated code without requiring me to search through the Avro schema.

Thanks Eduardo

@nrwiersma nrwiersma added the enhancement New feature or request label Aug 8, 2024
@EduardoLaranjo
Copy link
Author

EduardoLaranjo commented Aug 22, 2024

hi @nrwiersma

I'm happy to-do this work if it's ok

I just need some guidelines for what do we want

@nrwiersma
Copy link
Member

Hey. You are welcome to take a crack at it. Your proposed typed enum is good with me, but you need to consider that using the name directly is likely to cause conflicts, so making it unique is going to be the challenge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants