#6988·fastify

compileSerializationSchema passes null for omitted optional metadata

Author: jingkang0822Created Aug 28, 2026Updated Sep 6, 2026

Description

Calling reply.compileSerializationSchema(schema) without optional metadata passes null for both httpStatus and contentType to a custom serializer compiler. The public types model those fields as optional strings, and the documentation describes the default as undefined.

This is present on main at 1beaf7e72d24b2fc63a02a7f5806772a00e45454:

Reproduction

javascript
const Fastify = require('fastify')

const app = Fastify()

app.setSerializerCompiler((definition) => {
  console.log(definition.httpStatus, definition.contentType)
  return JSON.stringify
})

app.get('/', (_request, reply) => {
  const serialize = reply.compileSerializationSchema({ type: 'object' })
  return serialize({ ok: true })
})

app.inject({ method: 'GET', url: '/' })

Actual behavior

The custom compiler receives null, null.

Expected behavior

It should receive undefined, undefined, consistent with the optional TypeScript fields and documented default, or the public type/documentation should explicitly include null.

Possible direction

Default the implementation parameters to undefined (or omit the properties when they were not supplied). This would preserve the existing optional contract for custom compilers.

I found this while benchmarking an automated code-review workflow and manually verified the source path and reproduction before reporting it.