What does the example of query string validation look in the Fastify documentation? Like this:
const schema = {
querystring: {
name: { type: 'string' },
excitement: { type: 'integer' }
}
}
What is the problem? It is a lie!
The correct way of defining the schema of query parameters in this case (two values: “name” and “excitement”). Looks like this:
const querySchema = {
schema: {
querystring: {
type: 'object',
properties: {
name: {
type: 'string'
},
excitement: {
type: 'integer'
},
}
}
}
}
Additionally, if we want to make the name parameter mandatory, we add it to the array of required parameters:
const querySchema = {
schema: {
querystring: {
type: 'object',
properties: {
name: {
type: 'string'
},
excitement: {
type: 'integer'
},
}
required: ['name']
}
}
}