diff --git a/internal/codegen/golang/field.go b/internal/codegen/golang/field.go index 2a63b6d342..58b602cd71 100644 --- a/internal/codegen/golang/field.go +++ b/internal/codegen/golang/field.go @@ -69,7 +69,7 @@ func SetJSONCaseStyle(name string, style string, idUppercase bool) string { case "camel": return toJsonCamelCase(name, idUppercase) case "pascal": - return toPascalCase(name) + return toJsonPascalCase(name, idUppercase) case "snake": return toSnakeCase(name) default: @@ -95,6 +95,9 @@ func toCamelCase(s string) string { func toPascalCase(s string) string { return toCamelInitCase(s, true) } +func toJsonPascalCase(s string, idUppercase bool) string { + return toJsonCamelInitCase(s, true, idUppercase) +} func toCamelInitCase(name string, initUpper bool) string { out := "" @@ -113,6 +116,10 @@ func toCamelInitCase(name string, initUpper bool) string { } func toJsonCamelCase(name string, idUppercase bool) string { + return toJsonCamelInitCase(name, false, idUppercase) +} + +func toJsonCamelInitCase(name string, initUpper bool, idUppercase bool) string { out := "" idStr := "Id" @@ -121,7 +128,7 @@ func toJsonCamelCase(name string, idUppercase bool) string { } for i, p := range strings.Split(name, "_") { - if i == 0 { + if !initUpper && i == 0 { out += p continue } diff --git a/internal/endtoend/testdata/json_tags_null_enum/pascal_case/postgresql/stdlib/go/models.go b/internal/endtoend/testdata/json_tags_null_enum/pascal_case/postgresql/stdlib/go/models.go index 2d29fbd42b..5826f20cec 100644 --- a/internal/endtoend/testdata/json_tags_null_enum/pascal_case/postgresql/stdlib/go/models.go +++ b/internal/endtoend/testdata/json_tags_null_enum/pascal_case/postgresql/stdlib/go/models.go @@ -54,7 +54,7 @@ func (ns NullJobPostLocationType) Value() (driver.Value, error) { } type Author struct { - ID int64 `json:"ID"` + ID int64 `json:"Id"` Type NullJobPostLocationType `json:"Type"` Name string `json:"Name"` Bio sql.NullString `json:"Bio"`