fastify / fastify-response-validation

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

Unknown format "float" is used in schema at path "..." #42

Closed nicolagusso closed 2 years ago

nicolagusso commented 3 years ago

Prerequisites

Fastify version

3.17.0

Plugin version

0.1.0

Node.js version

16.2.0

Operating system

macOS

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

10.15.7

Description

Hi, I'm trying to use this plugin to validate the responses generated by my Fastify app. In addition to Fastify, in order to generate programmatically all the routes from an openapi specification, I'm using fastify-openapi-glue.

Each time I try to run my app I get the following error: unknown format "float" is used in schema at path "..."

In order to solve this issue i tried to use others libraries in order to integrate the missing format, for example:

I tryed also to override the instance of ajv used by Fastify with another one.

Steps to Reproduce

  1. Define a openApi specification that uses the float format for one of its properties;
  2. Create a Fastify app that uses the previous openApi specification to generate all its routes through the use of fastify-openapi-glue plugin;
  3. Inside the app code and before the use of fastify-openapi-glue register the fastify-response-validation plugin to enable the response validation;
  4. Run the app and see if the error occours.

Expected Behavior

Shouldn't throw the error reported in the description.

climba03003 commented 3 years ago

This plugin use it's own ajv instance and it is not shared with fastify. I do not see any way you can pass the ajv plugin to this plugin.

I think a PR to allow applying plugin to this plugin ajv instance is the solution. Would you like to send a PR to address this issue?

Reference for how to implement the plugins option. https://github.com/fastify/ajv-compiler/blob/main/index.js#L53-L61

nicolagusso commented 3 years ago

Hi, thanks for the response! 😃

I would like to try. Just to be sure of understanding correctly what you are asking for. You would like to implement the plugins option as it's currently implemented inside the ajv-compiler component, right? 🤔

nicolagusso commented 3 years ago

Also, I wanted to share a thought of mine. Since this is a plugin for Fastify, wouldn't be better to use the very same instance of ajv used by Fastify itself? 🤔