Skip to content

Conversation

@sruenwg
Copy link
Contributor

@sruenwg sruenwg commented Jun 8, 2025

This PR fixes convertSchema to no longer mark exactOptional object properties as required properties in the output JSON Schema.
See playground example{} is clearly a valid value according to the schema, but the generated JSON Schema would reject this as it requires the k2 property.

@vercel
Copy link

vercel bot commented Jun 8, 2025

@sruenwg is attempting to deploy a commit to the Valibot Team on Vercel.

A member of the Team first needs to authorize it.

@fabian-hiller fabian-hiller self-assigned this Jun 9, 2025
@fabian-hiller fabian-hiller added the fix A smaller enhancement or bug fix label Jun 9, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 9, 2025

Open in StackBlitz

npm i https://pkg.pr.new/valibot@1220

commit: 2595f60

@fabian-hiller
Copy link
Member

Thank you for your contribution! Not sure how we could miss that. I will merge it before releasing the next version of the package.

@fabian-hiller fabian-hiller added the priority This has priority label Jun 9, 2025
@sruenwg
Copy link
Contributor Author

sruenwg commented Jun 9, 2025

Thanks! 👍

@fabian-hiller fabian-hiller added this to the v1.4 (to-json-schema) milestone Jun 11, 2025
@fabian-hiller fabian-hiller requested a review from Copilot December 3, 2025 02:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where exactOptional object properties were incorrectly marked as required in the generated JSON Schema output. The fix ensures that exactOptional is treated the same way as optional and nullish properties, allowing objects to be valid even when these properties are absent.

Key Changes:

  • Added exact_optional check to the condition that determines required properties in object schemas
  • Updated test cases to include exactOptional properties and verify they are not marked as required

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/to-json-schema/src/converters/convertSchema/convertSchema.ts Added exact_optional type check to exclude exactOptional properties from the required array
packages/to-json-schema/src/converters/convertSchema/convertSchema.test.ts Enhanced tests for object, objectWithRest, looseObject, and strictObject schemas to include exactOptional properties and verify correct handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fabian-hiller fabian-hiller merged commit 227978d into open-circle:main Dec 3, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix A smaller enhancement or bug fix priority This has priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants