Skip to content

Commit 1a530e7

Browse files
author
Jan Buijnsters
committed
Fix idUpperCase functionality for the JSON PascalCase
1 parent 014e3f1 commit 1a530e7

File tree

2 files changed

+10
-3
lines changed
  • internal
    • codegen/golang
    • endtoend/testdata/json_tags_null_enum/pascal_case/postgresql/stdlib/go

2 files changed

+10
-3
lines changed

internal/codegen/golang/field.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func SetJSONCaseStyle(name string, style string, idUppercase bool) string {
6969
case "camel":
7070
return toJsonCamelCase(name, idUppercase)
7171
case "pascal":
72-
return toPascalCase(name)
72+
return toJsonPascalCase(name, idUppercase)
7373
case "snake":
7474
return toSnakeCase(name)
7575
default:
@@ -95,6 +95,9 @@ func toCamelCase(s string) string {
9595
func toPascalCase(s string) string {
9696
return toCamelInitCase(s, true)
9797
}
98+
func toJsonPascalCase(s string, idUppercase bool) string {
99+
return toJsonCamelInitCase(s, true, idUppercase)
100+
}
98101

99102
func toCamelInitCase(name string, initUpper bool) string {
100103
out := ""
@@ -113,6 +116,10 @@ func toCamelInitCase(name string, initUpper bool) string {
113116
}
114117

115118
func toJsonCamelCase(name string, idUppercase bool) string {
119+
return toJsonCamelInitCase(name, false, idUppercase)
120+
}
121+
122+
func toJsonCamelInitCase(name string, initUpper bool, idUppercase bool) string {
116123
out := ""
117124
idStr := "Id"
118125

@@ -121,7 +128,7 @@ func toJsonCamelCase(name string, idUppercase bool) string {
121128
}
122129

123130
for i, p := range strings.Split(name, "_") {
124-
if i == 0 {
131+
if !initUpper && i == 0 {
125132
out += p
126133
continue
127134
}

internal/endtoend/testdata/json_tags_null_enum/pascal_case/postgresql/stdlib/go/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)