Skip to content

fix: fixes hideEmpty not returning routes when no filter is provided#183

Merged
Eomm merged 3 commits into
Eomm:mainfrom
edge33:main
Feb 25, 2026
Merged

fix: fixes hideEmpty not returning routes when no filter is provided#183
Eomm merged 3 commits into
Eomm:mainfrom
edge33:main

Conversation

@edge33

@edge33 edge33 commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

Fix: hideEmpty dropping routes when no routesFilter is provided

Problem

When calling app.overview({ hideEmpty: true }) without a routesFilter, all routes were silently dropped from the output — even when routes existed on the encapsulation context.

The root cause is in the handleRoutes function in lib/utils.js. This function is called from the JSON.stringify replacer inside filterStructure. The previous code had two branches:

  1. If opts.routesFilter is set, filter and return the routes (or undefined if the filtered result is empty and hideEmpty is on).
  2. If opts.hideEmpty is set and value.length === 0, return undefined.

When hideEmpty: true was set but no routesFilter was provided, and the routes array was non-empty, the function fell through both branches without hitting any return statement — implicitly returning undefined. Since JSON.stringify omits keys whose replacer returns undefined, the routes property was stripped from the output entirely.

Fix

Added an explicit return of the routes array when it is non-empty and no routesFilter is provided:

if (opts.hideEmpty && value.length === 0) {
  return undefined
}
if (value.length) {
  return value
}

This ensures the handleRoutes function covers all code paths:

routesFilter Routes exist hideEmpty Result before fix Result after fix
yes yes (after filter) any routes returned routes returned
yes no (after filter) true undefined undefined
no yes true undefined (bug) routes returned
no no true undefined undefined
no yes false undefined (bug) routes returned

Example

const app = fastify({ exposeHeadRoutes: false })
await app.register(fastifyOverview)

app.get('/get', function noop () {})
app.get('/post', function noop () {})

await app.ready()
const root = app.overview({ hideEmpty: true })

// Before fix: root.routes === undefined
// After fix:
root.routes
// [
//   { method: 'GET', prefix: '', url: '/get' },
//   { method: 'GET', prefix: '', url: '/post' }
// ]

Test coverage

Added a dedicated test case ('hide empty with no routes filter') that registers routes on the root instance, calls app.overview({ hideEmpty: true }) without a routesFilter, and asserts the routes are present in the output.

Comment thread package.json Outdated

@Eomm Eomm left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

windows + node20 nevermind

@Eomm Eomm merged commit 88e2bdb into Eomm:main Feb 25, 2026
13 of 14 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.

2 participants