fix(procedures): fix exact procedure matching#101
Open
jonluca wants to merge 1 commit into
Open
Conversation
When two paths might collide (like /route/search and /route/{id}), we want to match the non-param based routes first, and then only match the param based route if a non param route exists.
Owner
|
Hey @jonluca thanks for the fix. Can you take a look at why the test is failing? |
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.
Fix: Prioritize exact path matches over parameterized paths in tRPC-to-OpenAPI adapter
Problem
The tRPC-to-OpenAPI adapter was incorrectly matching parameterized routes before exact path matches, causing conflicts when both types of routes exist for the same base path. For example, with routes
/image-lora-models/searchand/image-lora-models/{id}, requests to/image-lora-models/searchwere being incorrectly matched by the parameterized route/image-lora-models/{id}.Root Cause
The original implementation used a single cache with regex patterns for all routes. When matching paths, it would iterate through all regex patterns and return the first match, regardless of whether it was an exact or parameterized route. This meant that parameterized routes could incorrectly match exact paths.
Solution
Split the procedure cache into two separate caches with priority-based matching:
Implementation Details
Before
After
Examples
Route Definitions
Request Matching
/image-lora-models/search{id}routesearchroute/image-lora-models/123{id}route{id}route/image-lora-models/abc{id}route{id}routeBenefits
Testing