Skip to content

Type.Unsafe<Date> FST_ERR_SCH_VALIDATION_BUILD with TypeBoxValidatorCompiler in body schema #221

Description

@IngBertolini

Prerequisites

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

Fastify version

5.2.1

Plugin version

5.1.0

Node.js version

20.16.0

Operating system

Linux

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

Ubuntu 22.04.4

Description

I'm trying to deal with Date objects with Fastify and swagger. I defined the type of my date fields like this
const TDate = Type.Unsafe<Date>({ type: "string", format: "date-time" })
following this answer: link

Using the TypeBoxValidatorCompiler, during the start up i get this error:

/home/berto/Sviluppo/synapse/node_modules/.pnpm/fastify@5.2.1/node_modules/fastify/lib/route.js:392
              throw new FST_ERR_SCH_VALIDATION_BUILD(opts.method, url, error.message)
                    ^
FastifyError [Error]: Failed building the validation schema for POST: /users/:user_uuid/api-keys, due to error Unknown type
    at Boot.<anonymous> (/home/berto/Sviluppo/synapse/node_modules/.pnpm/fastify@5.2.1/node_modules/fastify/lib/route.js:392:21)
    at Object.onceWrapper (node:events:633:28)
    at Boot.emit (node:events:531:35)
    at Boot.emit (node:domain:488:12)
    at /home/berto/Sviluppo/synapse/node_modules/.pnpm/avvio@9.1.0/node_modules/avvio/boot.js:102:12
    at /home/berto/Sviluppo/synapse/node_modules/.pnpm/avvio@9.1.0/node_modules/avvio/boot.js:437:7
    at done (/home/berto/Sviluppo/synapse/node_modules/.pnpm/avvio@9.1.0/node_modules/avvio/lib/plugin.js:228:5)
    at check (/home/berto/Sviluppo/synapse/node_modules/.pnpm/avvio@9.1.0/node_modules/avvio/lib/plugin.js:252:9)
    at node:internal/process/task_queues:140:7
    at AsyncResource.runInAsyncScope (node:async_hooks:206:9) {
  code: 'FST_ERR_SCH_VALIDATION_BUILD',
  statusCode: 500
}

However this happens only if a TDate field is present in the schema in the params, quesrystring or body section.
The error doesn't occur if a TDate field is present within the reply section of the schema.

Link to code that reproduces the bug

https://github.com/IngBertolini/typebox-compiler-error

Expected Behavior

No response

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