Skip to content

Commit

Permalink
Fix for underscore field names fo ToGo/ToGoPrivate
Browse files Browse the repository at this point in the history
  • Loading branch information
vapopov committed Dec 27, 2021
1 parent 27a2b21 commit 06a5a56
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions codegen/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,12 @@ func ToGo(name string) string {
if name == "_" {
return "_"
}

runes := make([]rune, 0, len(name))
for strings.HasPrefix(name, "_") {
name = name[1:]
runes = append(runes, '_')
}

wordWalker(name, func(info *wordInfo) {
word := info.Word
Expand All @@ -312,7 +317,12 @@ func ToGoPrivate(name string) string {
if name == "_" {
return "_"
}

runes := make([]rune, 0, len(name))
for strings.HasPrefix(name, "_") {
name = name[1:]
runes = append(runes, '_')
}

first := true
wordWalker(name, func(info *wordInfo) {
Expand Down
2 changes: 1 addition & 1 deletion codegen/templates/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestToGo(t *testing.T) {
require.Equal(t, "ToCamel", ToGo("ToCamel"))
require.Equal(t, "ToCamel", ToGo("to-camel"))
require.Equal(t, "ToCamel", ToGo("-to-camel"))
require.Equal(t, "ToCamel", ToGo("_to-camel"))
require.Equal(t, "_ToCamel", ToGo("_to-camel"))
require.Equal(t, "_", ToGo("_"))

require.Equal(t, "RelatedURLs", ToGo("RelatedURLs"))
Expand Down

0 comments on commit 06a5a56

Please sign in to comment.