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

Conversation

@malcolm-kee
Copy link
Contributor

@malcolm-kee malcolm-kee commented Aug 21, 2025

The generated types for OpenAPI 3.1.x spec is incorrect when the schema type is an array of primitive.

  • I've added the test to illustrate the bug.
  • The first commit illustrate the bug (check the generated snapshot), the second commit is the fix.

@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 Aug 21, 2025

🦋 Changeset detected

Latest commit: ac7efbf

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 Aug 21, 2025

@malcolm-kee is attempting to deploy a commit to the Hey API Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug 🔥 Something isn't working labels Aug 21, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 21, 2025

Open in StackBlitz

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

commit: ac7efbf

@codecov
Copy link

codecov bot commented Aug 21, 2025

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 24.13%. Comparing base (63e60f0) to head (ac7efbf).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...ages/openapi-ts/src/openApi/3.1.x/parser/schema.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2502   +/-   ##
=======================================
  Coverage   24.13%   24.13%           
=======================================
  Files         342      342           
  Lines       33874    33874           
  Branches     1454     1454           
=======================================
  Hits         8174     8174           
  Misses      25690    25690           
  Partials       10       10           
Flag Coverage Δ
unittests 24.13% <0.00%> (ø)

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.

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 for the fix @malcolm-kee! This is a ridiculously clean pull request. But... how come it fixes things? I'm going to assume there was some mutation happening on the object if it wasn't shallow copied, can you explain?

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 21, 2025
if (type === 'null') {
schemaItems.push({ type: 'null' });
} else {
const irTypeSchema = parseOneType({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

parseOneType would mutate the irSchema passed to it, which causes the object pushed to schemaItems all having the same type.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for explaining! Weird I haven't caught this before, glad you did

@malcolm-kee
Copy link
Contributor Author

@mrlubos that's right. I assume the code is written this way for performance reason?

@mrlubos
Copy link
Member

mrlubos commented Aug 21, 2025

@malcolm-kee that's right!

@mrlubos mrlubos merged commit 6931b9c into hey-api:main Aug 21, 2025
11 of 13 checks passed
@github-actions github-actions bot mentioned this pull request Aug 21, 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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants