Skip to content

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

@marr

Description

@marr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions