fastify / fastify/fastify-autoload
Params validation
- Dominant language
- JavaScript
- Stars
- 373
- Forks
- 77
- PR merge metrics
- No merged PRs in 30d
Description
### Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
### Fastify version
^4.0.0
### Plugin version
_No response_
### Node.js version
19
### Operating system
Linux
### Operating system version (i.e. 20.04, 11.3, 10)
20.04
### Description
the required for param validation doesn't work and allow empty strings
### Steps to Reproduce
fastify.get<{
Params: {
model: string;
},
Querystring: {
sort: string;
asc: number;
}
}>('/listAll/:model/', {
schema: {
params: {
type: 'object',
properties: {
model: { type: 'string' },
},
required: ['model'],
},
querystring: {
type: 'object',
properties: {
sort: { type: 'string' },
asc: { type: 'number' },
},
required: ['sort'],
},
},
}, async function (request, reply) {
return 'db endpoint for => ' + request.params.model;
});
i undestand this can be fixed with
params: {
type: 'object',
properties: {
model: { type: 'string' },
minLength: 1,
},
required: ['model'],
},
but i think the required on a string should do it for params
### Current Behavior
CURL /listAll/t?sort=p => this is ok
CURL /listAll/t=> validation works , sort is required
CURL /listAll//?sort=p => get ok 200 , validation doesn't works , and allow the model to be empty
### Expected Behavior
CURL /listAll/t?sort=p => this is ok
CURL /listAll/t=> validation works , sort is required
CURL /listAll//?sort=p => validation works , and doesn't allow the model to be empty
Contributor guide
Assessment
This issue has not been assessed yet.