Skip to content

Commit

Permalink
fix: don't do a full camel case check against exported verbs (#1791)
Browse files Browse the repository at this point in the history
It forced users to use eg. `GetUserById` rather than `GetUserByID`,
which we currently don't want to do.
  • Loading branch information
alecthomas authored Jun 15, 2024
1 parent e9ffba4 commit 7184849
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions go-runtime/compile/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import (
"unicode"
"unicode/utf8"

"github.com/TBD54566975/ftl/go-runtime/schema/analyzers"
"github.com/alecthomas/types/optional"
"golang.org/x/exp/maps"

"github.com/TBD54566975/ftl/go-runtime/schema/analyzers"

"github.com/TBD54566975/ftl/backend/schema"
"github.com/TBD54566975/ftl/backend/schema/strcase"
"github.com/TBD54566975/ftl/internal/goast"
Expand Down Expand Up @@ -1224,8 +1225,8 @@ func visitFuncDecl(pctx *parseContext, node *ast.FuncDecl) (verb *schema.Verb) {
return nil
}

if expVerbName := strcase.ToUpperCamel(node.Name.Name); node.Name.Name != expVerbName {
pctx.errors.add(errorf(node, "unexpected verb name %q, did you mean to use %q instead?", node.Name.Name, expVerbName))
if expName := exportedName(node.Name.Name); node.Name.Name != expName {
pctx.errors.add(errorf(node, "verb %q is not exported, did you mean to use %q instead?", node.Name.Name, expName))
return nil
}

Expand Down Expand Up @@ -1831,3 +1832,10 @@ func isIotaEnum(node ast.Node) bool {
return false
}
}

func exportedName(name string) string {
if name == "" {
return ""
}
return string(unicode.ToUpper(rune(name[0]))) + name[1:]
}

0 comments on commit 7184849

Please sign in to comment.