Thanks to visit codestin.com
Credit goes to github.com

Skip to content

z.fromJSONSchema() does not support metadata for enums, literals and not/never #5732

@nepellion

Description

@nepellion

Related to #5564 (closed by #5586)

While for the simple cases metadata parsing was added, they do not seem to be parsed for all of the special cases in convertBaseSchema, such as enums and literals.

// Will equal { description: "The name of the person" }
const stringMeta = z.fromJSONSchema({
  type: "string",
  description: "The name of the person",
}).meta();

// But all of these will be undefined
const enumMeta = z.fromJSONSchema({
  type: "string",
  enum: ["red", "green", "blue"],
  description: "The color of the object",
}).meta();
const literalMeta = z.fromJSONSchema({
  type: "string",
  const: "hello",
  description: "A constant string value",
}).meta();
const notMeta = z.fromJSONSchema({
  description: "Placeholder item",
  not: {},
}).meta();

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