fastify / fastify-response-validation

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

Cannot set ajv instace to 2019 and 2020 #107

Closed nicobuzeta closed 6 months ago

nicobuzeta commented 6 months ago

Prerequisites

Fastify version

4.26.1

Plugin version

2.5.1

Node.js version

21.7.1

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

Docker node:latest

Description

Current plugin does not allow ajv instances created with non-draft 7 schemas to be used like: ajv/dist/2019 ajv/dist/2020

Steps to Reproduce

import ajvNew from 'ajv/dist/2020.js';

export default fp(async (fastify) => {
  const ajv = new ajvNew.default();
  await fastify.register(response_validation, {
    ajv
  });
}

### Expected Behavior

Expect it to use my ajv instance internally. Right now the check for setting the ajv instance is:

if (opts.ajv && opts.ajv instanceof Ajv) {


However, this fails for this case since the ajv I am passing in is not of type Ajv.
nicobuzeta commented 6 months ago

I've proposed a possible fix in #108