[TT-16890] fix: backport #7974 — validate middleware collapsed path fix#8067
[TT-16890] fix: backport #7974 — validate middleware collapsed path fix#8067buger merged 2 commits intorelease-5.12.1from
Conversation
Backport of [TT-16890] from master to release-5.12.1. Adds collapsed parameterized path disambiguation for validate-request and mock-response OAS middleware. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
This pull request backports a fix from #7974 to resolve ambiguity when multiple OpenAPI parameterized paths compile to the same regular expression (e.g., Files Changed AnalysisThe changes are primarily focused on the gateway's OpenAPI processing logic and are supported by a substantial addition of test cases:
Architecture & Impact Assessment
Request Disambiguation FlowsequenceDiagram
participant Client
participant Gateway
participant APILoader as API Definition Loader
participant Middleware
Note over APILoader: On API Load
APILoader->>APILoader: 1. Compile OAS paths to regex
APILoader->>APILoader: 2. Group paths with same regex (e.g., /users/{id}, /users/{name})
APILoader->>APILoader: 3. Score & sort candidates by schema restrictiveness
Note over Gateway: On Request
Client->>Gateway: GET /api/users/123
Gateway->>Middleware: Process request
Middleware->>Middleware: Find URLSpec with candidates
Middleware->>Middleware: Test "123" against {id:integer} schema -> Match!
Middleware->>Middleware: Commit to {id:integer} endpoint for full validation
Middleware-->>Gateway: Validation result
Gateway-->>Client: Response
Scope Discovery & Context ExpansionThe scope of this PR is well-contained within the Tyk Gateway's handling of OpenAPI specifications. The changes do not impact non-OAS APIs or other middleware functionalities.
Metadata
Powered by Visor from Probelabs Last updated: 2026-04-17T05:54:28.357Z | Triggered by: pr_updated | Commit: e4c1b04 💡 TIP: You can chat with Visor using |
Security Issues (1)
Architecture Issues (2)
Security Issues (1)
Powered by Visor from Probelabs Last updated: 2026-04-17T05:54:11.261Z | Triggered by: pr_updated | Commit: e4c1b04 💡 TIP: You can chat with Visor using |
pkg/schema was introduced on master by PR #7904 and is not available on release branches. Replace schema.RestoreUnicodeEscapesInError(err) with plain err to match existing release branch error handling. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
API Changes --- prev.txt 2026-04-17 05:53:26.485322992 +0000
+++ current.txt 2026-04-17 05:53:16.282363500 +0000
@@ -11268,6 +11268,14 @@
func (m *MockReadCloser) Read(p []byte) (n int, err error)
+type MockResponseCandidate struct {
+ OASMockResponseMeta *oas.MockResponse
+ OASMethod string
+ OASPath string
+}
+ MockResponseCandidate represents one OAS endpoint that maps to the same
+ compiled regex pattern for mock response disambiguation.
+
type Monitor struct {
Gw *Gateway `json:"-"`
}
@@ -12644,6 +12652,16 @@
OASValidateRequestMeta *oas.ValidateRequest
OASMockResponseMeta *oas.MockResponse
+ // OASValidateRequestCandidates holds multiple OAS endpoints that compile to the
+ // same regex pattern. When non-empty, the validate request middleware must
+ // disambiguate by checking path parameter schemas against each candidate.
+ OASValidateRequestCandidates []ValidateRequestCandidate
+
+ // OASMockResponseCandidates holds multiple OAS endpoints that compile to the
+ // same regex pattern. When non-empty, the mock response middleware must
+ // disambiguate by checking path parameter schemas against each candidate.
+ OASMockResponseCandidates []MockResponseCandidate
+
IgnoreCase bool
// OASMethod stores the HTTP method for OAS-specific middleware
// This is needed because OAS operations are method-specific
@@ -12746,6 +12764,16 @@
ProcessRequest will run any checks on the request on the way through the
system, return an error to have the chain fail
+type ValidateRequestCandidate struct {
+ OASValidateRequestMeta *oas.ValidateRequest
+ OASMethod string
+ OASPath string
+}
+ ValidateRequestCandidate represents one OAS endpoint that maps to the
+ same compiled regex pattern. Used for disambiguation when multiple
+ parameterized paths collapse to the same regex (e.g., /employees/{prct} and
+ /employees/{zd}).
+
type ValueExtractor struct {
BaseExtractor
} |
Cherry-pick critical fixes that were on release-5.12.1 but missing from release-5.12: - #8029: [TT-16890] validate request middleware regression fix - #8067: backport #7974 validate middleware collapsed path fix - #7862: dependency updates in go.mod and go.sum Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary Sync critical commits that are on release-5.12.1 but missing from release-5.12. The branches diverged on Feb 16 with no merge flow between them. This PR brings release-5.12 up to parity with release-5.12.1 for critical fixes. ## Missing commits synced - #8029: [TT-16890] validate request middleware regression fix (CRITICAL) - #8067: backport #7974 validate middleware collapsed path fix - #7862: dependency updates in go.mod and go.sum ## Test plan - [ ] Unit Tests & Linting passes - [ ] go build ./gateway/... passes 🤖 Generated with [Claude Code](https://claude.com/claude-code) [TT-16890]: https://tyktech.atlassian.net/browse/TT-16890?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
🚨 Jira Linter FailedCommit: The Jira linter failed to validate your PR. Please check the error details below: 🔍 Click to view error detailsNext Steps
This comment will be automatically deleted once the linter passes. |
Summary
Clean backport of #7974 to release-5.12.1. Replaces #8060 which had cherry-pick issues (empty diff, 0 changed files).
mockResponsereturn signature on this branchTest plan
🤖 Generated with Claude Code