Skip to content

feat: add double schema bucket for validator and serializer (#3402)#6757

Open
BALOGUN-DAVID wants to merge 1 commit into
fastify:mainfrom
BALOGUN-DAVID:main
Open

feat: add double schema bucket for validator and serializer (#3402)#6757
BALOGUN-DAVID wants to merge 1 commit into
fastify:mainfrom
BALOGUN-DAVID:main

Conversation

@BALOGUN-DAVID
Copy link
Copy Markdown

resolves #3402

This PR implements the "Double Schema Bucket" feature discussed in #3402 to resolve compatibility issues when passing schemas containing newer JSON Schema drafts (e.g., 2020-12) to both ajv (which supports it) and fast-json-stringify (which throws errors as it only supports up to draft 07).

Changes:

  • lib/schema-controller.js: Split the core schema container into discrete validatorBucket and serializerBucket instances.
  • fastify.js: Added an options parameter to addSchema(schema, options) supporting { validator?: boolean, serializer?: boolean } config object.
  • types/instance.d.ts: Updated TypeScript definitions for the new options argument and exposed getters.
  • test/schema-double-bucket.test.js: Added unit tests to ensure scopes do not leak when adding schemas targeted at specific compilers.

Note: The feature is completely backward compatible. Calling addSchema(schema) without options continues to add the schema to both buckets as it always has.

Checklist

@github-actions github-actions Bot added the typescript TypeScript related label Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

typescript TypeScript related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Double schema bucket

1 participant