Skip to content

Commit

Permalink
Update Validation-and-Serialization.md (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
cemremengu authored and delvedor committed Aug 26, 2018
1 parent e77cae9 commit ba9a629
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions docs/Validation-and-Serialization.md
Expand Up @@ -107,18 +107,30 @@ The function `getSchemas` returns all shared schemas that were added by `addSche
<a name="schema-compiler"></a>
#### Schema Compiler

The `schemaCompiler` is a function that returns a function that validates the body, url parameters, headers, and query string. The default `schemaCompiler` returns a function that implements the `ajv` validation interface. Fastify uses it internally to speed the validation up.
The `schemaCompiler` is a function that returns a function that validates the body, url parameters, headers, and query string. The default `schemaCompiler` returns a function that implements the [ajv](https://ajv.js.org/) validation interface. Fastify uses it internally to speed the validation up.

While you cannot change the configuration options of the default `ajv` instance, you can create your own:
Fastify's baseline ajv configuration is:

```js
{
removeAdditional: true,
useDefaults: true,
coerceTypes: true
}
```

This baseline configuration cannot be modified. If you want to change or set additional config options, you will need to create your own instance and override the existing one like:

```js
const fastify = require('fastify')()
const Ajv = require('ajv')
const ajv = new Ajv({
// the fastify defaults
// the fastify defaults (if needed)
removeAdditional: true,
useDefaults: true,
coerceTypes: true
// any other options
// ...
})
fastify.setSchemaCompiler(function (schema) {
return ajv.compile(schema)
Expand Down

0 comments on commit ba9a629

Please sign in to comment.