Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(topic): require lowerCamel topic names instead of lower_snake #2329

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion backend/controller/cronjobs/sql/db.go

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

2 changes: 1 addition & 1 deletion backend/controller/cronjobs/sql/models.go

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

2 changes: 1 addition & 1 deletion backend/controller/cronjobs/sql/querier.go

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

2 changes: 1 addition & 1 deletion backend/controller/cronjobs/sql/queries.sql.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

//ftl:export
var TestTopic = ftl.Topic[PubSubEvent]("test_topic")
var TestTopic = ftl.Topic[PubSubEvent]("testTopic")

type PubSubEvent struct {
Time time.Time
Expand Down Expand Up @@ -38,7 +38,7 @@ func PublishOne(ctx context.Context) error {
}

//ftl:export
var Topic2 = ftl.Topic[PubSubEvent]("topic_2")
var Topic2 = ftl.Topic[PubSubEvent]("topic2")

//ftl:verb
func PublishOneToTopic2(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion backend/controller/sql/db.go

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

2 changes: 1 addition & 1 deletion backend/controller/sql/models.go

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

2 changes: 1 addition & 1 deletion backend/controller/sql/querier.go

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

2 changes: 1 addition & 1 deletion backend/controller/sql/queries.sql.go

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

2 changes: 1 addition & 1 deletion common/configuration/sql/db.go

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

2 changes: 1 addition & 1 deletion common/configuration/sql/models.go

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

2 changes: 1 addition & 1 deletion common/configuration/sql/querier.go

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

2 changes: 1 addition & 1 deletion common/configuration/sql/queries.sql.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var _ = context.Background
//
{{- end}}
{{- if is "Topic" .}}
var {{.Name|strippedCamel}} = ftl.Topic[{{type $.Module .Event}}]("{{.Name}}")
var {{.Name|title}} = ftl.Topic[{{type $.Module .Event}}]("{{.Name}}")
{{- else if and (is "Enum" .) .IsValueEnum}}
{{- $enumName := .Name}}
//ftl:enum
Expand Down
2 changes: 1 addition & 1 deletion go-runtime/schema/schema_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (ExportedVariant) exportedTag() {}
var Topic = ftl.Topic[` + symbol + `]("topic")

//ftl:export
var ExportedTopic = ftl.Topic[` + symbol + `]("exported_topic")
var ExportedTopic = ftl.Topic[` + symbol + `]("exportedTopic")

var _ = ftl.Subscription(Topic, "subscription")

Expand Down
8 changes: 4 additions & 4 deletions go-runtime/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,10 @@ func TestExtractModulePubSub(t *testing.T) {
actual := schema.Normalise(r.Module)
expected := `module pubsub {
topic payins pubsub.PayinEvent
// public_broadcast is a topic that broadcasts payin events to the public.
// publicBroadcast is a topic that broadcasts payin events to the public.
// out of order with subscription registration to test ordering doesn't matter.
export topic public_broadcast pubsub.PayinEvent
subscription broadcastSubscription pubsub.public_broadcast
export topic publicBroadcast pubsub.PayinEvent
subscription broadcastSubscription pubsub.publicBroadcast
subscription paymentProcessing pubsub.payins

export data PayinEvent {
Expand Down Expand Up @@ -469,7 +469,7 @@ func TestExtractModuleSubscriber(t *testing.T) {
assert.Equal(t, nil, r.Errors, "expected no schema errors")
actual := schema.Normalise(r.Module)
expected := `module subscriber {
subscription subscriptionToExternalTopic pubsub.public_broadcast
subscription subscriptionToExternalTopic pubsub.publicBroadcast

verb consumesSubscriptionFromExternalTopic(pubsub.PayinEvent) Unit
+subscribe subscriptionToExternalTopic
Expand Down
4 changes: 2 additions & 2 deletions go-runtime/schema/testdata/pubsub/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ var Payins = ftl.Topic[PayinEvent]("payins")

var _ = ftl.Subscription(PublicBroadcast, "broadcastSubscription")

// public_broadcast is a topic that broadcasts payin events to the public.
// publicBroadcast is a topic that broadcasts payin events to the public.
// out of order with subscription registration to test ordering doesn't matter.
//
//ftl:export
var PublicBroadcast = ftl.Topic[PayinEvent]("public_broadcast")
var PublicBroadcast = ftl.Topic[PayinEvent]("publicBroadcast")

//ftl:verb export
func Broadcast(ctx context.Context) error {
Expand Down
6 changes: 3 additions & 3 deletions go-runtime/schema/topic/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
// Extractor extracts topics.
var Extractor = common.NewCallDeclExtractor[*schema.Topic]("topic", Extract, ftlTopicFuncPath)

// expects: var NameLiteral = ftl.Topic[EventType]("name_literal")
// Extract expects: var NameLiteral = ftl.Topic[EventType]("nameLiteral")
func Extract(pass *analysis.Pass, obj types.Object, node *ast.GenDecl, callExpr *ast.CallExpr,
callPath string) optional.Option[*schema.Topic] {
indexExpr, ok := callExpr.Fun.(*ast.IndexExpr)
Expand All @@ -34,7 +34,7 @@ func Extract(pass *analysis.Pass, obj types.Object, node *ast.GenDecl, callExpr
}

topicName := common.ExtractStringLiteralArg(pass, callExpr, 0)
expTopicName := strcase.ToLowerSnake(topicName)
expTopicName := strcase.ToLowerCamel(strcase.ToUpperStrippedCamel(topicName))
if topicName != expTopicName {
common.Errorf(pass, node, "unsupported topic name %q, did you mean to use %q?", topicName, expTopicName)
return optional.None[*schema.Topic]()
Expand All @@ -43,7 +43,7 @@ func Extract(pass *analysis.Pass, obj types.Object, node *ast.GenDecl, callExpr
if len(node.Specs) > 0 {
if t, ok := node.Specs[0].(*ast.ValueSpec); ok {
varName := t.Names[0].Name
expVarName := strcase.ToUpperStrippedCamel(topicName)
expVarName := strcase.ToUpperCamel(topicName)
if varName != expVarName {
common.Errorf(pass, node, "unexpected topic variable name %q, did you mean %q?", varName, expVarName)
return optional.None[*schema.Topic]()
Expand Down