Repository navigation
fix(plugin): rank path matchers by per-segment specificity (#1526) - #1546
Merged
Merged
Conversation
The #1519 fix ordered fully-static paths ahead of any-params paths, but treated all parametric paths as equal. When two same-depth paths differ only in a trailing static vs. parameter segment (e.g. `/pet/{petIds}/summary` vs. `/pet/{petId}/{tagId}`), the anchored regex `^/pet/[^/]+/[^/]+$` still matched the summary Postman path first, stealing the binding and leaving the summary operation with no request URL. Replace the hasParams boolean sort with a per-segment specificity ranking: literal segments (1) sort ahead of parameter segments (0), compared left-to-right. Anchored regexes only cross-match when segment counts are equal, so this fully disambiguates the failure case while preserving the #1519 behavior (fully-static paths still come first). Adds a regression test mirroring the #1526 reproduction, and extends the pathOrdering demo spec with the two colliding same-depth paths for visual verification. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Size Change: +2.29 kB (+0.1%) Total Size: 2.36 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Visit the preview URL for this PR (updated for commit 0903363): (expires Wed, 15 Jul 2026 20:16:34 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: bf293780ee827f578864d92193b8c2866acd459f |
Merged
This branch was previously deployed
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.
Summary
Closes #1526.
hasParamssort inbindCollectionToApiItemswith a per-segment specificity ranking (literal segments beat parameter segments at the same position)./pet/{petId},/pet/{petId}/{tagId},/pet/{petIds}/summary).demo/examples/tests/pathOrdering.yamlwith the two colliding same-depth paths for visual verification.Why the #1520 fix was insufficient
The prior sort only distinguished paths with any parameters from paths with none. Among paths that all have parameters, ordering was source-defined. Given the three #1526 paths,
/pet/:petIds/summary(from Postman) matches both^/pet/[^/]+/[^/]+$and^/pet/[^/]+/summary$, and the first one wins the binding — which is whygetPetTagByIdrendered the summary URL andgetPetsSummaryrendered no path at all.Anchored regexes can only cross-match when segment counts are equal, so ranking by per-segment specificity (literal > parameter, compared left-to-right) is sufficient to disambiguate.
Test plan
yarn jest packages/docusaurus-plugin-openapi-docs/src/openapi/openapi.test.ts— 6/6 pass, including new#1526case and existing#1519case.pathOrderingpages show the correct URL in code samples for all five operations.🤖 Generated with Claude Code