Skip to content

fix: validators enum default#3982

Open
mrlubos wants to merge 1 commit into
mainfrom
fix/enum-default-validators
Open

fix: validators enum default#3982
mrlubos wants to merge 1 commit into
mainfrom
fix/enum-default-validators

Conversation

@mrlubos
Copy link
Copy Markdown
Member

@mrlubos mrlubos commented May 31, 2026

Closes #3937

@bolt-new-by-stackblitz
Copy link
Copy Markdown

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

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 31, 2026

🦋 Changeset detected

Latest commit: 11f9324

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

This PR includes changesets to release 4 packages
Name Type
@hey-api/codegen-core Patch
@hey-api/shared Patch
@hey-api/openapi-ts Patch
@hey-api/openapi-python 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
Copy Markdown

vercel Bot commented May 31, 2026

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

Project Deployment Actions Updated (UTC)
web Ready Ready Preview, Comment Jun 1, 2026 5:29pm

Request Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 31, 2026

Open in StackBlitz

@hey-api/codegen-core

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

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

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

@hey-api/nuxt

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

@hey-api/openapi-ts

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

@hey-api/shared

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

@hey-api/spec-types

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

@hey-api/types

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

@hey-api/vite-plugin

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

commit: 11f9324

@codecov
Copy link
Copy Markdown

codecov Bot commented May 31, 2026

Codecov Report

❌ Patch coverage is 27.27273% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.14%. Comparing base (c054355) to head (1db79f5).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
packages/shared/src/config/input/path.ts 0.00% 3 Missing and 4 partials ⚠️
packages/openapi-ts/src/createClient.ts 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3982      +/-   ##
==========================================
- Coverage   39.15%   39.14%   -0.01%     
==========================================
  Files         607      607              
  Lines       21473    21480       +7     
  Branches     6337     6341       +4     
==========================================
+ Hits         8408     8409       +1     
- Misses      10640    10642       +2     
- Partials     2425     2429       +4     
Flag Coverage Δ
unittests 39.14% <27.27%> (-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.

Copy link
Copy Markdown
Contributor

@pullfrog pullfrog Bot left a comment

Choose a reason for hiding this comment

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

Important

The PR title promises a fix for validators enum default emission, but the actual zod/valibot plugin code changes are missing. The diff adds test fixtures and refactors logging, but no validator plugin files are modified.

Reviewed changes — The PR prepares test fixtures for enum defaults and refactors input logging, but the core fix for zod/valibot .default() emission when TypeScript enums are used is not yet present.

  • Add default values to enum test specs — Updates enum-names-values.json specs across 2.0.x, 3.0.x, and 3.1.x to include default on string and number enums.
  • Convert 3.1.x enum test spec from YAML to JSON — Changes test input format and updates 3.1.x.test.ts references.
  • Add enums: 'javascript' to validated dev preset — Changes the @hey-api/typescript plugin config in the validated preset to use JavaScript enums instead of TypeScript enums.
  • Refactor input path logging — Moves log level handling into logInputPaths, adds debug URL output, and adds uuid support for ReadMe registry inputs.
  • Add raw spec and readme inputs to dev config — Expands development input options.

⚠️ Core fix is missing

The diff does not touch any zod or valibot plugin source files. Issue #3937 describes a type error where z.enum(TsEnum).optional().default('RED') fails because 'RED' is not assignable to the TypeScript enum type Color. The fix requires updating the default value emission in the validator plugins to output enum member references (e.g., Color.RED) instead of bare literals when the enum is rendered as z.enum(TsEnum).

The affected code paths are likely:

  • packages/openapi-ts/src/plugins/zod/v4/visitor.tsgetDefaultValue() and applyModifiers()
  • packages/openapi-ts/src/plugins/zod/v3/visitor.ts — same pattern
  • packages/openapi-ts/src/plugins/zod/mini/visitor.ts — same pattern
  • packages/openapi-ts/src/plugins/valibot/v1/visitor.tsgetDefaultValue() and applyModifiers()

Additionally, the test fixtures add default directly to the enum schema definitions, but the reported bug is specifically about a property that $refs an enum schema and specifies a default on the referencing property. The fixtures should include that scenario to properly regression-test the fix.

ℹ️ Nitpicks

  • The logging refactor and input config changes (uuid, raw, readme) are unrelated to the enum default fix. Consider splitting them into a separate PR to keep the history clean.
  • Changing the validated preset to enums: 'javascript' avoids the bug in dev but does not fix it for users who use TypeScript enums. If this is intentional as a temporary workaround, it should be called out in the PR description.

Pullfrog  | Fix it ➔View workflow run | Using Kimi K2𝕏

@mrlubos mrlubos force-pushed the fix/enum-default-validators branch from 1db79f5 to 11f9324 Compare June 1, 2026 17:26
@mrlubos mrlubos marked this pull request as ready for review June 1, 2026 17:27
@pullfrog
Copy link
Copy Markdown
Contributor

pullfrog Bot commented Jun 1, 2026

  • Checkout PR fix: validators enum default #3982 and read diff
  • Triage PR: understand what it does, what domain it touches
  • Decide on lens approach (0 or 2+)
  • Execute review: either self-review or fan-out lenses
  • Aggregate findings and submit review

Pullfrog  | View workflow run | via Pullfrog | Using Kimi K2𝕏

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. bug 🔥 Broken or incorrect behavior. labels Jun 1, 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. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zod v4: .default(...) on enum fields emits a bare string literal that is not assignable to the referenced TS enum (regression in 0.97.2)

1 participant