Closed mstimvol closed 5 months ago
4.25.2
8.14.0
18.12.1
Windows
Windows 11
I've a get request that sends a comma separated list of ids to fastify. But when I send more than one id, I'm getting the following error:
{ "statusCode": 400, "code": "FST_ERR_VALIDATION", "error": "Bad Request", "message": "querystring/ids/0 must be number" }
That's the request that causes the error: GET http://localhost:8888/test?ids=201,202
GET http://localhost:8888/test?ids=201,202
const fastify = Fastify({ logger: true, ajv: { plugins: [ function (ajv) { ajv.addKeyword({ keyword: 'style' }) ajv.addKeyword({ keyword: 'explode' }) } ] } }) await fastify.register(FastifySwagger, { openapi: { info: { title: 'MyAPI', version: '0.1.0' }, host: 'https://host.tld', schemes: ['http', 'https'], consumes: ['application/json'], produces: ['application/json'] } }) fastify.get('/test', { schema: { querystring: { type: 'object', additionalProperties: false, properties: { ids: { type: 'array', description: 'List of ids to return', uniqueItems: true, items: { type: 'number', format: 'int64', exclusiveMinimum: 200 } }, explode: false } } } }, (req) => { // do something console.log(req.query) return '' }) await fastify.listen({ host: 'localhost', port: 8888 })
My expected behavior is that req.query.ids is an array that contains the ids, e.g. [201, 202, 203].
req.query.ids
[201, 202, 203]
Without deeper checking, i think you also need to set an appropriate querystring parser which can handle that format. The native querystring parser is afaik not able to handle that exploded format.
Prerequisites
Fastify version
4.25.2
Plugin version
8.14.0
Node.js version
18.12.1
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
Windows 11
Description
I've a get request that sends a comma separated list of ids to fastify. But when I send more than one id, I'm getting the following error:
That's the request that causes the error:
GET http://localhost:8888/test?ids=201,202
Steps to Reproduce
Expected Behavior
My expected behavior is that
req.query.ids
is an array that contains the ids, e.g.[201, 202, 203]
.