-
-
Notifications
You must be signed in to change notification settings - Fork 317
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
Fix array query string parsing #5268
Conversation
// defaults to 20 but Beacon API spec allows max items of 30 | ||
arrayLimit: 30, | ||
// array as comma-separated values must be supported to be OpenAPI spec compliant | ||
comma: true, |
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.
koa openapi req/res validator uses this library as well and sets comma: true
, this is required to be OpenAPI spec compliant, see Parameter Serialization
@@ -43,7 +43,15 @@ export class RestApiServer { | |||
const server = fastify({ | |||
logger: false, | |||
ajv: {customOptions: {coerceTypes: "array"}}, | |||
querystringParser: querystring.parse, | |||
querystringParser: (str) => | |||
qs.parse(str, { |
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.
querystringParser: (str) => | ||
qs.parse(str, { | ||
// defaults to 20 but Beacon API spec allows max items of 30 | ||
arrayLimit: 30, |
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.
Beacon API spec defines 30
as maxItems
for some values, e.g. getStateValidators
- id
query, see spec value
Performance Report✔️ no performance regression detected Full benchmark results
|
a198b7e
to
a9641a9
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.
The changes seems ok as it does not show up any regression. I tried to identify what are the changes in the minor release update but seems their repo does not document it well.
@nazarhussain they document their changes in changelog file, see CHANGELOG.md |
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.
looks good to me. The reason we didn't catch this issue in unit tests is because we always use our client api there.
probably we should also create unit tests with curl
@tuyennhv yeah, I looked into adding a test for this but there was no quick way to do it. I think for general cases such as this we just need to improve our spec compliance tests |
🎉 This PR is included in v1.6.0 🎉 |
🎉 This PR is included in v1.7.0 🎉 |
Motivation
The query string parser we use at the moment does not support an array as comma-separated values and on top of that the package itself is deprecated and last release was 2 years ago, querystring node API is considered legacy as well and does not support all parsing requirements we need.
The following request it not correctly parsed at the moment, it result in just one value
curl 'http://localhost:9596/eth/v1/beacon/states/head/validators?id=0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b,0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c'
To be OpenAPI spec compliant we need to support this query string format, all other 4 CLs support this format as well.
The issue was reported by jcrtp from rocketpool, see discord thread.
Description
Updates fastify querystringParser to use qs instead of querystring.
qs
seems to be really popular and is actively maintained. The code looks clean as well and has a good test suite.We also already use
qs
package in several other places (e.g. here) in the monorepo.