-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle rendering of URL Query Parameters in renderURL #11
Handle rendering of URL Query Parameters in renderURL #11
Conversation
9d41bd3
to
35f5a45
Compare
54cae23
to
d5f9d1e
Compare
What I finally ended up doing was:
It returns an empty string if there are no URL query parameters to be rendered. I have also written a small integration test to check if the query parameters are being rendered and passed properly. Looking forward to your feedback 🙏🏼 P.S. I have added the following to # remove binaries to ensure that binaries present in tools.go are installed
rm -f $GOBIN/protoc-gen-go $GOBIN/protoc-gen-grpc-gateway $GOBIN/protoc-gen-swagger
go install \
github.com/golang/protobuf/protoc-gen-go \
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger |
fd1d843
to
86a3893
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the flattenObject idea, this makes runtime to pickup the fields being set. And not to grow the generated asset size too much.
Suggestions have been made. Looking forward to it.
@lyonlai For example, lets take the following request payload where we filter out key const req = {
a: 10,
postReq: {
b: 11
},
c: [23, 25],
extMsg: {
d: 12
}
}; After flattening and filtering key {
"postReq.b": 11,
c: [23, 25],
"extMsg.d": 12
}; The above flattened request payload needs to be converted like this to use as input in [["postReq.b", 11], ["c", 23], ["c", 25], ["extMsg.d", 12]] However, it becomes complicated to use just Array.map on the filtered and flattened to return an array of type This is the implementation I tried which does not return Object.keys(flattenedRequestPayload)
.filter(key => !urlPathParams.includes(key))
.map(key => {
const value = flattenedRequestPayload[key];
if (Array.isArray(value)) {
return value.map(v => [key, v.toString()]);
}
return [key, value.toString()];
}); Looking forward to your feedback 🙇🏼 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it definitely looks nicer on this pass. there are few changes & cases to cover as per comment. Good job.
ba9ba25
to
f96ecd4
Compare
I have refactored the code according to your suggestions and added a test for checking falsy values as well 🙇🏼 |
850070f
to
a64e415
Compare
Thank you once again for taking your time in reviewing this. I have furthered fixed the code according to your suggestions 🙇🏼 |
a04e142
to
b36cd8e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last two comments. This is looking really good. sorry for missing the fieldsInPath
construction before.
Also when you finished, can you also please rebase to a single commit and push up?
b36cd8e
to
f2e7591
Compare
@@ -42,10 +41,69 @@ Turn Ton logging to stderr. Default to false. | |||
### `loglevel` | |||
Defines the logging levels. Default to info. Valid values are: debug, info, warn, error | |||
|
|||
### Notes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added the notes here. Looking forward to your feedback 🙇🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too long. The note section is supposed to note the things people unexpected to find, and also supposed to be concise. In the http get case, it is about the field value matches the default value won't be presented in url params. and a short example like the following will be enough .
{fieldA: "A", fieldB: "" fieldC:1}
will turned in the /path?filedA=A&fieldC=1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... ok I will try my best to make it more concise. Thank you for the feedback 🙏🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. I have simplified the notes section 🙇🏼
abd5e54
to
50b588a
Compare
@@ -42,10 +41,69 @@ Turn Ton logging to stderr. Default to false. | |||
### `loglevel` | |||
Defines the logging levels. Default to info. Valid values are: debug, info, warn, error | |||
|
|||
### Notes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too long. The note section is supposed to note the things people unexpected to find, and also supposed to be concise. In the http get case, it is about the field value matches the default value won't be presented in url params. and a short example like the following will be enough .
{fieldA: "A", fieldB: "" fieldC:1}
will turned in the /path?filedA=A&fieldC=1
README.md
Outdated
### Notes: | ||
This library generates URL Search Parameters (if required) at runtime for RPCs annotated as GET requests. For example, given the following proto definition | ||
|
||
```proto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protos in the integration test already covers this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So maybe we can point out in the notes to look for the integration test example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so. just point a link to the integration test service.proto will do the work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. Thanks for the feedback 🙇🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completed 🙏🏼
@@ -57,6 +57,32 @@ message HttpDeleteRequest { | |||
int32 a = 1; | |||
} | |||
|
|||
message HTTPGetWithURLSearchParamsRequest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be good to have the url example here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok, you mean the URL example from the notes section in the README?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a url example will be ok. no need to move the whole thing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand, just a simple request and response message and a simple RPC implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have modified the tests with the URL example. Please let me know if this good or if I have missed something 🙇🏼
db26415
to
2994137
Compare
2994137
to
2c992f8
Compare
Also rebased to a single commit 🙇🏼 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the contribution @atreya2011
@lyonlai |
Resolves #9
TODO: