Skip to content

Conversation

@edenoscherer
Copy link
Contributor

Fix error when controller has no mapped methods

Description

This PR fixes an issue in the getRouteInfo function in src/debug.ts where an error would occur when processing controllers that don't have any mapped methods. The fix ensures that methodMetadata is always treated as an array by providing a fallback empty array when it's undefined.

Related Issue

No existing issue was found for this bug, but the error occurs when trying to call .map() on undefined methodMetadata for controllers without HTTP method decorators.

Motivation and Context

When using the debug utilities to inspect routes in an application with controllers that don't have any HTTP methods mapped (perhaps they're abstract base controllers or controllers in development), the getRouteInfo function would throw an error. This fix makes the function more robust by handling this edge case properly.

How Has This Been Tested?

I've added a specific test case in the test suite that verifies the function can handle controllers without any mapped methods. The test creates a container with an empty controller (no HTTP methods) and ensures that getRouteInfo returns the expected structure with an empty endpoints array for that controller.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my change

Copy link
Member

@notaphplover notaphplover left a comment

Choose a reason for hiding this comment

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

lgtm! Add the changes to the changelog please and we're ready to merge it

@notaphplover notaphplover self-requested a review April 29, 2025 23:27
@notaphplover notaphplover merged commit 6e152da into inversify:master Apr 29, 2025
4 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