-
-
Couldn't load subscription status.
- Fork 281
fix: Treat undefinedable like other "optional"-ish schemas
#1319
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
base: main
Are you sure you want to change the base?
fix: Treat undefinedable like other "optional"-ish schemas
#1319
Conversation
There was a problem hiding this 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 undefinedable schemas were not being treated consistently with other "optional"-ish schemas (optional and nullish) throughout the Valibot codebase. The issue was that undefinedable schemas were being incorrectly marked as required fields in object validation and JSON schema conversion.
- Adds
undefinedabletype checks alongside existingoptionalandnullishchecks - Updates object schema validation logic to properly handle undefinedable fields
- Fixes JSON schema conversion to correctly mark undefinedable properties as non-required
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/to-json-schema/src/converters/convertSchema/convertSchema.ts | Updates JSON schema conversion to exclude undefinedable fields from required properties |
| library/src/schemas/variant/variantAsync.ts | Adds undefinedable check to discriminator validation logic |
| library/src/schemas/variant/variant.ts | Adds undefinedable check to discriminator validation logic |
| library/src/schemas/strictObject/strictObjectAsync.ts | Updates strict object validation to handle undefinedable fields properly |
| library/src/schemas/strictObject/strictObject.ts | Updates strict object validation to handle undefinedable fields properly |
| library/src/schemas/objectWithRest/objectWithRestAsync.ts | Updates object with rest validation to handle undefinedable fields properly |
| library/src/schemas/objectWithRest/objectWithRest.ts | Updates object with rest validation to handle undefinedable fields properly |
| library/src/schemas/object/objectAsync.ts | Updates object validation to handle undefinedable fields properly |
| library/src/schemas/object/object.ts | Updates object validation to handle undefinedable fields properly |
| library/src/schemas/looseObject/looseObjectAsync.ts | Updates loose object validation to handle undefinedable fields properly |
| library/src/schemas/looseObject/looseObject.ts | Updates loose object validation to handle undefinedable fields properly |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Hey, this is not a bug. We currently offer
|
|
Thanks for the quick response @fabian-hiller . To be honest, I wasn't sure if it was the right change or not. I will say, at the very least it seems like the documentation around undefinedable may be misleading? Specifically about "behaves exactly the same as optional at runtime" ... As demonstrated by this playground vs the original playground. For some context, my goal was to achieve the behavior described in this line. I wanted |
This is outdated and we forgot to update it! Sorry! We should get this right!
You could write |

I don't think
undefinedableis working as intended based on my understanding - here's aPlayground demonstrating the issue.
This PR goes through and adds a check for
undefinedablein the places thatoptionalornullishare modifying behavior.