Skip to content

Latest commit

 

History

History
66 lines (49 loc) · 3.4 KB

README.md

File metadata and controls

66 lines (49 loc) · 3.4 KB

fastify-response-validation

A simple plugin that enables response validation for Fastify.

Tests JavaScript Style Guide standard-readme compliant

Made by GEUT

Install

$ npm install --save-dev @geut/fastify-response-validation

Usage

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)
})

Issues

🐛 If you found an issue we encourage you to report it on github. Please specify your OS and the actions to reproduce it.

Contributing

👥 Ideas and contributions to the project are welcome. You must follow this guideline.

License

MIT © A GEUT project