Skip to content

Commit

Permalink
Use caseconv.UpperFirst instead of strings.Title
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellLuo committed Oct 17, 2022
1 parent 972e03d commit cc99725
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gen/endpoint/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (g *Generator) Generate(pkgInfo *generator.PkgInfo, ifaceData *ifacetool.Da

return generator.Generate(template, data, generator.Options{
Funcs: map[string]interface{}{
"title": strings.Title,
"title": caseconv.UpperFirst,
"nonCtxParams": func(params []*ifacetool.Param, reqParams []*openapi.Param) (out []ParamWithAlias) {
nameToAlias := make(map[string]string)
for _, p := range reqParams {
Expand Down
3 changes: 1 addition & 2 deletions gen/event/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package generator

import (
"fmt"
"strings"

"github.com/RussellLuo/kun/gen/event/parser"
utilannotation "github.com/RussellLuo/kun/gen/util/annotation"
Expand Down Expand Up @@ -172,7 +171,7 @@ func (g *Generator) Generate(pkgInfo *generator.PkgInfo, ifaceData *ifacetool.Da

return generator.Generate(template, data, generator.Options{
Funcs: map[string]interface{}{
"title": strings.Title,
"title": caseconv.UpperFirst,
"lowerFirst": caseconv.LowerFirst,
"addAmpersand": func(name string) string {
if g.opts.SchemaPtr {
Expand Down
5 changes: 2 additions & 3 deletions gen/http/chi/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package chi
import (
"fmt"
"net/http"
"strings"

"github.com/RussellLuo/kun/gen/http/parser/annotation"
utilannotation "github.com/RussellLuo/kun/gen/util/annotation"
Expand Down Expand Up @@ -213,7 +212,7 @@ func (g *Generator) Generate(pkgInfo *generator.PkgInfo, ifaceData *ifacetool.Da

return generator.Generate(template, data, generator.Options{
Funcs: map[string]interface{}{
"title": strings.Title,
"title": caseconv.UpperFirst,
"lowerFirst": caseconv.LowerFirst,
"addAmpersand": func(name string) string {
if g.opts.SchemaPtr {
Expand Down Expand Up @@ -326,7 +325,7 @@ func (g *Generator) Generate(pkgInfo *generator.PkgInfo, ifaceData *ifacetool.Da
if param.IsBlank {
return "nil"
}
return fmt.Sprintf("&%s.%s", reqVar, strings.Title(param.Name))
return fmt.Sprintf("&%s.%s", reqVar, caseconv.UpperFirst(param.Name))
},
},
Formatted: g.opts.Formatted,
Expand Down
9 changes: 5 additions & 4 deletions gen/http/httpclient/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
utilannotation "github.com/RussellLuo/kun/gen/util/annotation"
"github.com/RussellLuo/kun/gen/util/generator"
"github.com/RussellLuo/kun/gen/util/openapi"
"github.com/RussellLuo/kun/pkg/caseconv"
"github.com/RussellLuo/kun/pkg/ifacetool"
)

Expand Down Expand Up @@ -242,7 +243,7 @@ func (g *Generator) Generate(pkgInfo *generator.PkgInfo, ifaceData *ifacetool.Da
var results []string

for _, p := range params {
r := strings.NewReplacer(">Name", strings.Title(p.Name))
r := strings.NewReplacer(">Name", caseconv.UpperFirst(p.Name))
results = append(results, r.Replace(format))
}
return strings.Join(results, sep)
Expand All @@ -258,7 +259,7 @@ func (g *Generator) Generate(pkgInfo *generator.PkgInfo, ifaceData *ifacetool.Da
"getOperation": func(name string) *openapi.Operation {
return operationMap[name]
},
"title": strings.Title,
"title": caseconv.UpperFirst,
"addTag": func(name, typ string) string {
if g.opts.SchemaTag == "" {
return ""
Expand Down Expand Up @@ -389,8 +390,8 @@ func (g *Generator) Generate(pkgInfo *generator.PkgInfo, ifaceData *ifacetool.Da
})
}

//Returns the empty value that should be returned depending on it's type.
//Defaults to returning 'nil' if type can't be found
// Returns the empty value that should be returned depending on it's type.
// Defaults to returning 'nil' if type can't be found
func emptyValue(param *ifacetool.Param) string {
t := param.Type.Underlying()

Expand Down
3 changes: 2 additions & 1 deletion gen/http/oas2/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
utilannotation "github.com/RussellLuo/kun/gen/util/annotation"
"github.com/RussellLuo/kun/gen/util/generator"
"github.com/RussellLuo/kun/gen/util/openapi"
"github.com/RussellLuo/kun/pkg/caseconv"
)

var (
Expand Down Expand Up @@ -183,7 +184,7 @@ func (g *Generator) Generate(pkgInfo *generator.PkgInfo, spec *openapi.Specifica

return generator.Generate(template, data, generator.Options{
Funcs: map[string]interface{}{
"title": strings.Title,
"title": caseconv.UpperFirst,
"lower": strings.ToLower,
"operationsGroupByPattern": func(ops []*openapi.Operation) (outOps []*OperationsPerPattern) {
var opp *OperationsPerPattern
Expand Down
2 changes: 1 addition & 1 deletion pkg/caseconv/caseconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func ToSnakeCase(s string) string {

func ToCamelCase(s string) string {
return matchUnderscore.ReplaceAllStringFunc(s, func(x string) string {
return strings.Title(strings.TrimLeft(x, "_"))
return UpperFirst(strings.TrimLeft(x, "_"))
})
}

Expand Down

0 comments on commit cc99725

Please sign in to comment.