npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fastify-no-response-validation

v1.0.2

Published

A Fastify plugin to disable response validation

Downloads

12

Readme

fastify-no-response-validation

NPM version NPM downloads CI Coverage

Disable response validation in Fastify.

Why This Plugin?

By default, Fastify doesn't validate responses unless you're using the @fastify/response-validation plugin, which only supports AJV (Fastify's default validator). However, when working with Zod schemas, especially through fastify-zod-openapi or fastify-type-provider-zod, response validation is automatically enabled.

This plugin disables response validation in Fastify. After applying this plugin:

  1. Responses that don't match the defined schema won't trigger a 500 error
  2. API performance improves as response validation overhead is removed
  3. Schema documentation is preserved for API documentation purposes

Pro Tip

When using this plugin, you don't need to include fastify.setSerializerCompiler(serializerCompiler) in your setup. The plugin takes care of serialization internally.

Install

npm install fastify-no-response-validation

Usage

import Fastify from 'fastify';
import fastifyNoResponseValidation from 'fastify-no-response-validation';
import { validatorCompiler, type FastifyZodOpenApiTypeProvider } from 'fastify-zod-openapi';
import { z } from 'zod';

const fastify = Fastify().withTypeProvider<FastifyZodOpenApiTypeProvider>();

// Set up Zod validation
fastify.setValidatorCompiler(validatorCompiler);

// Register the plugin to disable response validation
fastify.register(fastifyNoResponseValidation);

// Define a route with a schema
fastify.get('/user', {
  schema: {
    response: {
      200: z.object({
        id: z.number(),
        name: z.string(),
      }),
    },
  },
}, (request, reply) => {
  // This response doesn't match the schema, but it will still be sent
  return { name: 'John', age: 30 } as any;
});

fastify.listen({ port: 3000 }, (err) => {
  if (err) throw err;
  console.log('Server is running on http://localhost:3000');
  console.log('Try: http://localhost:3000/user');
});

Compatibility

This plugin is compatible with Fastify v4.x and v5.x.

Contributing

Contributions, issues, and feature requests are welcome!

License

This project is licensed under the MIT License.