Skip to content

Schema definitions are ignored #210

@nikita-mishchenko

Description

@nikita-mishchenko

When a schema (for example, response schema) contains cycles, zod toJSONSchema creates _shared with refs definitions, however, in fastify-type-provider-zod@6.0.0 this attribute is ignored. And I'm getting invalid schema because it contains references to missing schemas.

To reproduce it, just add z.json() to your schema.

The place in the code where it is ignored is zod-to-json.ts when you call method zodSchemaToJson.

 const {
    schemas: { [tempID]: result },
  } = toJSONSchema(tempRegistry, {
    target,
    metadata: registry,
    io,
    unrepresentable: 'any',
    cycles: 'ref',
...

should be something like:

 const {
    schemas: { 
        [tempID]: result, 
        __shared,
    },
  } = toJSONSchema(tempRegistry, {
    target,
    metadata: registry,
    io,
    unrepresentable: 'any',
    cycles: 'ref',
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions