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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to ajv/2020 for fastify 5 #5448

Open
2 tasks done
kibertoad opened this issue May 6, 2024 · 7 comments
Open
2 tasks done

Switch to ajv/2020 for fastify 5 #5448

kibertoad opened this issue May 6, 2024 · 7 comments
Labels
discussion Issues or PRs with this label will never stale

Comments

@kibertoad
Copy link
Member

Prerequisites

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

馃殌 Feature Proposal

I wonder if we should consider switching to ajv/dist/2020 during our next SemVer major.

According to sinclairzx81/typebox#490 (comment), default ajv is still using Draft 7 version of JSON schema.

Motivation

Support latest additions to the JSON schema standard. Considering the scope and impact of this change, I doubt we can do this outside of a SemVer major.

Example

I don't expect usage patterns for ajv or ajv-compiler to change, it will simply allow to support the features introduced in later versions of JSON Schema.

@kibertoad kibertoad added the feature request New feature to be added label May 6, 2024
@climba03003
Copy link
Member

Draft 7 and Draft 2020-12 is great different.
It also provides a large set of incompatibility.

@kibertoad
Copy link
Member Author

@climba03003 Do you mean that existing Draft 7 schemas will stop working under Draft 2020?

@climba03003
Copy link
Member

climba03003 commented May 6, 2024

Do you mean that existing Draft 7 schemas will stop working under Draft 2020?

Mostly, yes. If it can works, I don't see a reason why, ajv would split into different version.

https://json-schema.org/draft/2019-09/release-notes
https://json-schema.org/draft/2020-12/release-notes

@metcoder95
Copy link
Member

Draft-2020 is also marked as non-backwards compatible by ajv: https://ajv.js.org/json-schema.html#draft-2020-12

It would be nice but a lot of schemas uses mostly the 2019-draft, and doing this make them prone to break and cause friction with the adoption of Fastify v5.

Might be better to allow them do it if they want or still use 2019's draft

@gurgunday
Copy link
Member

gurgunday commented May 6, 2024

It's also important to note that, and this is what changed my mind on this, the AJV docs recommend sticking with 07 if we don't need the two new properties as all schemas will be affected by the reduced performance required to support them

fastify/ajv-compiler#105 (comment)
https://ajv.js.org/guide/schema-language.html#draft-2019-09-and-draft-2020-12

So it seems logical for me to keep the default 7 and let the user configure the setting

@Eomm
Copy link
Member

Eomm commented May 6, 2024

Switching the ajv version is as easy as writing:

const factoryValidator = require('@fastify/ajv-compiler')()

const app = fastify({
  schemaController: {
    compilersFactory: {
      buildValidator: factoryValidator
    }
  }
})

Since changing the default would be a massive breaking change for the user (as it should rewrite all its schemas) - we could just ship a new @fastify/ajv-compiler major with ajv/2020 and let those users that want the new standard set the buildValidator option accordingly.

@climba03003 climba03003 added discussion Issues or PRs with this label will never stale and removed feature request New feature to be added labels May 6, 2024
@mcollina
Copy link
Member

mcollina commented May 6, 2024

I think we would need fast-json-stringify to support it first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Issues or PRs with this label will never stale
Projects
None yet
Development

No branches or pull requests

6 participants