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

fix: zod; handle array union types #2159

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

Merged

Conversation

Joshua-hypt
Copy link
Contributor

@Joshua-hypt Joshua-hypt commented Jun 11, 2025

Fixes #2157

Copy link

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

Copy link

changeset-bot bot commented Jun 11, 2025

🦋 Changeset detected

Latest commit: 99ae4de

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

Copy link

vercel bot commented Jun 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hey-api-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 11, 2025 1:36pm

// TODO: parser - handle union
// return compiler.typeArrayNode(compiler.typeUnionNode({ types: itemExpressions }));
if (schema.logicalOperator === 'or') {
arrayExpression = compiler.callExpression({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as the tests pass this looks good but please add a test like this https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts-tests/test/spec/3.1.x/validators-union-merge.json

You can either tack on another schema to that file or create a separate file altogether and add a new test case. Run pnpm openapi-ts-tests test:update to update snapshots once you've done either of these approaches

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All done! I updated the test you shared with me a bit.

Copy link

pkg-pr-new bot commented Jun 11, 2025

Open in StackBlitz

@hey-api/client-axios

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/client-axios@2159

@hey-api/client-fetch

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/client-fetch@2159

@hey-api/client-next

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/client-next@2159

@hey-api/client-nuxt

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/client-nuxt@2159

@hey-api/nuxt

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

@hey-api/openapi-ts

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

@hey-api/vite-plugin

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@2159

commit: 99ae4de

Copy link

codecov bot commented Jun 11, 2025

Codecov Report

Attention: Patch coverage is 0% with 14 lines in your changes missing coverage. Please review.

Project coverage is 22.49%. Comparing base (01134c5) to head (99ae4de).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
packages/openapi-ts/src/plugins/zod/plugin.ts 0.00% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2159      +/-   ##
==========================================
- Coverage   22.49%   22.49%   -0.01%     
==========================================
  Files         273      273              
  Lines       25496    25504       +8     
  Branches      950      950              
==========================================
  Hits         5736     5736              
- Misses      19754    19762       +8     
  Partials        6        6              
Flag Coverage Δ
unittests 22.49% <0.00%> (-0.01%) ⬇️

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
Copy link
Member

mrlubos commented Jun 11, 2025

@Joshua-hypt I'm not on a computer but see a lot of snapshot changes. Did you verify they're all correct?

Copy link
Member

@mrlubos mrlubos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks good now! Assuming you want to remove the comment let's do that and it can be released

}),
],

// compiler.callExpression({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a dead code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 my bad

@Joshua-hypt Joshua-hypt requested a review from mrlubos June 11, 2025 13:34
Copy link
Member

@mrlubos mrlubos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@mrlubos mrlubos merged commit 66fecce into hey-api:main Jun 11, 2025
15 of 17 checks passed
@github-actions github-actions bot mentioned this pull request Jun 11, 2025
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.

Zod schema generates unknown for union type
2 participants