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

fix enum capitalization #2630

Merged
merged 2 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion codegen/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,25 @@ func wordWalker(str string, f func(*wordInfo)) {
}

matchCommonInitial := false
if commonInitialisms[strings.ToUpper(word)] {
upperWord := strings.ToUpper(word)
if commonInitialisms[upperWord] {
// If the uppercase word (string(runes[w:i]) is "ID" or "IP"
// AND
// the word is the first two characters of the str
// AND
// that is not the end of the word
// AND
// the length of the string is greater than 3
// AND
// the third rune is an uppercase one
// THEN
// do NOT count this as an initialism.
switch upperWord {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
switch upperWord {
// If the uppercase word (string(runes[w:i]) is "ID" or "IP"
// AND
// the word is the first two characters of the str
// AND
// that is not the end of the word
// AND
// the length of the string is greater than 3
// AND
// the third rune is an uppercase one
// THEN
// do NOT count this as an initialism.
switch upperWord {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your suggestion!
I applied it and pushed.

case "ID", "IP":
if word == str[:2] && !eow && len(str) > 3 && unicode.IsUpper(runes[3]) {
continue
}
}
hasCommonInitial = true
matchCommonInitial = true
}
Expand Down
18 changes: 18 additions & 0 deletions codegen/templates/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ func TestToGo(t *testing.T) {
require.Equal(t, "RelatedUrls", ToGo("RelatedUrls"))
require.Equal(t, "ITicket", ToGo("ITicket"))
require.Equal(t, "FooTicket", ToGo("fooTicket"))

require.Equal(t, "Idle", ToGo("IDLE"))
require.Equal(t, "Idle", ToGo("Idle"))
require.Equal(t, "Idle", ToGo("idle"))
require.Equal(t, "Identities", ToGo("IDENTITIES"))
require.Equal(t, "Identities", ToGo("Identities"))
require.Equal(t, "Identities", ToGo("identities"))
require.Equal(t, "Iphone", ToGo("IPHONE"))
require.Equal(t, "IPhone", ToGo("iPHONE"))
}

func TestToGoPrivate(t *testing.T) {
Expand Down Expand Up @@ -73,6 +82,15 @@ func TestToGoPrivate(t *testing.T) {
require.Equal(t, "id", ToGoPrivate("id"))
require.Equal(t, "", ToGoPrivate(""))
require.Equal(t, "_", ToGoPrivate("_"))

require.Equal(t, "idle", ToGoPrivate("IDLE"))
require.Equal(t, "idle", ToGoPrivate("Idle"))
require.Equal(t, "idle", ToGoPrivate("idle"))
require.Equal(t, "identities", ToGoPrivate("IDENTITIES"))
require.Equal(t, "identities", ToGoPrivate("Identities"))
require.Equal(t, "identities", ToGoPrivate("identities"))
require.Equal(t, "iphone", ToGoPrivate("IPHONE"))
require.Equal(t, "iPhone", ToGoPrivate("iPHONE"))
}

func TestToGoModelName(t *testing.T) {
Expand Down