From 795e83a710abee5e4c0351e34e8d743b1de44078 Mon Sep 17 00:00:00 2001 From: Jakob Date: Sat, 13 Nov 2021 11:25:42 +0100 Subject: [PATCH] docs: Extend TypeBox documentation (#3437) --- docs/Type-Providers.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/Type-Providers.md b/docs/Type-Providers.md index c2aae8bf87..58f596b5b4 100644 --- a/docs/Type-Providers.md +++ b/docs/Type-Providers.md @@ -61,7 +61,14 @@ import { TypeBoxTypeProvider, Type } from 'fastify-type-provider-typebox' import fastify from 'fastify' -const server = fastify().withTypeProvider() +const server = fastify({ + ajv: { + customOptions: { + strict: 'log', + keywords: ['kind', 'modifier'], + }, + }, +}).withTypeProvider() server.get('/route', { schema: { @@ -77,3 +84,7 @@ server.get('/route', { const { foo, bar } = request.query // type safe! }) ``` + +TypeBox uses the properties `kind` and `modifier` internally. These properties are not strictly valid JSON schema which will cause `AJV@7` and newer versions to throw an invalid schema error. To remove the error it's either necessary to omit the properties by using [`Type.Strict()`](https://github.com/sinclairzx81/typebox#strict) or use the AJV options for adding custom keywords. + +See also the [TypeBox documentation](https://github.com/sinclairzx81/typebox#validation) on how to set up AJV to work with TypeBox.