All Projects → fastify → fastify-response-validation

fastify / fastify-response-validation

Licence: MIT License
A simple plugin that enables response validation for Fastify.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to fastify-response-validation

openui5-validator
A library to validate OpenUI5 fields
Stars: ✭ 17 (-15%)
Mutual labels:  validation, ajv
ng2-multi-step-wizard-ui-router1
Series 3: Tutorials on creating an Angular 2 Multi-Step Wizard using UI-Router 1.0 and TypeScript 2.0.10
Stars: ✭ 33 (+65%)
Mutual labels:  validation
datalize
Parameter, query, form data validation and filtering for NodeJS.
Stars: ✭ 55 (+175%)
Mutual labels:  validation
formalizer
React hooks based form validation made for humans.
Stars: ✭ 12 (-40%)
Mutual labels:  validation
frames-android
Checkout API Client, Payment Form UI and Utilities
Stars: ✭ 26 (+30%)
Mutual labels:  validation
dockerfile-utils
A library and command line interface for formatting and linting Dockerfiles.
Stars: ✭ 17 (-15%)
Mutual labels:  validation
phone
Validate phone number format
Stars: ✭ 63 (+215%)
Mutual labels:  validation
fastify-boilerplate
fastify boilerplate for building RESTful APIs ⏰ Includes design (APIs), deploy(Application), and monitoring(Application).
Stars: ✭ 27 (+35%)
Mutual labels:  fastify
vue-tiny-validate
💯 Tiny Vue Validate Composition
Stars: ✭ 80 (+300%)
Mutual labels:  validation
ember-changeset-conditional-validations
Conditional validations for ember-changeset-validations
Stars: ✭ 26 (+30%)
Mutual labels:  validation
validatedb
Validate on a table in a DB, using dbplyr
Stars: ✭ 15 (-25%)
Mutual labels:  validation
Domainker
BugBounty Tool
Stars: ✭ 40 (+100%)
Mutual labels:  response
Fore
Fore - declarative programming with web components
Stars: ✭ 34 (+70%)
Mutual labels:  validation
fastify-kafka
Fastify plugin to interact with Apache Kafka.
Stars: ✭ 37 (+85%)
Mutual labels:  fastify
fqdn
RFC-compliant FQDN validation and manipulation for Python.
Stars: ✭ 23 (+15%)
Mutual labels:  validation
filter
Go语言的数据过滤包,由 数据输入、格式化、校验、输出 几个部份组成。
Stars: ✭ 22 (+10%)
Mutual labels:  validation
rdf-validate-shacl
Validate RDF data purely in JavaScript. An implementation of the W3C SHACL specification on top of the RDFJS stack.
Stars: ✭ 61 (+205%)
Mutual labels:  validation
openapi-lint-vscode
OpenAPI 2.0/3.0.x intellisense, validator, linter, converter and resolver extension for Visual Studio Code
Stars: ✭ 47 (+135%)
Mutual labels:  validation
verum-php
Server-Side Validation Library for PHP
Stars: ✭ 17 (-15%)
Mutual labels:  validation
liquibase-linter
Quality control for your Liquibase scripts
Stars: ✭ 15 (-25%)
Mutual labels:  validation

fastify-response-validation

CI NPM version Known Vulnerabilities js-standard-style

A simple plugin that enables response validation for Fastify.
The use of this plugin will slow down your overall performance, so we suggest using it only during development.

Install

npm i fastify-response-validation

Usage

You just need to register the plugin and you will have response validation enabled:

const fastify = require('fastify')()

fastify.register(require('fastify-response-validation'))

fastify.route({
  method: 'GET',
  path: '/',
  schema: {
    response: {
      '2xx': {
        type: 'object',
        properties: {
          answer: { type: 'number' }
        }
      }
    }
  },
  handler: async (req, reply) => {
    return { answer: '42' }
  }
})

fastify.inject({
  method: 'GET',
  path: '/'
}, (err, res) => {
  if (err) throw err
  console.log(res.payload)
})

If you want to override the default ajv configuration, you can do that by using the ajv option:

// Default configuration:
//    coerceTypes: false
//    useDefaults: true
//    removeAdditional: true
//    allErrors: true
//    nullable: true

fastify.register(require('fastify-response-validation'), {
  ajv: {
    coerceTypes: true
  }
})

By default the response validation is enabled on every route that has a response schema defined. If needed you can disable it all together with responseValidation: false:

fastify.register(require('fastify-response-validation'), {
  responseValidation: false
})

Alternatively, you can disable a specific route with the same option:

fastify.route({
  method: 'GET',
  path: '/',
  responseValidation: false,
  schema: {
    response: {
      '2xx': {
        type: 'object',
        properties: {
          answer: { type: 'number' }
        }
      }
    }
  },
  handler: async (req, reply) => {
    return { answer: '42' }
  }
})

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].