Skip to content

fix(validation): enforce min/max and length rules on nullable types - #274

Merged
thiamsantos merged 1 commit into
mainfrom
fix/nullable-type-keyword-validation
Sep 10, 2026
Merged

thiamsantos merged 1 commit into
mainfrom
fix/nullable-type-keyword-validation

Conversation

@thiamsantos

@thiamsantos thiamsantos commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

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 type was a union such as ["number", "null"] or ["string", "null"], because validators compared type to a single string and bailed out before running minimum/maximum/multipleOf, minLength/maxLength, or pattern.

Adds schemaTypeIncludes in schema.ts to treat type as either one value or a list and match if any requested type is present; schemas with no type still allow keyword checks (unchanged semantics). validateNumber and validateString use 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.

…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>
@thiamsantos thiamsantos self-assigned this Sep 9, 2026
@thiamsantos
thiamsantos merged commit d42cbc9 into main Sep 10, 2026
6 checks passed
@thiamsantos
thiamsantos deleted the fix/nullable-type-keyword-validation branch September 10, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants