Skip to content

addSchema prevents reuse of fluent-json-schema objects #4276

@esatterwhite

Description

@esatterwhite

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.5.3

Plugin version

No response

Node.js version

16.14

Operating system

Linux

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

Linux 5.10.136-1-MANJARO x86_64 GNU/Linux

Description

Using addSchema seems to prevent the reuse of the same schema with modifications - this is particularly restrictive when using fluent-json-schema. This prevents you from being able to re-use the schema object for both input and response validations.

fastify.addSchema(Thing)

fastify.route({
  method: 'POST'
, path: '/thing'
, schema: {
    body: Thing.only('whiz')
  , response: {
      200: Thing
    }
  }
})

Additionally, when Using the openapi bits in @fastify/swagger It seems you have to use addSchema to have them show up properly in the compoments.schema section of the documentation.

Commenting out fastify.addSchema(Thing) allows me to re-use the schema for multiple purposes, however, the swagger/openapi documentation ends up missing a lot of information. and the use of ref no longer works.

Steps to Reproduce

There is a reproduction gist here

Expected Behavior

When using fastify w/ fluent-json-schema, I would expect to be able to define a full schema object , register that with fastify as a canonical type, and be able to reuse the fluent schema object to generate subsets of that for other validation points.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions