fastify / fastify-response-validation

A simple plugin that enables response validation for Fastify.
MIT License
53 stars 17 forks source link

Support passing in a custom Ajv instance #93

Closed felixfbecker closed 1 year ago

felixfbecker commented 1 year ago

Prerequisites

🚀 Feature Proposal

Please provide the ability to pass in your own Ajv instance.

Motivation

Currently, one can only pass in ajv options, and the plugin instantiates ajv. But to use latest drafts of JSON Schema, one has to import a different Ajv class than the default export: https://ajv.js.org/json-schema.html#draft-2020-12

In Fastify request validation, this is possible with setCompileFactory(), but it won't work for response validation.

Example

const ajv = new Ajv2020({ ... })
fastify.register(responseValidation, { ajv })
mcollina commented 1 year ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

Fdawgs commented 1 year ago

Closed by #94