Replies: 1 comment 3 replies
-
@enzolupia Hi, The format setup doesn't look quite right. Just a few things Format RegistrationThe format callback is passed a string, so you need to be checking a string value. The TypeSystem.Format('clientFormat', value => Value.Check(schema, value));
// ^ ^ value is string
// |
// { client: { name: string, alias: string } }
// For example, it should be
TypeSystem.Format('foo-format', value => value === 'foo'); Compiler SetupJust note if you're using Fastify with the Type Provider, and want to use the TypeBox validation backend, you need to register that with the Fastify instance. import { Type, TypeBoxTypeProvider, TypeBoxValidatorCompiler } from '@fastify/type-provider-typebox'
import Fastify from 'fastify'
const fastify = Fastify().setValidatorCompiler(TypeBoxValidatorCompiler) // set validator compiler here Information on the setup can be found here Let me know if that helps |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Typebox version: 0.28.14
Hi, I'm trying to define a custom format to validate a string header against a custom object schema.
This is a simplified version of what I did so far:
Finally my request' schema looks like this:
On server startup I get the following error:
[serve] FastifyError [Error]: Failed building the validation schema for POST: /api/v2/projects/get-project, due to error unknown format "clientFormat" ignored in schema at path "#/properties/x-client"
It looks like the custom format is not registered, I didn't find any additional information in the documentations, am I missing something?
Beta Was this translation helpful? Give feedback.
All reactions