Skip to content

docs: clarify anyOf nullable coercion behavior with primitive types#6531

Merged
mcollina merged 1 commit intofastify:mainfrom
slegarraga:fix/nullable-number-zero
Feb 28, 2026
Merged

docs: clarify anyOf nullable coercion behavior with primitive types#6531
mcollina merged 1 commit intofastify:mainfrom
slegarraga:fix/nullable-number-zero

Conversation

@slegarraga
Copy link
Copy Markdown
Contributor

When type coercion is enabled, using anyOf with a null type before a primitive type (number, boolean) causes Ajv to coerce falsy values like 0 and false to null. This documents the pitfall and recommends using the nullable keyword instead.

Fixes #6411

This picks up where #6429 left off (which was closed after an accidental merge/revert).

Checklist

When type coercion is enabled, using anyOf with a null type before a
primitive type (number, boolean) causes Ajv to coerce falsy values like
0 and false to null. Document this pitfall and recommend using the
nullable keyword instead.

Fixes fastify#6411
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Feb 25, 2026
Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit 8fad072 into fastify:main Feb 28, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validation of optional, nullable number where property value is 0 will default to null

2 participants