@fastify/ajv-compiler
Advanced tools
Comparing version 2.1.0 to 3.0.0
@@ -9,3 +9,3 @@ 'use strict' | ||
const defaultAjvOptions = { | ||
coerceTypes: true, | ||
coerceTypes: 'array', | ||
useDefaults: true, | ||
@@ -12,0 +12,0 @@ removeAdditional: true, |
{ | ||
"name": "@fastify/ajv-compiler", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Build and manage the AJV instances for the fastify framework", | ||
@@ -44,3 +44,3 @@ "main": "index.js", | ||
"tap": "^15.0.9", | ||
"tsd": "^0.17.0" | ||
"tsd": "^0.19.0" | ||
}, | ||
@@ -47,0 +47,0 @@ "dependencies": { |
@@ -16,3 +16,4 @@ # @fastify/ajv-compiler | ||
| v1.x | v6.x | ^3.14 | | ||
| v2.x | v8.x | TBD | | ||
| v2.x | v8.x | - | | ||
| v3.x | v8.x | ^4.x | | ||
@@ -26,3 +27,3 @@ | ||
{ | ||
coerceTypes: true, | ||
coerceTypes: 'array', | ||
useDefaults: true, | ||
@@ -32,4 +33,3 @@ removeAdditional: true, | ||
// When set to `true`, a DoS attack is possible. | ||
allErrors: false, | ||
nullable: true | ||
allErrors: false | ||
} | ||
@@ -41,3 +41,3 @@ ``` | ||
To customize them, see how in the [Fastify official docs](https://www.fastify.io/docs/latest/Server/#ajv). | ||
To customize them, see how in the [Fastify official docs](https://www.fastify.io/docs/latest/Reference/Server/#ajv). | ||
@@ -48,3 +48,3 @@ | ||
This module is already used as default by Fastify. | ||
If you need to provide to your server instance a different version, refer to [the official doc](https://www.fastify.io/docs/latest/Server/#schemacontroller). | ||
If you need to provide to your server instance a different version, refer to [the official doc](https://www.fastify.io/docs/latest/Reference/Server/#schemacontroller). | ||
@@ -183,3 +183,3 @@ ### Customize the `ajv-formats` plugin | ||
This module provide a factory function to produce [Validator Compilers](https://www.fastify.io/docs/latest/Server/#validatorcompiler) functions. | ||
This module provide a factory function to produce [Validator Compilers](https://www.fastify.io/docs/latest/Reference/Server/#validatorcompiler) functions. | ||
@@ -192,3 +192,3 @@ The Fastify factory function is just one per server instance and it is called for every encapsulated context created by the application through the `fastify.register()` call. | ||
- the AJV configuration: it is [one per server](https://www.fastify.io/docs/latest/Server/#ajv) | ||
- the AJV configuration: it is [one per server](https://www.fastify.io/docs/latest/Reference/Server/#ajv) | ||
- the external JSON schemas: once a new schema is added to a fastify's context, calling `fastify.addSchema()`, it will cause a new AJV inizialization | ||
@@ -195,0 +195,0 @@ |
@@ -57,2 +57,41 @@ 'use strict' | ||
t.test('array coercion', t => { | ||
t.plan(2) | ||
const factory = AjvCompiler() | ||
const compiler = factory(externalSchemas1, fastifyAjvOptionsDefault) | ||
const arraySchema = { | ||
$id: 'example1', | ||
type: 'object', | ||
properties: { | ||
name: { type: 'array', items: { type: 'string' } } | ||
} | ||
} | ||
const validatorFunc = compiler({ schema: arraySchema }) | ||
const inputObj = { name: 'hello' } | ||
t.equal(validatorFunc(inputObj), true) | ||
t.same(inputObj, { name: ['hello'] }, 'the name property should be coerced to an array') | ||
}) | ||
t.test('nullable default', t => { | ||
t.plan(2) | ||
const factory = AjvCompiler() | ||
const compiler = factory({}, fastifyAjvOptionsDefault) | ||
const validatorFunc = compiler({ | ||
schema: { | ||
type: 'object', | ||
properties: { | ||
nullable: { type: 'string', nullable: true }, | ||
notNullable: { type: 'string' } | ||
} | ||
} | ||
}) | ||
const input = { nullable: null, notNullable: null } | ||
const result = validatorFunc(input) | ||
t.equal(result, true) | ||
t.same(input, { nullable: null, notNullable: '' }, 'the notNullable field has been coerced') | ||
}) | ||
t.test('plugin loading', t => { | ||
@@ -59,0 +98,0 @@ t.plan(3) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31843
16
762