Skip to content
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

[BUG]: additionalProperties values from json-schema should not be set on zod types #2681

Open
marr opened this issue Jan 31, 2025 · 0 comments
Labels

Comments

@marr
Copy link

marr commented Jan 31, 2025

When generating typescript-zod output from json-schema, quicktype includes additionalProperties values in the generated typescript.

Issue Type

quicktype io

Context (Environment, Version, Language)

mac osx/cli

Input Format: JSON Schema
Output Language: TypeScript Zod

using the npm cli

CLI, npm, or app.quicktype.io:
Version: quicktype version 23.0.171

Description

I am trying to output a zod schema from a json-schema file. My source includes additionalProperties which end up in the output zod schema. I'm not sure if that is valid output, as additionalProperties is a reserved word in json schema.

additionalProperties docs from JSON-Schema spec

Input Data

{
  "$id": "http://myapp.com/mything/",
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "additionalProperties": true,
  "metamodel_version": "1.7.0",
  "title": "mything",
  "type": "object",
  "version": null
}

Expected Behaviour / Output

import * as z from "zod";

export const MyThingSchema = z.object({
    "$id": z.string(),
    "$schema": z.string(),
    "metamodel_version": z.string(),
    "title": z.string(),
    "type": z.string(),
    "version": z.null(),
});
export type MyThing = z.infer<typeof MyThingSchema>;

Current Behaviour / Output

import * as z from "zod";

export const MyThingSchema = z.object({
    "$id": z.string(),
    "$schema": z.string(),
    "additionalProperties": z.boolean(),
    "metamodel_version": z.string(),
    "title": z.string(),
    "type": z.string(),
    "version": z.null(),
});
export type MyThing = z.infer<typeof MyThingSchema>;

Steps to Reproduce

quicktype schema.json --lang typescript-zod -o MyThing.ts

Possible Solution

I don't know what should actually be output in this situation, my use case is to send the generated zod to an instance of autoform, and I wasn't expecting to see additionalProperties part of the form.

@marr marr added the bug label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant