Skip to content

Route schema might be undefined #5393

@nflaig

Description

@nflaig

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

Plugin version

No response

Node.js version

20.x

Operating system

Linux

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

Ubuntu 22.04

Description

FastifyRequest.routeSchema might be undefined, for example if route does not exists. The type currently can't be trusted if you would try to access the schema within any hook.

I think the type here should be marked as optional

routeSchema: FastifySchema

and same goes for schema in route options

schema: SchemaCompiler;

Steps to Reproduce

Set up fastify with a hook like onRequest and observe schema while calling a route that has no been defined.

Expected Behavior

The type should correctly reflect runtime behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bugtypescriptTypeScript related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions