Repository navigation
fix(validation): enforce min/max and length rules on nullable types - #274
Merged
Merged
Conversation
…g types validateNumber and validateString guarded on schema.type being equal to a single type name. When the type is a list such as ["number", "null"], the comparison fails and minimum, maximum, multipleOf, exclusiveMinimum, exclusiveMaximum, minLength, maxLength and pattern are never checked. Add schemaTypeIncludes, which normalises the type to a list, and use it in both validators. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
brennj
approved these changes
Sep 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The number validator first checks that schema.type equals 'number'. For a nullable field type is the list ["number", "null"], which never equals a string, so min/max checks are skipped entirely.
How
The guard now normalises schema.type to a list and asks whether it includes 'number' or 'integer' (or 'string'), so nullable types pass the check and the keyword validations run.
Note
Low Risk
Targeted validation guard change with tests; behavior only changes for multi-type schemas that include null, fixing incorrect skips rather than loosening unrelated rules.
Overview
Fixes a bug where numeric and string keyword validations were skipped when
typewas a union such as["number", "null"]or["string", "null"], because validators comparedtypeto a single string and bailed out before runningminimum/maximum/multipleOf,minLength/maxLength, orpattern.Adds
schemaTypeIncludesinschema.tsto treattypeas either one value or a list and match if any requested type is present; schemas with notypestill allow keyword checks (unchanged semantics).validateNumberandvalidateStringuse this helper instead of ad hoc type checks.Tests cover nullable number and string schemas end-to-end (including form validation for strings).
Reviewed by Cursor Bugbot for commit 0933c69. Bugbot is set up for automated code reviews on this repo. Configure here.