Skip to content

fix: omit absent compileSerializationSchema metadata instead of passing null - #7001

Merged
gurgunday merged 1 commit into
fastify:mainfrom
Kjubikstronk:compile-serialization-undefined-metadata
Sep 26, 2026
Merged

gurgunday merged 1 commit into
fastify:mainfrom
Kjubikstronk:compile-serialization-undefined-metadata

Conversation

@Kjubikstronk

Copy link
Copy Markdown
Contributor

Closes #6988.

compileSerializationSchema defaulted both optional parameters to null:

function (schema, httpStatus = null, contentType = null)

so a custom serializer compiler called through reply.compileSerializationSchema(schema) received null for both. FastifyRouteSchemaDef declares them as optional strings and the reference docs describe the default as undefined, so the implementation was the odd one out. serializeInput already declares the same two parameters without defaults and forwards undefined, so this also makes the two paths agree.

Dropping the defaults is the whole change. Existing tests that touch this assert !httpStatus rather than a specific value, so they hold either way, and I could not find anywhere in lib, test or types that compares this to null.

Added one test asserting both values arrive as undefined when the metadata is not supplied. It fails without the change.

Verified locally: node --test test/internals/*.test.js gives 395 passed / 0 failed, npm run test:types passes all 16 files and 1282 assertions, and eslint is clean on both touched files.

I left a separate note on #6987 about the cache-keying half, since fixing that one has a public API consequence for getSerializationFunction and I would rather agree the approach first.

@gurgunday gurgunday left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@gurgunday gurgunday added the bugfix Issue or PR that should land as semver patch label Sep 26, 2026
@gurgunday
gurgunday merged commit c3051e5 into fastify:main Sep 26, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Issue or PR that should land as semver patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compileSerializationSchema passes null for omitted optional metadata

3 participants