Skip to content

Cannot access metadata in toJSONSchema unrepresentable #6626

Description

@joshuaavalon

I am trying to handle unrepresentable for json schema. However, I am not able to access the metadata defined in the original schema.
I checked the code and it seems like ctx.zodSchema is a new copy instead of original schema. It would be much simpler if metadata is also injected into the context.

zod: ^4.6.5

Example

import { z } from "zod";

const schema = z.number().transform(v => `${v}`).meta({ title: "foo" });
console.log(schema.meta());
console.log(z.globalRegistry.get(schema));

schema.toJSONSchema({ unrepresentable: ctx => {
  console.log(schema === ctx.zodSchema)
  console.log(z.globalRegistry.get(ctx.zodSchema));
  return "any"
}});

Result

node a.js
{ title: 'foo' }
{ title: 'foo' }
false
undefined

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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