Skip to content

Union type generates anyOf instead oneOf #5493

@ddontsov-b2broker

Description

@ddontsov-b2broker
export const example = z.union([
  z.string().min(10),
  z.string().min(5)],
);

will generate schema like this in zod@4.1.13

"exampleField": {
  "anyOf":[
    {"type":"string","minLength":10},
    {"type":"string","minLength":5}
  ]
}

but in zod v3 it generates:

"exampleField": {
  "oneOf":[
    {"type":"string","minLength":10},
    {"type":"string","minLength":5}
  ]
}

I think it should use oneOf instead of anyOf

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