Body schema validation
See original GitHub issueHi!
Thanks for the amazing project, it’s helping me a lot!
I’m having an issue on controllers when I try to insert schema validation, like this:
@POST('/', { schema })
public async create(
request: FastifyRequest<{ Body: CreateTransactionSchema }>,
response: FastifyReply,
): Promise<FastifyReply> {
...
And I have a schema like this:
export const schema = {
schema: {
body: {
type: 'object',
requiredKeys: ['title', 'value', 'category', 'realized_date'],
properties: {
title: { type: 'string' },
value: { type: 'number' },
category: { type: 'string' },
realized_date: { type: 'string' },
},
},
},
};
When I try to run this method on postman, for example, it simply bypass my schema validation.
Do you have any suggestion what I have to do to handle schema validation on the body of requests?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Using a JSON schema to validate a response body - Learnetto
The validate() method compiles the JSON schema with Ajv, and then returns a middleware function which will be run every time a request...
Read more >JSON Schema Validator - Newtonsoft
View source code. An online, interactive JSON Schema validator. Supports JSON Schema Draft 3, Draft 4, Draft 6, Draft 7 and Draft 2019-09....
Read more >Schema Validation - express-validator
Schemas are a special, object-based way of defining validations or sanitizations on requests. At the root-level, you specify field paths as keys, ...
Read more >JSON Schema | The home of JSON Schema
JSON Schema is a declarative language that allows you to annotate and validate JSON documents. JSON Schema enables the confident and reliable use...
Read more >Schema Validation - API Shield - Cloudflare Docs
Schema Validation allows you to check if incoming traffic complies with a previously supplied API schema. When you provide an API schema, API ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks @L2jLiga and @unematiii!
Both changes worked for me. But following fastify’s docs, the wright config for
avjis:With this on configs and
requiredset on schema, ererything worked perfectly for me. 😄 Thanks again!Shouldn’t it be
requiredinstead ofrequiredKeys? See docs