Skip to content

feat: Filter out unrepresentable schemas from unions #5013

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Bram-dc
Copy link
Contributor

@Bram-dc Bram-dc commented Jul 30, 2025

I needed this to properly create openapi types for example my date schema:

export const zodISODateTime = () => {
	return z
		.union([z.date(), z.iso.datetime()])
		.overwrite((v) => {
			if (typeof v === 'string') {
				return new Date(v)
			}
			return v
		})
		.pipe(z.date())
}

z.date() is not representable, but I still want it to work internally. The resulting json schema should skip it.

I was thinking we should not create an extra unrepresentable option "filter" but instead include it in the "any" option, because this is also done for z.literal()

@Bram-dc
Copy link
Contributor Author

Bram-dc commented Jul 30, 2025

I was thinking we should not create an extra unrepresentable option "filter" but instead include it in the "any" option, because this is also done for z.literal()

In this PR I did create an extra option. @colinhacks what are your thoughts?

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

Successfully merging this pull request may close these issues.

1 participant