Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeBox no longer requires explicit configuration of kind and modifier keywords #19

Closed
2 tasks done
sinclairzx81 opened this issue Jun 29, 2022 · 4 comments · Fixed by #20
Closed
2 tasks done

Comments

@sinclairzx81
Copy link
Contributor

sinclairzx81 commented Jun 29, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

Hi. Just a heads up. I've recently published a new version of TypeBox that should mitigate the need to configure AJV for the kind and modifier keywords. As of @sinclair/typebox@0.24.0, the kind and modifier keywords have been replaced as symbol property keys. This seems to sidestep the AJV strict checks allowing TypeBox schemas to be used without any explicit configuration.

Before

const StringKind = Symbol('StringKind')

const T = {
   kind: StringKind
   type: 'string'
}

After

const Kind = Symbol('TypeBox.Kind')

const T = {
   [Kind]: 'String' // AJV should ignore properties defined as symbols
   type: 'string'
}

The TypeBox type provider will continue to function with this existing kind and modifier configuration, however it may be good to remove the ajvTypeBoxPlugin export and update the documentation accordingly.

Current

import Fastify from 'fastify'
import { ajvTypeBoxPlugin, TypeBoxTypeProvider } from '@fastify/type-provider-typebox'

const fastify = Fastify({
  ajv: {
    plugins: [ajvTypeBoxPlugin]
  }
}).withTypeProvider<TypeBoxTypeProvider>()

Update

import Fastify from 'fastify'

import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'

const fastify = Fastify().withTypeProvider<TypeBoxTypeProvider>()
@mcollina
Copy link
Member

Thanks for reporting! Would you like to send a Pull Request to address this issue?

@sinclairzx81
Copy link
Contributor Author

@mcollina Yup, just preparing one now for review :)

@sinclairzx81
Copy link
Contributor Author

@mcollina Submitted on #20

@sinclairzx81 sinclairzx81 changed the title TypeBox no longer requires explicit configuration of kind and modifier keywords. TypeBox no longer requires explicit configuration of kind and modifier keywords Jun 29, 2022
@RafaelGSS RafaelGSS linked a pull request Jun 29, 2022 that will close this issue
4 tasks
@simonplend
Copy link

@sinclairzx81 This is a really nice improvement 👌🏻

simonplend added a commit to simonplend/fastify that referenced this issue Jun 29, 2022
TypeBox no longer requires the `kind` and `modifier` keywords to be added to Ajv (since v0.24.0).

See:

- https://github.com/sinclairzx81/typebox/blob/master/changelog.md#0240
- fastify/fastify-type-provider-typebox#19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants