fix(procedures): fix exact procedure matching #101
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