diff --git a/codegen/templates/templates.go b/codegen/templates/templates.go index 0ea3c8725e6..6f5324e3f21 100644 --- a/codegen/templates/templates.go +++ b/codegen/templates/templates.go @@ -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 @@ -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) { diff --git a/codegen/templates/templates_test.go b/codegen/templates/templates_test.go index e77930d85c7..08ad78e4c19 100644 --- a/codegen/templates/templates_test.go +++ b/codegen/templates/templates_test.go @@ -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"))