Skip to content

Incorrect zod generation for schemas with "additionalProperties": true #2352

@ntjess

Description

@ntjess

Description

Make an openapi spec for a schema with arbitrary keys (`"additionalProperties": true) and generate types + zod models for it using hey-api.

The type will be correct:

export type MyModel = {
  id: string;
  [key: string]: unknown | string; // Hooray, it worked!
};

But the zod schema won't look for these extra properties and will instead strip them during parse:

export const zMyModel = z.object({
  id: z.string()
}); // no .catchall(...) :(

Reproducible example or configuration

(Seems like a bunch of work to mangle stackblitz into a MWE -- hopefully the bug report contains sufficient info)

OpenAPI specification (optional)

No response

System information (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Something isn't workingneeds info ⏳Further information is required

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions