Replies: 1 comment
-
I just found that Feathers internally uses Ajv. Should I use Ajv to define all custom type for the application scope or layer? Thank you. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Although it defines the schema but it seems that it can't validate the query parameters completely? (Or I don't how to use it)
The schema against the validation of query parameters can ONLY be used to check whether the field is required or optional, or the Type. It throws errors if the type does not match.
Since client side can pass valid or invalid values, for an positive integer type (Type.Integer() in the schema) via the simple textfield in an online form he can pass
20,
20a (String)
a20, (String)
20.1 (decimal)
-20 (negative)
It supposes that the backend is looking for the String type before the validation. As I don't want to release the default error messages due to the Feathers schema validation. Furthermore, the input can be come from Postman that we can test to pass all kind of types.
As I don't wanna expose the default error messages in the response for production use, what I need to do now is to override the schema in the query part in the .schema.js file generated from the CLI. I need to pick or intersect the original integer fields (from the 1st model schema) and convert it to the string fields. And finally I applied the custom hooks to validate the parameters. For more advanced validation, I also need to do with the Yup library.
The whole thing requires a lot of codes, and the coding seems a bit duplicated, and is not easy to read.
What is the correct ways to do the complete validations of user inputs in Feathers?
The default schema / resolver codes generated from Feathers CLI is not readable and is weak to validate inputs without using other validation libraries.
Thanks so much.
Beta Was this translation helpful? Give feedback.
All reactions