Skip to content

Commit

Permalink
Update query parser options (#5280)
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Mar 19, 2023
1 parent 8bc1f69 commit ae4e442
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/api/test/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function getTestServer(): {baseUrl: string; server: FastifyInstance} {

const server = fastify({
ajv: {customOptions: {coerceTypes: "array"}},
querystringParser: (str) => qs.parse(str, {comma: true}),
querystringParser: (str) => qs.parse(str, {comma: true, parseArrays: false}),
});

server.addHook("onError", (request, reply, error, done) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/beacon-node/src/api/rest/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export class RestApiServer {
ajv: {customOptions: {coerceTypes: "array"}},
querystringParser: (str) =>
qs.parse(str, {
// 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
// Array as comma-separated values must be supported to be OpenAPI spec compliant
comma: true,
// default limit of 1000 seems unnecessarily high, let's reduce it a bit
parameterLimit: 100,
// Drop support for array query strings like `id[0]=1&id[1]=2&id[2]=3` as those are not required to
// be OpenAPI spec compliant and results are inconsistent, see https://github.com/ljharb/qs/issues/331.
// The schema validation will catch this and throw an error as parsed query string results in an object.
parseArrays: false,
}),
bodyLimit: opts.bodyLimit,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/light-client/test/utils/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function startServer(
const server = fastify({
logger: false,
ajv: {customOptions: {coerceTypes: "array"}},
querystringParser: (str) => qs.parse(str, {comma: true}),
querystringParser: (str) => qs.parse(str, {comma: true, parseArrays: false}),
});

registerRoutes(server, config, api, ["lightclient", "proof", "events"]);
Expand Down

0 comments on commit ae4e442

Please sign in to comment.