Reputation: 109
I am learning fastify and I learned about validation schema. If I go to the fastify docs validation I saw this:
Treat the schema definition as application code. Validation and serialization features dynamically evaluate code with new Function(), which is not safe to use with user-provided schemas. See Ajv and fast-json-stringify for more details.
Moreover, the $async Ajv feature should not be used as part of the first validation strategy. This option is used to access Databases and reading them during the validation process may lead to Denial of Service Attacks to your application. If you need to run async tasks, use Fastify's hooks instead after validation completes, such as preHandler.
So which should I use now ajv or fast-json-stringify and how can I use it in my schema ?
I learned this:
schema: {
response: {
200: {
type: 'array',
items: {
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'number' }
}
}
}
}
}
and this too
fastify.addSchema({
$id: "createUseSchema",
type: "object",
required: ["name"],
properties: {
name: {
type: "string",
},
},
});
but which libary should I use for secure and fast json ?
Upvotes: 0
Views: 155
Reputation: 21
Kryo: Spring supports fast serialisation https://docs.mulesoft.com/mule-runtime/3.9/improving-performance-with-the-kryo-serializer
Upvotes: 0