Skip to content
Open
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
4 changes: 3 additions & 1 deletion internal/codegen/golang/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func StructName(name string, options *opts.Options) string {
if _, found := options.InitialismsMap[p]; found {
out += strings.ToUpper(p)
} else {
out += strings.Title(p)
if len(p) > 0 {
out += strings.ToUpper(p[:1]) + p[1:]
}
Comment on lines +38 to +40

Choose a reason for hiding this comment

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

There isn't any whitespace in p (see line 31 above), so this code will do the same thing as strings.Title.

Copy link

@em-ily-dev em-ily-dev Dec 4, 2025

Choose a reason for hiding this comment

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

Ah, actually, slicing off the first byte would split up a multi-byte character, and fail to convert it. The existing call to strings.Title will properly uppercase a multi-byte character.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What does it have to do with the existence of whitespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do agree on the problem with multibyte characters though.
We can split the string in runes and convert the first rune in that case? Not sure how uppercasing works with multibyte chars, gotta find out.

Choose a reason for hiding this comment

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

strings.Title already does what we want here. #4202 (comment)

}
}

Expand Down
Loading