fastify / fastify/help

Error with Typebox extended schema and Ajv

Open
#848 0 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
No language data
Stars
68
Forks
8
Avg merge
11h 2m
Merged PRs (30d)
2

Description

Can't get ajv validator work with typebox extended schema.

i want to use ` Type.Date()` in my schema
```js
export const createUserSchema = Type.Object(
{
...
dateOfBirth: Type.Date(),
...
},
{additionalProperties: false}
)
````
Then i am getting ajv validation error `FastifyError [Error]: Failed building the validation schema for GET: /, due to error strict mode: unknown keyword: "instanceOf"` `"code": "FST_ERR_SCH_VALIDATION_BUILD",
`

I tried to follow docs and add `instanceof` to `ajv-keywords`. But this is not helping.
```
const server = Fastify({
ajv: {
customOptions: {
removeAdditional: 'all' // Refer to [ajv options](https://ajv.js.org/options.html#removeadditional)
},
plugins: [
[ajvKeywords, 'instanceof']
]
}
})
```

## Environment
modules:
```
"@fastify/type-provider-typebox": "^2.4.0",
"@sinclair/typebox": "^0.25.24",
"ajv-keywords": "^5.1.0",
"fastify": "^4.14.1"
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.