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

Validation not taken into account with anyOf #239

Open
dmckeone opened this issue Oct 5, 2023 · 1 comment
Open

Validation not taken into account with anyOf #239

dmckeone opened this issue Oct 5, 2023 · 1 comment

Comments

@dmckeone
Copy link

dmckeone commented Oct 5, 2023

Describe the bug

When using anyOf for an optional field, validation criteria are not generated.

Minimal reproduction

"first_name": {
   "type": "string",
  "minLength": 1
  "maxLength": 30
}

The above works, and produces:

.object({
    first_name: z.string().min(1).max(30),
  })

The below does not work:

"first_name": {
    "anyOf": [
        {
            "type": "string",
            "maxLength": 30,
            "minLength": 1
        },
        {
            "type": "null"
        }
    ],
    "default": null
}

and produces:

.object({
    first_name: z.union([z.string(), z.null()]),
  })

Expected behavior

"first_name": {
    "anyOf": [
        {
            "type": "string",
            "maxLength": 30,
            "minLength": 1
        },
        {
            "type": "null"
        }
    ],
    "default": null
}

should produce:

.object({
    first_name: z.union([z.string().min(1).max(30), z.null()]),
  })
@dror-trail
Copy link

.object({
    first_name: z.string().min(1).max(30).nullable(),
  })

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