Skip to content

fix(plugin): rank path matchers by per-segment specificity (#1526) - #1546

Merged
sserrata merged 1 commit into
mainfrom
fix/path-specificity-1526
Jul 8, 2026
Merged

sserrata merged 1 commit into
mainfrom
fix/path-specificity-1526

Conversation

@sserrata

@sserrata sserrata commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

Closes #1526.

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 why getPetTagById rendered the summary URL and getPetsSummary rendered 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 #1526 case and existing #1519 case.
  • Visually verify demo pathOrdering pages show the correct URL in code samples for all five operations.

🤖 Generated with Claude Code

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]>
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Size Change: +2.29 kB (+0.1%)

Total Size: 2.36 MB

📦 View Changed
Filename Size Change
demo/.docusaurus/globalData.json 82 kB +316 B (+0.39%)
demo/.docusaurus/registry.js 119 kB +445 B (+0.38%)
demo/.docusaurus/routes.js 112 kB +448 B (+0.4%)
demo/.docusaurus/routesChunkNames.json 46.7 kB +185 B (+0.4%)
demo/build/assets/js/main.********.js 697 kB +800 B (+0.11%)
demo/build/assets/js/runtime~main.********.js 26.8 kB +96 B (+0.36%)
ℹ️ View Unchanged
Filename Size
demo/.docusaurus/codeTranslations.json 2 B
demo/.docusaurus/docusaurus.config.mjs 16.4 kB
demo/.docusaurus/i18n.json 372 B
demo/.docusaurus/site-metadata.json 1.58 kB
demo/build/assets/css/styles.********.css 173 kB
demo/build/index.html 99.5 kB
demo/build/petstore/add-pet/index.html 30 kB
demo/build/petstore/create-user/index.html 24.7 kB
demo/build/petstore/create-users-with-array-input/index.html 24.8 kB
demo/build/petstore/create-users-with-list-input/index.html 24.8 kB
demo/build/petstore/delete-order/index.html 24.5 kB
demo/build/petstore/delete-pet/index.html 24.8 kB
demo/build/petstore/delete-user/index.html 25 kB
demo/build/petstore/find-pets-by-status/index.html 25.5 kB
demo/build/petstore/find-pets-by-tags/index.html 26.2 kB
demo/build/petstore/get-inventory/index.html 23.8 kB
demo/build/petstore/get-order-by-id/index.html 24.8 kB
demo/build/petstore/get-pet-by-id/index.html 25.6 kB
demo/build/petstore/get-user-by-name/index.html 25.1 kB
demo/build/petstore/login-user/index.html 25.6 kB
demo/build/petstore/logout-user/index.html 24.4 kB
demo/build/petstore/new-pet/index.html 25 kB
demo/build/petstore/pet/index.html 23.2 kB
demo/build/petstore/place-order/index.html 24 kB
demo/build/petstore/schemas/apiresponse/index.html 25.2 kB
demo/build/petstore/schemas/cat/index.html 39.4 kB
demo/build/petstore/schemas/category/index.html 26.3 kB
demo/build/petstore/schemas/dog/index.html 39.6 kB
demo/build/petstore/schemas/honeybee/index.html 39.6 kB
demo/build/petstore/schemas/id/index.html 23.4 kB
demo/build/petstore/schemas/order/index.html 27.4 kB
demo/build/petstore/schemas/pet/index.html 39.2 kB
demo/build/petstore/schemas/tag/index.html 24.7 kB
demo/build/petstore/schemas/user/index.html 41.1 kB
demo/build/petstore/store/index.html 22.2 kB
demo/build/petstore/subscribe-to-the-store-events/index.html 30.9 kB
demo/build/petstore/swagger-petstore-yaml/index.html 30.9 kB
demo/build/petstore/update-pet-with-form/index.html 25 kB
demo/build/petstore/update-pet/index.html 25.4 kB
demo/build/petstore/update-user/index.html 25 kB
demo/build/petstore/upload-file/index.html 24.8 kB
demo/build/petstore/user/index.html 22.9 kB

compressed-size-action

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 0903363):

https://docusaurus-openapi-36b86--pr1546-2mnlcj8w.web.app

(expires Wed, 15 Jul 2026 20:16:34 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: bf293780ee827f578864d92193b8c2866acd459f

@sserrata
sserrata merged commit c353fdb into main Jul 8, 2026
12 checks passed
@sserrata
sserrata deleted the fix/path-specificity-1526 branch July 8, 2026 20:38
@sserrata sserrata mentioned this pull request Jul 8, 2026

This branch was previously deployed

1 inactive deployment
preview — 0903363f Deployed Jul 8, 2026 by sserrata via Deploy #2261
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.

Plugin mixes up URLs for same-depth paths ending with static segment vs parameter

1 participant