{"size": 575, "ext": "js", "max_stars_repo_path": "src/plugins/ajvCompiler.js", "max_stars_repo_name": "seesharpguy/fastify-api", "max_stars_repo_stars_event_min_datetime": "2020-07-17T07:47:54.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-28T21:33:24.000Z", "max_issues_repo_path": "src/plugins/ajvCompiler.js", "max_issues_repo_name": "seesharpguy/fastify-api", "max_issues_repo_issues_event_min_datetime": "2021-09-14T14:24:26.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-14T14:25:46.000Z", "max_forks_repo_path": "src/plugins/ajvCompiler.js", "max_forks_repo_name": "seesharpguy/fastify-api", "max_forks_repo_forks_event_min_datetime": "2021-09-07T12:53:39.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-30T11:53:11.000Z"}
{"max_stars_count": 34, "max_issues_count": 5, "max_forks_count": 3, "avg_line_length": 21.2962962963, "max_line_length": 48, "alphanum_fraction": 0.6626086957}
'use strict';

const fp = require('fastify-plugin');
const Ajv = require('ajv');
const AjvErrors = require('ajv-errors');
const addFormats = require('ajv-formats');

async function ajvCompiler(fastify, options) {
  const ajv = new Ajv({
    removeAdditional: true,
    useDefaults: true,
    coerceTypes: true,
    allErrors: true,
    allowUnionTypes: true
  });
  AjvErrors(ajv);
  addFormats(ajv);
  fastify.setValidatorCompiler(({ schema }) => {
    return ajv.compile(schema);
  });
}

module.exports = fp(ajvCompiler, {
  fastify: '>=3.0.0',
  name: 'ajv-compiler'
});
