10000 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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
marclp-es opened this issue Apr 20, 2025 · 1 comment
Open

V4: toJSONSchema z.literal is missing "type" #4249

marclp-es opened this issue Apr 20, 2025 · 1 comment

Comments

@marclp-es
Copy link
marclp-es commented Apr 20, 2025

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"
  ]
}
@samchungy
Copy link
Contributor

const is technical valid by itself so it seems Google is picky. In my own library I made the decision to always include type as a number of different libraries which rely on spec aren't always compliant. But to be fair to them, the spec can be iffy at times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0