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

Amino: User lower snake case for Protobuf field names #1211

Open
jefft0 opened this issue Oct 9, 2023 · 1 comment
Open

Amino: User lower snake case for Protobuf field names #1211

jefft0 opened this issue Oct 9, 2023 · 1 comment

Comments

@jefft0
Copy link
Contributor

jefft0 commented Oct 9, 2023

The official Protobuf guide is pretty clear that field names should be lower snake case. But Amino currently outputs the existing Go struct field names which are not snake case. For us, this results in many Protobuf linter warnings like:

Field name "PackagePath" should be lower_snake_case, such as "package_path".

Having so many linter warnings makes it difficult to find important warnings that we need to fix. Therefore, it is desirable for Amino to be able to use lower snake case for field names.

For option 1 below, the Amino code to output the Protobuf field name can be changed from:

		Name:     field.Name,

to

		Name:     ToLowerSnakeCase(field.Name),

where we can borrow ToLowerSnakeCase from the official buf code.

If you agree that it is desirable for Amino to be able to output lower snake case, there are a few options:

  1. Change Amino to always use ToLowerSnakeCase(field.Name) as shown above. (Easiest for devs.)
  2. Add an option to genproto.WriteProto3Schema to optionally output lower snake case. (Allows backwards compatibility, if that is important.)
  3. Amino already extracts the JSON string from Go code like PackagePath string `json:"package_path"` We could make Amino extract a proto string and use it if it is present, like PackagePath string `json:"package_path" proto:"package_path"` (Uses existing mechanisms. Backwards compatible. But lots of work for the dev writing the Go struct.)

Any of these solutions is a trivial amount of code. We could do a quick pull request. What do you think?

@moul
Copy link
Member

moul commented Oct 9, 2023

SGTM.

Amino should remain simple when the protobuf generator is not being used.

Therefore, it's advisable to make the protobuf generator as compliant as possible for the official version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🌟 Wanted for Launch
Development

No branches or pull requests

2 participants