Skip to content

Commit

Permalink
explicitlly define name normalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
rucciva committed Aug 27, 2024
1 parent 10e7bb2 commit 75e4674
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions internal/proxy/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ import (

const prefixUpstream = "upstream-"

var codegenNameNormalizerFunctionName = codegen.NameNormalizerFunctionUnset
var codegenNameNormalizerFunction = codegen.NameNormalizers[codegenNameNormalizerFunctionName]

func addTemplateFunc(pe ProxyExtension) {
codegen.TemplateFunctions["upstreamOperationID"] = func(opid string) string {
for k, v := range pe.Proxied() {
if opid != codegen.ToCamelCase(k.OperationId) {
if opid != codegenNameNormalizerFunction(k.OperationId) {
continue
}

Expand All @@ -36,7 +39,7 @@ func addTemplateFunc(pe ProxyExtension) {
}
codegen.TemplateFunctions["upstream"] = func(opid string) string {
for k, v := range pe.Proxied() {
if opid != codegen.ToCamelCase(k.OperationId) {
if opid != codegenNameNormalizerFunction(k.OperationId) {
continue
}
return codegen.ToCamelCase(v.GetName())
Expand All @@ -45,7 +48,7 @@ func addTemplateFunc(pe ProxyExtension) {
}
codegen.TemplateFunctions["upstreams"] = func() (a []string) {
for _, p := range pe.Upstream() {
a = append(a, codegen.ToCamelCase(p.GetName()))
a = append(a, codegenNameNormalizerFunction(p.GetName()))
}
return
}
Expand Down Expand Up @@ -122,8 +125,9 @@ func Generate(ctx context.Context, specPath string, opts GenerateOptions) (bytes
Models: true,
},
OutputOptions: codegen.OutputOptions{
UserTemplates: t,
SkipFmt: true,
UserTemplates: t,
SkipFmt: true,
NameNormalizer: string(codegenNameNormalizerFunctionName),
},
})
if err != nil {
Expand Down Expand Up @@ -178,8 +182,9 @@ func Generate(ctx context.Context, specPath string, opts GenerateOptions) (bytes
Models: true,
},
OutputOptions: codegen.OutputOptions{
UserTemplates: t,
SkipFmt: true,
UserTemplates: t,
SkipFmt: true,
NameNormalizer: string(codegenNameNormalizerFunctionName),
},
})
if err != nil {
Expand Down

0 comments on commit 75e4674

Please sign in to comment.