@geut/fastify-response-validation

1.0.0 • Public • Published

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

Package Sidebar

Install

npm i @geut/fastify-response-validation

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

929 kB

Total Files

5

Last publish

Collaborators

  • geutuser
  • the-real-dk
  • tinchoz49
  • estebanprimost