[Bug]: API Aggregation cookbook examples not work for me.
grootpiano opened this issue ยท 2 comments
Describe the bug
Hi there, I have some trouble when walking through our API Aggregation cookbook. Need HELP! ๐
There's two kind of problems:
Problem 1
In scenario 1 and 2, when using example specs, I got this error:
2023-01-28T13:37:57.542+08:00 WARN builder/responsebuilder.go:131 ResponseBuilder(buildResponse): failed to build response info: yaml: line 1: did not find expected key
2023-01-28T13:37:57.542+08:00 ERROR httpserver/mux.go:225 server-demo: response is nil
And I found that, in line pkg/filters/builder/builder.go:65
, the result which should be unmarshaled was an invalid YAML data:
statusCode: 200
body: "[{"mega":"ease"}, {"hello":"world"}, {"hello":"new world"}]"
----------^
After changing the ResponseBuilder template like this:
diff --git a/doc/cookbook/api-aggregation.md b/doc/cookbook/api-aggregation.md
index 4107e7c0..e980c73a 100644
--- a/doc/cookbook/api-aggregation.md
+++ b/doc/cookbook/api-aggregation.md
@@ -68,7 +68,8 @@ filters:
kind: ResponseBuilder
template: |
statusCode: 200
- body: "[{{.responses.demo1.Body}}, {{.responses.demo2.Body}}, {{.responses.demo3.Body}}]"
+ body: |
+ [{{.responses.demo1.Body}}, {{.responses.demo2.Body}}, {{.responses.demo3.Body}}]
@@ -147,7 +148,8 @@ filters:
kind: ResponseBuilder
template: |
statusCode: 200
- body: "{{mergeObject .responses.demo1.JSONBody .responses.demo2.JSONBody .responses.demo3.JSONBody | toRawJson}}"
+ body: |
+ {{mergeObject .responses.demo1.JSONBody .responses.demo2.JSONBody .responses.demo3.JSONBody | toRawJson}}
then it works.
Problem 2
In scenario 3, when I stopped service demo1
and called the api again. It directly jumped to the END
filter, not calling service demo2
and demo3
.
So, I added a jumpIf
condition:
diff --git a/doc/cookbook/api-aggregation.md b/doc/cookbook/api-aggregation.md
index 4107e7c0..e980c73a 100644
--- a/doc/cookbook/api-aggregation.md
+++ b/doc/cookbook/api-aggregation.md
@@ -181,6 +183,8 @@ flow:
namespace: demo3
- filter: proxy-demo1
namespace: demo1
+ jumpIf:
+ serverError: "proxy-demo2"
- filter: proxy-demo2
namespace: demo2
then I got the expected result.
Version
The latest master branch version.
Additional context
Actually, I'm not sure if the modifications above are needed. Or maybe I forgot to configure something? I don't know. Please help me to figure it out. ๐ฟ
Thanks for contributing ๐!
Thanks @grootpiano for pointing these issues out, and much appreciate if you could submit a PR to fix them.
Thanks @grootpiano for pointing these issues out, and much appreciate if you could submit a PR to fix them.
That's so sure. It's my pleasure! Waiting, the PR is on the way. ๐