8000 V4: toJSONSchema z.literal is missing "type" · Issue #4249 · colinhacks/zod · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
V4: toJSONSchema z.literal is missing "type" #4249
Closed
@marclp

Description

@marclp

I am using toJSONSchema to generate an openapi schema for gemini and it is complaining that "type" is missing when using z.literal() compared to using v3 with zod-to-json-schema, I am not sure if this is intended, an oversight, or google's APIs are very picky. Here is an example of a simple json schema produced in v3 vs the same in v4 using z.toJSONSchema.

V3:

{
  "type": "object",
  "properties": {
    "test": {
      "type": "string",
      "const": "test"
    }
  },
  "required": [
    "test"
  ],
  "additionalProperties": false,
  "$schema": "http://json-schema.org/draft-07/schema#"
}

V4:

{
  "type": "object",
  "properties": {
    "test": {
      "const": "test"
    }
  },
  "required": [
    "test"
  ]
}

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

      0