Skip only the offending area when a locator entry is unusable - #35
Merged
Conversation
matchesByRouteName() returned false as soon as a locator entry was not a RouteCollection, abandoning every area after it. A single unusable entry therefore made routes in later areas look like non-API routes, silently turning off request validation and RFC 7807 error responses for them. Continue past the bad entry instead. testNonRouteCollectionServiceCausesFalse asserted the old behaviour with a fixture whose route sat in the very area that went unchecked; it now asserts the route is found, with a companion test keeping false for a locator that offers nothing usable at all.
|
Warning Review limit reachedNext included review available in 5 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #33 and #34 — spotted while reviewing those.
Problem
NelmioAreaRoutesChecker::matchesByRouteName()bailed out of the whole loop when a locator entry was not aRouteCollection:Areas are iterated in locator order, so one unusable entry hides every area after it. Routes in those areas would be reported as non-API, silently disabling OpenAPI request validation and RFC 7807 error responses for them.
Reachability — this is a defensive path, not a live bug
Checked against Nelmio 5.8:
nelmio_api_doc.routes.{area}is always aRouteCollection, on both branches ofNelmioApiDocExtension:Definition(RouteCollection::class)with factory[router, 'getRouteCollection']register(..., RouteCollection::class)with aFilteredRouteCollectionBuilder::filterfactoryCollectNelmioApiDocRoutesPassalso skips areas whose service is missing, so the locator only ever holds services that exist. Reaching the guard means someone has replaced or decoratednelmio_api_doc.routes.{area}with a non-RouteCollection— possible, but not something a stock setup hits.So this is hardening a defensive branch, not fixing user-visible breakage. Merge it on the strength of the test change rather than any urgency.
Change
continuepast the offending entry so the remaining areas are still checked. Kept as skip-and-continue rather than throwing: the guard is unreachable in normal operation, and turning an exotic-but-working setup into a hard failure is not worth it here.Tests
The more valuable half.
testNonRouteCollectionServiceCausesFalseasserted the old behaviour, and its fixture is the bug in miniature:would_matchsits in the second area, the first entry is unusable, and the test assertedfalse— locking in a wrong invariant under a name that read as intentional. It now asserts the route is found, and is renamed to say what it covers.Added
testUnusableAreasAloneStillReturnFalseso the genuinefalsepath stays pinned when nothing usable is on offer.Verified the updated test fails against the old
return false. 224 tests pass; PHPStan max and PHP-CS-Fixer clean.