A simple plugin that enables response validation for Fastify.
$ npm install --save-dev @geut/fastify-response-validation
import fastify from 'fastify'
const app = fastify()
await app.register(import('@geut/fastify-response-validation'))
app.route({
method: 'GET',
path: '/',
schema: {
response: {
'2xx': {
type: 'object',
properties: {
answer: { type: 'string', format: 'date' }
}
}
}
},
handler: async (req, reply) => {
return { answer: 'wrong date' }
}
})
app.inject({
method: 'GET',
path: '/'
}, (err, res) => {
if (err) throw err
// {"statusCode":500,"error":"Internal Server Error","message":"response/answer must match format \"date\""}
console.log(res.payload)
})
🐛 If you found an issue we encourage you to report it on github. Please specify your OS and the actions to reproduce it.
👥 Ideas and contributions to the project are welcome. You must follow this guideline.
MIT © A GEUT project