Skip to content

geut/fastify-response-validation

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published