Closed robotastronaut closed 2 years ago
cc @Eomm
Considering the tight coupling between this package and the main Fastify package, I would have expected this to include an override for the fastify function to support the new Ajv 8 options.
Fastify should use these exported types (that are the ajv8). I wonder if the issue is on Fastify's side. Did you take a look there too?
Considering the tight coupling between this package and the main Fastify package, I would have expected this to include an override for the fastify function to support the new Ajv 8 options.
Fastify should use these exported types (that are the ajv8). I wonder if the issue is on Fastify's side. Did you take a look there too?
Yeah. Unfortunately, they have a non-peer dependency on Ajv6 and use that import directly, and the options type definitions are incompatible between the two. It's hard to say whether or not moving the Ajv dependency to peer would make sense. I know there are compatibility issues that have been noted when ajv has been installed as a peer dependency in other projects (I recall there being eslint issues, for one), so there's some logic to keeping it a private dependency. I'm sure I'm also in a minority of developers who use typescript in such a strict fashion that this is an issue.
Considering the tight coupling between this package and the main Fastify package, I would have expected this to include an override for the fastify function to support the new Ajv 8 options.
I think this is solved now in fastify v4: https://github.com/fastify/fastify/blob/main/fastify.d.ts#L11
It uses the exported option by this module.
Prerequisites
Fastify version
3.25.3
Plugin version
3.0.0
Node.js version
16.6.2
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
20.04
Description
When using this package as the default schema validator in fastify@3.25.3 (and others),
FastifyServerOptions
uses its own imported Ajv options type as the type for theajv
property, which is incompatible with those of Ajv 8. In general, this isn't a huge deal because you can just create an override of thefastify
function that accepts something like this (pardon any ugliness, it's a five second hack and I didn't bother with the generics):The current documentation for configuring Ajv 8 as the default validator isn't actually complete for typescript users.
Steps to Reproduce
Simply attempt to set the
ajv.customOptions.validateFormats
field onFastifyServerOptions
when using typescriptExpected Behavior
Considering the tight coupling between this package and the main Fastify package, I would have expected this to include an override for the fastify function to support the new Ajv 8 options.