-
-
Notifications
You must be signed in to change notification settings - Fork 272
fix(valibot): generate v.record() for additionalProperties with typed schemas #2870
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
Conversation
|
|
🦋 Changeset detectedLatest commit: da88dd9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…h types
Fixed the Valibot plugin to correctly handle additionalProperties with type definitions. Now generates v.record() instead of v.object({}) to prevent silent data loss.
- Modified object.ts to check for any additionalProperties.type (not just 'object')
- Objects with only additionalProperties: generate v.record(v.string(), <valueSchema>)
- Objects with properties AND additionalProperties: generate v.objectWithRest({properties}, <valueSchema>)
Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Updated test snapshots to reflect the corrected behavior for additionalProperties. The fix now properly generates: - v.record() for objects with only additionalProperties - v.objectWithRest() for objects with both properties and additionalProperties This correctly handles free-form objects per OpenAPI spec defaults. Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2870 +/- ##
==========================================
- Coverage 30.59% 30.58% -0.02%
==========================================
Files 488 488
Lines 39938 39953 +15
Branches 2442 2442
==========================================
Hits 12219 12219
- Misses 27685 27700 +15
Partials 34 34
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
commit: |
The Valibot plugin generates
v.object({})foradditionalPropertieswith type definitions, causing silent data loss as Valibot strips unknown keys by default.Changes
Modified
packages/openapi-ts/src/plugins/valibot/v1/toAst/object.ts:additionalPropertieswith a schema, not justtype: 'object'additionalProperties→v.record(v.string(), <valueSchema>)additionalProperties→v.objectWithRest(<properties>, <valueSchema>)Added test coverage:
Example
Before:
After:
Breaking Change
Updates 9 snapshots. Free-form objects (
additionalProperties: trueor{}) now generatev.record(v.string(), v.unknown())instead ofv.object({}), aligning with OpenAPI semantics. Users relying on automatic key stripping will need to explicitly useadditionalProperties: false.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.