Skip to content

Commit

Permalink
fix: verb call order (#2940)
Browse files Browse the repository at this point in the history
we can't sort this way because the generated resource providers need to
match the param ordering to ensure they pass the correct resources in
place. will have to think of another solution to stable sort here
  • Loading branch information
worstell authored Oct 1, 2024
1 parent 0b7e64d commit 23842d7
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 80 deletions.
2 changes: 1 addition & 1 deletion go-runtime/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func TestExtractModuleSchemaTwo(t *testing.T) {
+calls two.two
export verb callsTwoAndThree(two.Payload<String>) two.Payload<String>
+calls two.three, two.two
+calls two.two, two.three
export verb ingress(builtin.HttpRequest<two.PostRequest, Unit, Unit>) builtin.HttpResponse<two.PostResponse, String>
+ingress http POST /users
Expand Down
11 changes: 5 additions & 6 deletions go-runtime/schema/testdata/named/types.ftl.go

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

1 change: 0 additions & 1 deletion go-runtime/schema/testdata/namedext/types.ftl.go

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

28 changes: 13 additions & 15 deletions go-runtime/schema/testdata/one/types.ftl.go

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

14 changes: 6 additions & 8 deletions go-runtime/schema/testdata/parent/types.ftl.go

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

15 changes: 7 additions & 8 deletions go-runtime/schema/testdata/pubsub/types.ftl.go

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

12 changes: 5 additions & 7 deletions go-runtime/schema/testdata/subscriber/types.ftl.go

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

36 changes: 17 additions & 19 deletions go-runtime/schema/testdata/two/types.ftl.go

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

16 changes: 1 addition & 15 deletions go-runtime/schema/verb/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package verb
import (
"go/ast"
"go/types"
"slices"
"strings"
"unicode"

Expand Down Expand Up @@ -94,7 +93,7 @@ func Extract(pass *analysis.Pass, node *ast.FuncDecl, obj types.Object) optional
}
verb.Request = reqV
verb.Response = resV
sortMetadata(verb)

return optional.Some(verb)
}

Expand Down Expand Up @@ -172,16 +171,3 @@ func getResourceRef(paramObj types.Object, pass *analysis.Pass, param *ast.Field
}
return dbRef
}

func sortMetadata(verb *schema.Verb) {
for _, md := range verb.Metadata {
if calls, ok := md.(*schema.MetadataCalls); ok {
slices.SortFunc(calls.Calls, func(i, j *schema.Ref) int {
if i.Module != j.Module {
return strings.Compare(i.Module, j.Module)
}
return strings.Compare(i.Name, j.Name)
})
}
}
}

0 comments on commit 23842d7

Please sign in to comment.