Skip to content

Commit

Permalink
feat: fix broken pkg name
Browse files Browse the repository at this point in the history
  • Loading branch information
masu-mi committed Sep 13, 2022
1 parent 9624af9 commit 6a55f6f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/codegen/template_helpers.go
Expand Up @@ -277,6 +277,7 @@ var TemplateFunctions = template.FuncMap{
"swaggerUriToGorillaUri": SwaggerUriToGorillaUri,
"lcFirst": LowercaseFirstCharacter,
"ucFirst": UppercaseFirstCharacter,
"ucFirstWithPkgName": UppercaseFirstCharacterWithPkgName,
"camelCase": ToCamelCase,
"genResponsePayload": genResponsePayload,
"genResponseTypeName": genResponseTypeName,
Expand Down
2 changes: 1 addition & 1 deletion pkg/codegen/templates/strict/strict-interface.tmpl
Expand Up @@ -25,7 +25,7 @@
{{$hasHeaders := ne 0 (len .Headers) -}}
{{$fixedStatusCode := .HasFixedStatusCode -}}
{{$isRef := .IsRef -}}
{{$ref := .Ref | ucFirst -}}
{{$ref := .Ref | ucFirstWithPkgName -}}
{{$headers := .Headers -}}

{{if (and $hasHeaders (not $isRef)) -}}
Expand Down
18 changes: 18 additions & 0 deletions pkg/codegen/utils.go
Expand Up @@ -43,6 +43,24 @@ func UppercaseFirstCharacter(str string) string {
return string(runes)
}

// Uppercase the first character in a identifier with pkg name. This assumes UTF-8, so we have
// to be careful with unicode, don't treat it as a byte array.
func UppercaseFirstCharacterWithPkgName(str string) string {
if str == "" {
return ""
}

segs := strings.Split(str, ".")
var prefix string
if len(segs) == 2 {
prefix = segs[0] + "."
str = segs[1]
}
runes := []rune(str)
runes[0] = unicode.ToUpper(runes[0])
return prefix + string(runes)
}

// Same as above, except lower case
func LowercaseFirstCharacter(str string) string {
if str == "" {
Expand Down

0 comments on commit 6a55f6f

Please sign in to comment.