Skip to content

fix(printRoutes): ensure commonPrefix: false returns uncompressed flat routes #6275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

riyap03
Copy link

@riyap03 riyap03 commented Aug 1, 2025

Thank you for reviewing my pull request! ✨

This PR fixes the unintuitive behavior of fastify.printRoutes({ commonPrefix: false }), which was expected to print routes without any prefix grouping — but still compressed longer prefixes. That was confusing for users (like me 😅).

So I’ve added a custom printRoutes logic that ensures this flag works as expected — showing all routes in a flat structure with no compression when commonPrefix: false.

🛠️ Fixes: Issue #6009

This is my third PR to Fastify 💙 and part of my journey toward GSoC 2026. I'm learning deeply and I'm grateful for the opportunity to grow and contribute to such a wonderful project 🌱.


Checklist

  • I ran npm run test and all tests pass
  • No benchmark changes needed
  • No documentation updates needed
  • Commit message and code follow Fastify guidelines

Let me know if anything needs to be changed or improved! 💫

Copy link
Member

@jean-michelet jean-michelet left a comment

Choose a reason for hiding this comment

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

I think the linked issue should be transferred to the find-my-way package, if relevant.

eslint.config.js Outdated
@@ -13,7 +13,8 @@ module.exports = [
}),
{
rules: {
'comma-dangle': ['error', 'never']
'comma-dangle': ['error', 'never'],
'max-len': ['error', { code: 100 }]
Copy link
Member

Choose a reason for hiding this comment

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

Why do you add this here?

Copy link
Author

Choose a reason for hiding this comment

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

Why do you add this here?
Thanks for the question! I had originally added this change in a separate PR to address issue #6029 — but it accidentally got included here while rebasing 😅

I’ve removed it from this PR now so the scope stays focused on printRoutes. Thanks for catching it! 🙏

return router.prettyPrint(opts)
}

// ✅ fallback to raw list of routes
Copy link
Member

Choose a reason for hiding this comment

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

Avoid emojis plz, this comment is unnecessary.

Copy link
Author

Choose a reason for hiding this comment

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

Avoid emojis plz, this comment is unnecessary.

Thanks for the review!
I just wanted to clarify that the emoji in the code comment wasn’t added by me — perhaps it was already present or added by mistake during a merge.

Still, I’ll go ahead and clean it up along with the other suggestions you gave. Appreciate the feedback! 💙

Copy link
Member

Choose a reason for hiding this comment

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

This is a file you added.

Copy link
Author

Choose a reason for hiding this comment

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

This is a file you added.

You’re absolutely right — I added the file and must’ve overlooked the comment. Sorry for the confusion. I’ve now removed the emoji and cleaned it up. Thanks again for your feedback!

lib/route.js Outdated
Comment on lines 256 to 260





Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

lib/route.js Outdated
Comment on lines 597 to 599



Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

@riyap03 riyap03 force-pushed the fix-printRoutes-behavior branch from ccbb2ee to cde73fe Compare August 2, 2025 10:49
@riyap03
Copy link
Author

riyap03 commented Aug 2, 2025

I think the linked issue should be transferred to the find-my-way package, if relevant.

Thank you for pointing that out! 🙌
You're right — since the route printing logic comes from find-my-way, transferring the issue there sounds reasonable.
Should I go ahead and open a corresponding issue in the find-my-way repo and link it here? Let me know what you'd prefer. 🌱

@metcoder95
Copy link
Member

Can you solve the conflicts you have?

@riyap03
Copy link
Author

riyap03 commented Aug 3, 2025

Can you solve the conflicts you have?

Sure, I’ll get on it and resolve the conflicts soon. Thanks for the nudge!

@riyap03
Copy link
Author

riyap03 commented Aug 3, 2025

Conflicts have been resolved and the branch is now up to date with main! Let me know if there’s anything else needed 💫

@@ -0,0 +1,15 @@
const Fastify = require('fastify')
const t = require('tap')
Copy link
Member

Choose a reason for hiding this comment

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

Please use node:test

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the catch! I’ve updated the test to use node:test instead of tap.

app.js Outdated
Copy link
Member

Choose a reason for hiding this comment

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

What is this file for?

Copy link
Author

Choose a reason for hiding this comment

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

That was just for local testing. I’ve removed it now — thanks for pointing it out!

Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem to test something in particular, maybe let's focus only on test/pretty-print.test.js

Copy link
Author

Choose a reason for hiding this comment

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

You're right — I’ve deleted this file and moved relevant tests into pretty-print.test.js.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Done! I’ve moved all the tests into pretty-print.test.js and deleted this file.

package.json Outdated
@@ -210,6 +210,7 @@
"abstract-logging": "^2.0.1",
"avvio": "^9.0.0",
"fast-json-stringify": "^6.0.0",
"fastify": "^5.4.0",
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Author

Choose a reason for hiding this comment

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

That addition was accidental during local testing. I’ve reverted the package.json changes now.

@riyap03
Copy link
Author

riyap03 commented Aug 6, 2025

Hey! I’ve made all the changes:

switched to node:test

removed app.js and routes-test.js

moved everything into pretty-print.test.js

cleaned up the package.json (thanks for catching that!)

Please let me know if I missed anything. I’m still learning and happy to improve this further 💫
Really grateful for your review and guidance 💙

lib/route.js Outdated
function noop () { }
module.exports = { buildRouting, validateBodyLimitOption }
Copy link
Member

Choose a reason for hiding this comment

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

This seems duplicated

Copy link
Author

Choose a reason for hiding this comment

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

You're right — thanks for catching that! I've removed the duplicated code from lib/route.js in the latest commit. Let me know if there's anything else I should adjust.

Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

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

Sorry for the ping and pong, just notice to smaller things to be fixed, after that it should be good to go

@@ -364,3 +364,31 @@ test('pretty print - includeMeta, includeHooks', (t, done) => {
done()
})
})
// test/printRoutes-commonPrefix.test.js

const assert = require('node:assert')
Copy link
Member

Choose a reason for hiding this comment

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

Let's use the assert that comes with the TestContext (the variable passed to the test callback.

@@ -364,3 +364,31 @@ test('pretty print - includeMeta, includeHooks', (t, done) => {
done()
})
})
// test/printRoutes-commonPrefix.test.js
Copy link
Member

Choose a reason for hiding this comment

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

Feel free to remove it

Copy link
Author

Choose a reason for hiding this comment

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

Hi @metcoder95 ,

Thank you so much for your kindness and patience with my PRs. This is only my second PR ever, and I feel really lucky to have a mentor like you guiding me through every step.

You’re not just helping me fix code — you’re helping me grow, learn, and believe in myself a little more each day. That means more than words can say.

I’m grateful for your time, your thoughtful reviews, and your kindness. I hope to keep learning and making you proud.

With lots of respect and gratitude,
Riya 💙

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.

4 participants