Background
I'm building an API with Fastify and it's my first time using JSON schema validation. The idea is that it will both make the server code more efficient and help our developers as they learn how to consume my API.
Problem
I'm trying to validate a route that allows the client to query kittens by name only. A successful formed query would look /kittens?name=fluffykins
.
My schema for this route looks like this:
{
querystring: {
type: 'object',
name: { type: 'string' },
}
}
Question
How can I make my schema validator accept only queries on name
and reject other queries like /kittens?age=1
? My preference is for the schema validator to handle it independently of my controller code and for it to also support queries that we may add in the future.
Thanks!