Skip to content

Fix Zod and Valibot plugins missing u flag on regex patterns with unicode property escapes#3468

Merged
mrlubos merged 6 commits intomainfrom
copilot/fix-zod-plugin-regex-unicode
Feb 27, 2026
Merged

Fix Zod and Valibot plugins missing u flag on regex patterns with unicode property escapes#3468
mrlubos merged 6 commits intomainfrom
copilot/fix-zod-plugin-regex-unicode

Conversation

Copy link
Contributor

Copilot AI commented Feb 26, 2026

  • Update patternNode in v3/toAst/string.ts to detect unicode property escapes and add u flag
  • Update patternNode in v4/toAst/string.ts similarly
  • Update patternNode in mini/toAst/string.ts similarly
  • Update patternNode in valibot/v1/toAst/string.ts similarly
  • Add unicode pattern test case to spec files (2.0.x, 3.0.x, 3.1.x)
  • Update test snapshots (zod + valibot + client snapshots)
  • Run pnpm examples:generate to update all example output
  • Run tests and verify (all tests pass)
Original prompt

This section details on the original issue you should resolve

<issue_title>Zod plugin doesn't work with regexes that contain unicode patterns</issue_title>
<issue_description>### Description

I have an Open API spec with a property defined as:

type: string
pattern: ^[\p{L} `\-'^.]{1,35}$

The zod plugin generates the following output for this type:z.string().regex(/^[\p{L} `\-'^.]{1,35}$/);

However the \p{L} segment of this code flags with the error "Property escape sequences are not supported in this regex dialect", and does not successfully match valid inputs.

Additional details

I am have been able to work around this issue by manually adding the unicode flag to this regex in the generated code - i.e. z.string().regex(/^[\p{L} `\-'^.]{1,35}$/u);

Digging into the Hey API code, it looks like this could be handled by passing a "u" value the optional second param of the $.regexp call in the patternNode function(s).

Proposed solution

As far as I can see, the options for addressing this are:

  1. Just set the "u" flag all the time
  2. Add logic to determine whether to enable the flag based on whether the pattern contains elements that require it
  3. Add a config option to specify flags that will be set for regexp validation

Reproducible example or configuration

No response

OpenAPI specification (optional)

No response

System information (optional)

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@changeset-bot
Copy link

changeset-bot bot commented Feb 26, 2026

🦋 Changeset detected

Latest commit: 02d0ed9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hey-api/openapi-ts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Feb 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hey-api-docs Ready Ready Preview, Comment Feb 27, 2026 9:28am

Request Review

…operty escapes

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Zod plugin regex handling for unicode patterns Fix Zod plugin missing u flag on regex patterns with unicode property escapes Feb 26, 2026
@mrlubos
Copy link
Member

mrlubos commented Feb 27, 2026

@copilot make sure regex works with Valibot as well. I'm not sure if the fix is the same there.

…e property escapes

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 27, 2026

@copilot make sure regex works with Valibot as well. I'm not sure if the fix is the same there.

Yes, Valibot had the same issue. Applied the same fix to valibot/v1/toAst/string.ts in commit 022960f — now v.regex(/^\p{L}+$/u) is generated when unicode property escapes are detected.

Copilot AI changed the title Fix Zod plugin missing u flag on regex patterns with unicode property escapes Fix Zod and Valibot plugins missing u flag on regex patterns with unicode property escapes Feb 27, 2026
Update Zod plugin to include `u` flag for regex patterns with unicode property escapes.
@mrlubos mrlubos marked this pull request as ready for review February 27, 2026 09:16
@pullfrog
Copy link

pullfrog bot commented Feb 27, 2026

Leaping into action...

Pullfrog  | View workflow run | Using OpenCode | Triggered by Pullfrogpullfrog.com𝕏

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug 🔥 Broken or incorrect behavior. labels Feb 27, 2026
@mrlubos
Copy link
Member

mrlubos commented Feb 27, 2026

@copilot CI fails, you probably didn't run pnpm test:update and pnpm examples:generate

…hUnicode field

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 27, 2026

@copilot CI fails, you probably didn't run pnpm test:update and pnpm examples:generate

Fixed in commit 02d0ed9. Ran vitest run --update to update the clients test snapshots and pnpm examples:generate to regenerate all example output — 93 snapshot files updated.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 27, 2026
@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.10%. Comparing base (75d9833) to head (02d0ed9).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
.../openapi-ts/src/plugins/valibot/v1/toAst/string.ts 0.00% 1 Missing and 1 partial ⚠️
...es/openapi-ts/src/plugins/zod/mini/toAst/string.ts 0.00% 1 Missing and 1 partial ⚠️
...ages/openapi-ts/src/plugins/zod/v3/toAst/string.ts 0.00% 1 Missing and 1 partial ⚠️
...ages/openapi-ts/src/plugins/zod/v4/toAst/string.ts 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3468      +/-   ##
==========================================
- Coverage   40.11%   40.10%   -0.02%     
==========================================
  Files         478      478              
  Lines       17488    17494       +6     
  Branches     5294     5299       +5     
==========================================
  Hits         7016     7016              
- Misses       8425     8426       +1     
- Partials     2047     2052       +5     
Flag Coverage Δ
unittests 40.10% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 27, 2026

Open in StackBlitz

@hey-api/codegen-core

npm i https://pkg.pr.new/@hey-api/codegen-core@3468

@hey-api/json-schema-ref-parser

npm i https://pkg.pr.new/@hey-api/json-schema-ref-parser@3468

@hey-api/nuxt

npm i https://pkg.pr.new/@hey-api/nuxt@3468

@hey-api/openapi-ts

npm i https://pkg.pr.new/@hey-api/openapi-ts@3468

@hey-api/shared

npm i https://pkg.pr.new/@hey-api/shared@3468

@hey-api/types

npm i https://pkg.pr.new/@hey-api/types@3468

@hey-api/vite-plugin

npm i https://pkg.pr.new/@hey-api/vite-plugin@3468

commit: 748780f

@mrlubos mrlubos merged commit 7ef9332 into main Feb 27, 2026
10 of 17 checks passed
@mrlubos mrlubos deleted the copilot/fix-zod-plugin-regex-unicode branch February 27, 2026 09:43
@hey-api hey-api bot mentioned this pull request Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🔥 Broken or incorrect behavior. lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zod plugin doesn't work with regexes that contain unicode patterns

2 participants