Skip to content
This repository was archived by the owner on Aug 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 5 additions & 11 deletions common/schema/metadataingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package schema
import (
"fmt"
"strings"

"github.com/block/ftl/common/slices"
)

//protobuf:2
Expand All @@ -11,7 +13,7 @@ type MetadataIngress struct {

Type string `parser:"'+' 'ingress' @('http')?" protobuf:"2"`
Method string `parser:"@('GET' | 'POST' | 'PUT' | 'DELETE')" protobuf:"3"`
Path []IngressPathComponent `parser:"('/' @@)+" protobuf:"4"`
Path []IngressPathComponent `parser:"'/' (@@ ('/' @@)*)?" protobuf:"4"`
}

var _ Metadata = (*MetadataIngress)(nil)
Expand All @@ -25,15 +27,7 @@ func (m *MetadataIngress) String() string {
//
// For example, /foo/{bar}
func (m *MetadataIngress) PathString() string {
path := make([]string, len(m.Path))
for i, p := range m.Path {
switch v := p.(type) {
case *IngressPathLiteral:
path[i] = v.Text
case *IngressPathParameter:
path[i] = fmt.Sprintf("{%s}", v.Name)
}
}
path := slices.Map(m.Path, func(c IngressPathComponent) string { return c.String() })
return "/" + strings.Join(path, "/")
}

Expand Down Expand Up @@ -76,6 +70,6 @@ type IngressPathParameter struct {
var _ IngressPathComponent = (*IngressPathParameter)(nil)

func (l *IngressPathParameter) Position() Position { return l.Pos }
func (l *IngressPathParameter) String() string { return l.Name }
func (l *IngressPathParameter) String() string { return "{" + l.Name + "}" }
func (*IngressPathParameter) schemaChildren() []Node { return nil }
func (*IngressPathParameter) schemaIngressPathComponent() {}
42 changes: 41 additions & 1 deletion common/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,46 @@ func TestParsing(t *testing.T) {
errors []string
expected *Schema
}{
{name: "IngressRoot",
input: `
realm test {
module test {
export verb index(builtin.HttpRequest<Unit, Unit, Unit>) builtin.HttpResponse<Unit, String>
+ingress http GET /
}
}
`,
expected: &Schema{
Realms: []*Realm{{
Name: "test",
Modules: []*Module{{
Name: "test",
Decls: []Decl{
&Verb{
Visibility: VisibilityScopeModule,
Name: "index",
Request: &Ref{
Module: "builtin",
Name: "HttpRequest",
TypeParameters: []Type{&Unit{}, &Unit{}, &Unit{}},
},
Response: &Ref{
Module: "builtin",
Name: "HttpResponse",
TypeParameters: []Type{&Unit{}, &String{}},
},
Metadata: []Metadata{
&MetadataIngress{
Type: "http",
Method: "GET",
},
},
},
},
}},
}},
},
},
{name: "Empty Realm",
input: `realm foo { }`,
expected: &Schema{Realms: []*Realm{{Name: "foo"}}},
Expand Down Expand Up @@ -843,7 +883,7 @@ realm foo {
} else {
assert.NoError(t, err)
actual = Normalise(actual)
assert.NotZero(t, test.expected, "test.expected is nil")
assert.NotZero(t, test.expected, "test.expected is nil but should contain a schema")
test.expected.Realms[0].Modules = append([]*Module{Builtins()}, test.expected.Realms[0].Modules...)
assert.Equal(t, Normalise(test.expected), Normalise(actual), assert.OmitEmpty(), assert.Exclude[Position]())
}
Expand Down
Loading