fix(drift): match path segments that mix literal text with parameters - #2994
Open
ariesclark wants to merge 2 commits into
Open
fix(drift): match path segments that mix literal text with parameters#2994ariesclark wants to merge 2 commits into
ariesclark wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 78d0b0b The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
7 tasks
tatomyr
reviewed
Jul 31, 2026
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.
What/Why/How?
Note
This was heavily assisted by Anthropic's Opus 5. I've reviewed the code to the best of my ability, but if there's any obvious issues I didn't catch, let me know.
A path template whose segment mixes literal text with parameters never matched a request.
compileOpenApiPathtested each segment with/^\{([^}]+)\}$/, which recognizes only a segment that is entirely one parameter. Anything else, such as two parameters or a parameter beside literal text, fell through toescapeRegexand became a literal. So/instances/{worldId}:{instanceId}matched only a URL containing that raw text, which no request carries.driftreported those requests as undocumented andcoverageleft them out of its figures.The compiler now scans each segment for
\{([^}]+)\}, escapes the literal runs between matches, and emits([^/]+?)per parameter. Non-greedy is deliberate: with two parameters around a separator, the first must stop at the first occurrence rather than swallow to the last.Specificity scoring gains a middle tier. A pure literal still scores
+2and a bare parameter0, with+1for a segment holding both. The counter reads a per-segmentparamsBeforesnapshot, becauseparamsaccumulates across the whole template.Reference
None.
Testing
compile-openapi-path.test.tscovers single-parameter segments, the/boundary, two parameters in one segment, a multi-parameter segment with a following suffix, the first-separator split when the trailing value holds another separator, score ordering, and pure literals.Against a 140-exchange capture,
drift's false "undocumented endpoint" reports went from 3 to 0 andcoveragerose from 87 to 90 operations.driftnow validates the three newly matched responses.Check yourself
Security
The change only widens which documented paths a recorded request can match, and adds no new input handling.
Note
Low Risk
Localized regex compilation fix with broad test coverage; it only expands which documented paths match traffic and does not add new input surfaces.
Overview
compileOpenApiPathno longer treats only whole-segment{param}templates as parameters. Segments like/instances/{worldId}:{instanceId}are compiled by scanning each{name}, escaping literal runs, and emitting non-greedy([^/]+?)captures so the first parameter stops at the first separator.driftandcoveragecan therefore match recorded traffic to those documented routes instead of flagging them undocumented or omitting them from coverage. Specificity scoring adds +1 for mixed literal/parameter segments (between pure literals +2 and bare parameters 0).New unit tests in
compile-openapi-path.test.tscover multi-parameter segments, separator boundaries, suffix paths, and score ordering. Changeset documents the patch for@redocly/cli.Reviewed by Cursor Bugbot for commit f7237de. Bugbot is set up for automated code reviews on this repo. Configure here.