title: Use ajv-formats with fastify
body: <p>Playing with fastify and the schema object on routes, I'm trying to add more validations. fastify use (for body validations) <a href="https://github.com/ajv-validator/ajv" rel="nofollow noreferrer">ajv</a>. Following fastify documentation and code, to add a ajv plugin I need to do this:</p>
  <pre class="lang-js prettyprint-override"><code>const fastify = require('fastify')({
    ajv: {
      plugins: [
        require('ajv-merge-patch')
      ]
    }
  })
  </code></pre>
  <p>The documentation is <a href="https://www.fastify.io/docs/latest/Validation-and-Serialization/#ajv-plugins" rel="nofollow noreferrer">here</a></p>
  <p>The problem is that when we try to add this plugin, I receive this error: <code>Cannot read property 'code' of undefined&quot;</code> and this is the stack error:</p>
  <pre><code>TypeError: Cannot read property 'code' of undefined
    at addFormats (/test-api/node_modules/ajv-formats/dist/index.js:30:26)
    at Array.formatsPlugin (/test-api/node_modules/ajv-formats/dist/index.js:15:5)
    at ValidatorCompiler (/test-api/node_modules/fastify/lib/schema-compilers.js:42:16)
    at buildCompilerFromPool (/test-api/node_modules/fastify/lib/schema-compilers.js:20:22)
    at Boot.&lt;anonymous&gt; (/test-api/node_modules/fastify/lib/route.js:269:39)
    at Object.onceWrapper (events.js:421:28)
    at Boot.emit (events.js:327:22)
    at /test-api/node_modules/avvio/boot.js:153:12
    at /test-api/node_modules/avvio/plugin.js:269:7
    at done (/test-api/node_modules/avvio/plugin.js:201:5)&quot;
  </code></pre>
  <p>I get this error with this piece of code:</p>
  <pre class="lang-js prettyprint-override"><code>const server: FastifyInstance&lt;Server, IncomingMessage, ServerResponse &gt; = fastify({
    ignoreTrailingSlash: true,
    logger: true,
    ajv: {
      plugins: [
        require('ajv-formats')
      ]
    }
  })
  
  async function run (): Promise&lt;string&gt; {
    server.addHook('onRoute', (options) =&gt; console.log(options))
  
    await server.register(helmet)
    await server.register(cors)
  
    return server.listen(3000, 'localhost')
  }
  </code></pre>
  <p>Has anyone been able to use <code>ajv-formats</code> with fastify or could you help me, please?</p>
  <p>Thanks in advance!</p>