Skip to content

Error: Schema for validaton is undefined #4634

@c0sx

Description

@c0sx

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

Plugin version

No response

Node.js version

any

Operating system

Windows

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

10

Description

4.15 release have a backward compatibility issue (PR): it throws an error if schema for validation is undefined.

For example, we get a schemas and pass them to fastify.

const { headers, body } = getSchemas();

fastify.post('/', {
  schema: {
    headers,
    body
  }
}

Steps to Reproduce

const fastify = require("fastify")({ logger: true });

fastify.get(
  "/",
  {
    schema: {
      headers: undefined,
    },
  },
  () => {
    return "hello";
  }
);

const start = async () => {
  try {
    await fastify.listen({ port: 3000 });
  } catch (err) {
    fastify.log.error(err);
    process.exit(1);
  }
};

start();

Server throws an error Failed building the validation schema for GET: /, due to error headers schema is undefined" when started

Expected Behavior

I think that undefined is acceptable value, which means that validation will be skipped.

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