Skip to content

Type null does not work with Typebox #889

@Edgar200021

Description

@Edgar200021

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

Plugin version

9.5.1

Node.js version

22

Operating system

Linux

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

Operating System: Arch Linux Kernel: Linux 6.15.6-arch1-1

Description

Hi, I'm using @fastify/type-provider-typebox to generate schemas, I noticed that when I pass type null, swagger doesn't understand this type

Generic type

import { type TSchema, Type } from "@sinclair/typebox";

export const SuccessResponseSchema = <T extends TSchema>(T: T) =>
	Type.Object({
		status: Type.Literal("success"),
		data: T,
	});

Usage in the function

import {
	type FastifyPluginAsyncTypebox,
	Type,
} from "@fastify/type-provider-typebox";
import { SignInSchema } from "../schemas/auth/sign-in.schema.js";
import {
	ErrorResponseSchema,
	SuccessResponseSchema,
	ValidationErrorResponseSchema,
} from "../schemas/base.js";

const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
	fastify.post(
		"/auth/sign-up",
		{
			schema: {
				body: SignInSchema,
				response: {
					201: SuccessResponseSchema(Type.Null()),
					400: Type.Union([ErrorResponseSchema, ValidationErrorResponseSchema]),
				},
				tags: ["Authentication"],
			},
		},

The result

Image

Link to code that reproduces the bug

Included in the description

Expected Behavior

The Type.Null() schema from TypeBox must be properly supported in the generated OpenAPI (Swagger) specification.

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