Skip to content

Using zod 4, and fastify-swagger reports "/$defs/__schema0 does not exist in document" #879

@Chan-cdt

Description

@Chan-cdt

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

No response

Node.js version

22.12.

Operating system

Windows

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

windows 11

Description

I customized a request body schema ,including a json format object.
Here is the example.

type Literal = boolean | number | string | null | undefined
type Json = Literal | { [key: string]: Json } | Json[]
const literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()])
const jsonSchema: z.ZodSchema = z.lazy(() => z.union([literalSchema, z.array(jsonSchema), z.record(z.string(), jsonSchema)]))

export const testModel = z.object({
id: z.string(),
content: jsonSchema.nullish()
})

When I open the Swagger UI url,it reports error: Could not resolve reference: Could not resolve pointer: /$defs/__schema0 does not exist in document.

Image

How can I fix it ,or it just not match?

Link to code that reproduces the bug

1

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