Skip to content

custom schema support installed by setValidatorCompiler removed if any schemas are added #5178

@derammo

Description

@derammo

Prerequisites

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

Fastify version

4.24.3

Plugin version

No response

Node.js version

18.18.2

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

bookworm

Description

At this location:

this.validatorCompiler = this.getValidatorBuilder()(this.schemaBucket.getSchemas(), serverOptions.ajv)

Any custom schema support is removed if any schemas were added, because the default builder is used to overwrite the installed validatorCompiler.

The order of operations does not appear to matter, because both registering the custom schema support and adding schemas by id will happen before listen and this initialization is run at that time.

Steps to Reproduce

const server: Fastify = fastify({
  logger: true
});
server.setValidatorCompiler(...)
server.addSchema(...)
server.setValidatorCompiler(...) // again if you want to, it won't help
server.listen(...)

Any validation schema that needs the customization from setValidatorCompiler(...) will fail to compile because the default compiler is actually used.

Expected Behavior

if this.isCustomSerializerCompiler then it should not overwrite the installed compiler

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions