这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 17, 2025

The Zod plugin was incorrectly deduplicating schemas with different validation constraints when using anyOf, resulting in incomplete union schemas. For example:

{
  "anyOf": [
    {
      "type": "string",
      "minLength": 5,
      "maxLength": 5,
      "description": "Combination of ISO 639-1 and ISO 3166-1 alpha-2 separated by a hyphen."
    },
    {
      "type": "string",
      "minLength": 2,
      "maxLength": 2,
      "description": "ISO 639-1 language code."
    }
  ]
}

Before this fix:

export const zLocaleOrLanguage = z.string().length(5);

After this fix:

export const zLocaleOrLanguage = z.union([
    z.string().length(5),
    z.string().length(2)
]);

The issue was in the deduplicateSchema function which only considered $ref, type, const, and format when creating type identifiers, but ignored validation constraints like minLength, maxLength, minimum, maximum, pattern, etc. This caused schemas with different constraints to be treated as duplicates and incorrectly merged.

The fix enhances the type identification logic to include all validation constraints, ensuring that schemas with different validation rules are properly preserved in unions.

Changes:

  • Modified packages/openapi-ts/src/ir/schema.ts to include validation constraints in type ID generation
  • Added comprehensive test case validators-string-constraints-union.json to prevent regression
  • Verified compatibility across all Zod versions (v3, v4, mini)
  • Added changeset file for patch release

Fixes #2644.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link
Contributor Author

Copilot AI commented Sep 17, 2025

@mrlubos 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

@vercel
Copy link

vercel bot commented Sep 17, 2025

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

Project Deployment Preview Comments Updated (UTC)
hey-api-docs Ready Ready Preview Comment Sep 17, 2025 2:52pm

@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 Sep 17, 2025

🦋 Changeset detected

Latest commit: 8bd26d5

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

…s in type ID

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copilot AI changed the title [WIP] The generated Zod schema can be incorrect Fix Zod schema union deduplication by including validation constraints in type ID Sep 17, 2025
Copilot AI requested a review from mrlubos September 17, 2025 13:52
Copilot finished work on behalf of mrlubos September 17, 2025 13:52
@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 17, 2025

Open in StackBlitz

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/codegen-core@2650
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/nuxt@2650
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/openapi-ts@2650
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@2650

commit: 8bd26d5

@codecov
Copy link

codecov bot commented Sep 17, 2025

Codecov Report

❌ Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 23.83%. Comparing base (91bc2d0) to head (8bd26d5).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
packages/openapi-ts/src/ir/schema.ts 87.50% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2650      +/-   ##
==========================================
+ Coverage   23.81%   23.83%   +0.02%     
==========================================
  Files         379      379              
  Lines       36945    36960      +15     
  Branches     1623     1632       +9     
==========================================
+ Hits         8798     8811      +13     
- Misses      28134    28136       +2     
  Partials       13       13              
Flag Coverage Δ
unittests 23.83% <87.50%> (+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.

@mrlubos mrlubos marked this pull request as ready for review September 17, 2025 14:02
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug 🔥 Something isn't working labels Sep 17, 2025
@mrlubos
Copy link
Member

mrlubos commented Sep 17, 2025

@copilot add a changeset file with patch for the modified package. You can have a look at past releases or commits for the desired format. I'll let you know if I want any further changes

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

Copilot AI commented Sep 17, 2025

@copilot add a changeset file with patch for the modified package. You can have a look at past releases or commits for the desired format. I'll let you know if I want any further changes

Added changeset file with patch version bump for @hey-api/openapi-ts package in commit 31b3933. The changeset documents the Zod union deduplication fix and follows the standard format used in this repository.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 17, 2025
@mrlubos mrlubos merged commit 10c13de into main Sep 17, 2025
17 checks passed
@mrlubos mrlubos deleted the copilot/fix-2644 branch September 17, 2025 15:20
This was referenced Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🔥 Something isn't working lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The generated Zod schema can be incorrect

2 participants