-
-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Params validation #315
Comments
I don't think this could be considered an issue, it seems like an acceptable behaviour to me: empty string is still a string, different from undefined |
I would check here: https://stackoverflow.com/questions/45888524/empty-values-validation-in-json-schema-using-ajv I would not expect that behaviour with that schema since In any case, it is an AJV thing and it is not related to fastify:
Adding this custom logic could be a harmful as it would be not a standard JSON schema anymore - you can implement it on your app using the |
i am not speaking about the validation of the string , i am speaking about the
for a querystring
even without the minlength it's work as the request when we don't set "sort" it's undefined but for params
the required is useless as it is , because it's replaced by the route no matter what we define it and the problem is when we access req.params.model , it's shows as undefined and not an empty string , so why the required is not working |
Can't reproduce
Could you add a Minimal, Reproducible Example? Without it, we are unable to help you. |
interesting the issue is with using the fastify/autoload how to reproduce 1 - install fastify-cli 2 - genereate a new server and run npm install 3 - change the root.js ( or any route point inside routes ) add the exact same code
4 - now this endpoint and if you change route to
using this without using the @fastify/autoload this issue doesn't happen :/ instead you get 404 error so should i move this issue there ? |
It worth investigating on it, I will move the issue 👍🏼 |
@Zack-Heisnberg could you check if fastify/fastify#4903 solved? |
Prerequisites
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
i undestand this can be fixed with
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
The text was updated successfully, but these errors were encountered: