Skip to content
This repository was archived by the owner on Jan 18, 2026. It is now read-only.

feat: add custom initialisms support to gen package and avrogen#303

Merged
nrwiersma merged 4 commits intohamba:mainfrom
hhromic:gen-initialisms
Sep 6, 2023
Merged

feat: add custom initialisms support to gen package and avrogen#303
nrwiersma merged 4 commits intohamba:mainfrom
hhromic:gen-initialisms

Conversation

@hhromic
Copy link
Copy Markdown
Contributor

@hhromic hhromic commented Sep 5, 2023

Hello, this simple PR adds support for custom initialisms to the gen package and avrogen command.

Additional custom initialisms are necessary because strcase.ToGoPascal only uses GoLint's list of initialisms.
Currently, if an initialism in struct/field names is not part of Golint's, then strcase wrongly downcases it.

For example, consider the following schema containing the domain initialism AID:

{
  "type": "record",
  "name": "AIDEventHTTPService",
  "namespace": "example",
  "fields" : [
    {"name": "AIDNumber", "type": "long"},
    {"name": "Desc", "type": "string"}
  ]
}

Currently, avrogen generates the following Go struct (struct/field names: AID -> Aid):

package example

// Code generated by avro/gen. DO NOT EDIT.

// AidEventHTTPService is a generated struct.
type AidEventHTTPService struct {
        AidNumber int64  `avro:"AIDNumber"`
        Desc      string `avro:"Desc"`
}

With this PR, -initialisms AID can be given to avrogen to generate the correct struct/field names:

package example

// Code generated by avro/gen. DO NOT EDIT.

// AIDEventHTTPService is a generated struct.
type AIDEventHTTPService struct {
        AIDNumber int64  `avro:"AIDNumber"`
        Desc      string `avro:"Desc"`
}

There is a related PR in the upstream strcase repository: ettle/strcase#13
That PR allows to preserve any extra initialisms without having to define them in advance, however the maintainers seems to not be merging it any time soon. This PR allows to solve the issue in the mean time.

Copy link
Copy Markdown
Member

@nrwiersma nrwiersma left a comment

Choose a reason for hiding this comment

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

One nitpick about test error assertion, otherwise looks good.

@hhromic
Copy link
Copy Markdown
Contributor Author

hhromic commented Sep 6, 2023

One nitpick about test error assertion, otherwise looks good.

Thanks for the feedback, indeed looks cleaner after your suggestion.

I merged main too into this branch. Thanks for being open to contributions! Appreciated!

Copy link
Copy Markdown
Member

@nrwiersma nrwiersma left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@nrwiersma nrwiersma merged commit ca141fc into hamba:main Sep 6, 2023
@hhromic hhromic deleted the gen-initialisms branch September 6, 2023 16:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants