Skip to content

Commit

Permalink
chore: statically extract .proto from Go source
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas committed Oct 3, 2024
1 parent ede3a5a commit 5c8e41f
Show file tree
Hide file tree
Showing 59 changed files with 2,107 additions and 1,692 deletions.
2 changes: 1 addition & 1 deletion .go-arch-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ components:
frontend: { in: frontend/console/** }
ftl-gen-lsp-cmd: { in: cmd/ftl-gen-lsp/** }
ftl-initdb-cmd: { in: cmd/ftl-initdb/** }
ftl-schema-cmd: { in: cmd/ftl-schema/** }
go2proto: { in: cmd/go2proto/** }
lint-commit-or-rollback-cmd: { in: cmd/lint-commit-or-rollback/** }
databasetesting: { in: backend/controller/sql/databasetesting/** }
sql: { in: backend/controller/sql/** }
Expand Down
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ linters-settings:
# ignorePackageGlobs:
# - github.com/TBD54566975/ftl/*
spancheck:

extra-start-span-signatures:
- "github.com/TBD54566975/ftl/backend/controller/observability.BeginSpan:opentelemetry"
issues:
Expand Down
4 changes: 2 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ pnpm-install:

# Regenerate protos
build-protos: pnpm-install
@mk {{SCHEMA_OUT}} : internal/schema -- "ftl-schema > {{SCHEMA_OUT}} && buf format -w && buf lint"
@mk {{SCHEMA_OUT}} : internal/schema -- "go2proto -o "{{SCHEMA_OUT}}" -g 'github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema;schemapb' xyz.block.ftl.v1.schema ./internal/schema.Schema && buf format -w && buf lint"
@mk {{PROTOS_OUT}} : {{PROTOS_IN}} -- "cd backend/protos && buf generate"

# Unconditionally rebuild protos
build-protos-unconditionally: pnpm-install
ftl-schema > {{SCHEMA_OUT}} && buf format -w && buf lint
go2proto -o "{{SCHEMA_OUT}}" -g 'github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema;schemapb' xyz.block.ftl.v1.schema ./internal/schema.Schema && buf format -w && buf lint
cd backend/protos && buf generate

# Run integration test(s)
Expand Down
4 changes: 2 additions & 2 deletions backend/controller/ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestValidation(t *testing.T) {
{name: "IntAlias",
schema: `module test {
typealias IntAlias Int
data Test { intValue test.IntAlias }
data Test { intValue test.IntAlias }
}`,
request: obj{"intValue": 10.0},
},
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestResponseBodyForVerb(t *testing.T) {
&schema.Data{
Name: "Test",
Fields: []*schema.Field{
{Name: "message", Type: &schema.String{}, Metadata: []schema.Metadata{&schema.MetadataAlias{Kind: schema.AliasKindJSON, Alias: "msg"}}},
{Name: "message", Type: &schema.String{}, Metadata: []schema.Metadata{&schema.MetadataAlias{Kind: schema.AliasKindJson, Alias: "msg"}}},
},
},
jsonVerb,
Expand Down
2 changes: 1 addition & 1 deletion backend/controller/ingress/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func parseQueryParams(values url.Values, data *schema.Data) (map[string]any, err

var field *schema.Field
for _, f := range data.Fields {
if jsonAlias, ok := f.Alias(schema.AliasKindJSON).Get(); (ok && jsonAlias == key) || f.Name == key {
if jsonAlias, ok := f.Alias(schema.AliasKindJson).Get(); (ok && jsonAlias == key) || f.Name == key {
field = f
}
for _, typeParam := range data.TypeParameters {
Expand Down
2 changes: 1 addition & 1 deletion backend/controller/ingress/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func bodyForType(typ schema.Type, sch *schema.Schema, data []byte) ([]byte, erro
}

err = schema.TransformAliasedFields(sch, t, response, func(obj map[string]any, field *schema.Field) string {
if jsonAlias, ok := field.Alias(schema.AliasKindJSON).Get(); ok && field.Name != jsonAlias {
if jsonAlias, ok := field.Alias(schema.AliasKindJson).Get(); ok && field.Name != jsonAlias {
obj[jsonAlias] = obj[field.Name]
delete(obj, field.Name)
return jsonAlias
Expand Down
Loading

0 comments on commit 5c8e41f

Please sign in to comment.