Skip to content

Commit

Permalink
fix(topic): require lowerCamel topic names instead of lower_snake (#2329
Browse files Browse the repository at this point in the history
)

Breaking change, fixes #2328

Original topic name PR is #1958
  • Loading branch information
safeer authored Aug 13, 2024
1 parent 907731e commit a5425b1
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 27 deletions.
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.

4 changes: 2 additions & 2 deletions backend/controller/pubsub/testdata/go/publisher/publisher.go
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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -334,7 +334,7 @@ module test {
database postgres testDb
export topic exported_topic {{.TypeName}}
export topic exportedTopic {{.TypeName}}
topic topic {{.TypeName}}
subscription subscription test.topic
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
2 changes: 1 addition & 1 deletion go-runtime/schema/subscription/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func Extract(pass *analysis.Pass, obj types.Object, node *ast.GenDecl, callExpr
common.Errorf(pass, callExpr, "subscription registration must have a topic")
return optional.None[*schema.Subscription]()
}
name := strcase.ToLowerSnake(varName)
name := strcase.ToLowerCamel(varName)
topicRef = &schema.Ref{
Module: moduleIdent.Name,
Name: name,
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

0 comments on commit a5425b1

Please sign in to comment.