Skip to content

fix: don't let route defaults override global options on partial route config - #448

Merged
mcollina merged 1 commit into
fastify:mainfrom
Cdineshreddy12:fix/partial-route-options-merge
Nov 22, 2026
Merged

mcollina merged 1 commit into
fastify:mainfrom
Cdineshreddy12:fix/partial-route-options-merge

Conversation

@Cdineshreddy12

Copy link
Copy Markdown
Contributor

Closes #340

Picking this up since it's been open a while and the PR that was asked for never arrived.

The problem is where the merge happens. processCompressParams() / processDecompressParams() fill in a default for every option that isn't set, so by the time the route params get merged over the global params in the onRoute hook, there's no way to tell "the route chose this value" apart from "that's just the default". The route's defaults then clobber explicitly configured global options — in the reported case a global onInvalidRequestPayload disappears as soon as a route sets only onUnsupportedRequestEncoding in its decompress config.

So instead of merging the two processed objects, this merges the raw route options over the raw plugin options and processes the result once — same way the global params themselves are built. A route override still wins per key, everything the route doesn't mention keeps the global behavior.

Added one test for each side (compress and decompress) reproducing the report: global handler/flag plus a route that overrides a single different option. Both fail on main and pass with the fix. Full suite and type tests pass.

Checklist

…e config

When a route defined partial compress/decompress options, the processed
route params were merged over the processed global params. Since
processCompressParams/processDecompressParams fill in defaults for every
option that is not set, those defaults silently replaced explicitly
configured global options (e.g. a global onInvalidRequestPayload was
lost when a route only set onUnsupportedRequestEncoding).

The raw route options are now merged over the raw plugin options before
processing, so a route override wins per key and everything else keeps
the global configuration.

Fixes fastify#340

@mcollina mcollina 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

@mcollina
mcollina merged commit 868cecc into fastify:main Nov 22, 2026
19 checks passed
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.

global options are not taked into account when route options are defined partially

2 participants