Conversation
…ints with different param schemas
|
API Changes --- prev.txt 2026-04-15 14:06:16.099725738 +0000
+++ current.txt 2026-04-15 14:06:07.343690786 +0000
@@ -11468,6 +11468,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:"-"`
}
@@ -12918,6 +12926,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
@@ -13020,6 +13038,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
} |
|
This PR resolves an issue where OAS endpoints with identical parameterized path structures but differing parameter schemas (e.g., A two-phase disambiguation mechanism has been introduced, specifically scoped to the OAS request validation and mock response middleware, to address this without altering the core routing engine.
This change ensures that requests are correctly validated against the specific endpoint whose schema—including path parameter types, patterns, and formats—they match. Files Changed AnalysisThe changes are concentrated within the
Architecture & Impact Assessment
Disambiguation FlowsequenceDiagram
participant Loader as API Definition Loader
participant Middleware as OAS Validate/Mock Middleware
participant Client as API Client
Note over Loader: On API Load
Loader->>Loader: groupCollapsedSpecs(): Find endpoints with same regex + method
Loader->>Loader: sortByRestrictiveness(): Sort candidates (integer > string with pattern > string)
Loader-->>Middleware: Store sorted candidates in URLSpec
Note over Middleware: On Incoming Request
Client->>Middleware: GET /employees/123
Middleware->>Middleware: Find URLSpec matching request path
alt URLSpec has candidates
Middleware->>Middleware: processRequestWithCandidates()
loop For each candidate (most restrictive first)
Middleware->>Middleware: Does "123" match candidate's path param schema?
opt Path param schema matches
Middleware->>Middleware: Commit to this candidate
Middleware->>Middleware: Run full validation/mock logic & break
end
end
else No candidates
Middleware->>Middleware: Use default URLSpec logic
end
Scope Discovery & Context Expansion
Metadata
Powered by Visor from Probelabs Last updated: 2026-04-15T14:06:38.601Z | Triggered by: pr_updated | Commit: e626227 💡 TIP: You can chat with Visor using |
\n\n
\n\n
Performance Issues (3)
Quality Issues (3)
Powered by Visor from Probelabs Last updated: 2026-04-15T14:06:07.970Z | Triggered by: pr_updated | Commit: e626227 💡 TIP: You can chat with Visor using |
These are mostly small linting issues, like duplicate of error message, and false report on increasing function complexity. |
|
@probelabs I think your CRITICAL finding about regexp.MatchString is an already existing problem that requires elevated privileges such as API creation for it to work and therefore it's not CRITICAL for this Pull request |
|
/release to release-5.8 |
|
/release to release-5.12.1 |
|
|
|
/release to release-5.8.13 |
|
|
|
|
|
/release to release-5.12.1 |
|
|
|
/release to release-5.12.1 |
|
|
|
/release to release-5.12 |
|
|
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>
Backport of [TT-16890] from master to release-5.12. 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>
## Summary Clean backport of #7974 to release-5.12.1. Replaces #8060 which had cherry-pick issues (empty diff, 0 changed files). - Adds collapsed parameterized path disambiguation for validate-request and mock-response OAS middleware - Cherry-picked from merge commit d89cf0b with conflict resolution for the 2-value `mockResponse` return signature on this branch ## Test plan - [ ] Unit Tests & Linting passes - [ ] CI Tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>
Backport of collapsed parameterized path disambiguation fix from master to release-5.8. Applied on top of the #7972 backport (first commit on this branch). Conflict resolution: - Replaced `pkg/schema.RestoreUnicodeEscapesInError` with `lib.RestoreUnicodeEscapesInError` (pkg/schema doesn't exist on release-5.8) - Kept `lib "github.com/TykTechnologies/tyk/lib/apidef"` import instead of pkg/schema - Added `tykregexp` import for path parameter pattern matching Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ix (#8073) ## Summary Backport of #7974 to release-5.8. Follow-up fix for collapsed parameterized path disambiguation in validate-request and mock-response OAS middleware. This branch includes two commits: 1. Backport of #7972 (prerequisite) -- static path shields and path priority sorting 2. Backport of #7974 -- collapsed parameterized path disambiguation Conflict resolution (vs master): - Replaced `pkg/schema.RestoreUnicodeEscapesInError` with `lib.RestoreUnicodeEscapesInError` (`pkg/schema` doesn't exist on release-5.8) - Removed `internal/mcp` import and MCP-related functions (not present on release-5.8) - Added `internal/oasutil` import with exported `PathLess` and `PathParamRegex` ## Test plan - [ ] Unit Tests & Linting passes - [ ] `go build ./gateway/...` passes (verified locally) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Backport of collapsed parameterized path disambiguation fix from master to release-5.8.13. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ix (#8074) ## Summary Backport of #7974 to release-5.8.13. Follow-up fix for collapsed parameterized path disambiguation. - Adds `groupCollapsedValidateRequestSpecs` and `groupCollapsedMockResponseSpecs` to detect and group URLSpec entries with identical compiled regex patterns - Adds candidate-based disambiguation using path parameter schema validation - Adds `matchCandidatePath` for shared disambiguation logic - Removes `lib.RestoreUnicodeEscapesInError` reference (not available on this branch) **Note:** This PR includes the #7972 backport commit as a prerequisite (stacked PR). Merge #7972 backport first: #8072 ## Test plan - [ ] Unit Tests & Linting passes - [ ] `go build ./gateway/...` passes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Description
When two OAS endpoints share the same base path but differ only in path parameter schemas (e.g.,
/employees/{prct}withpattern: ^[a-z]$vs/employees/{zd}withpattern: [1-9]), both compile to the identical regex^/employees/([^/]+)$. The gateway'sFindSpecMatchesStatusreturns the first match, so one endpoint's validation rules are always ignored.This fix introduces a two-step disambiguation mechanism scoped to the validate request middleware:
Compilation: A new
groupCollapsedValidateRequestSpecsfunction detects URLSpec entries that compile to the same regex+method pair and groups them as candidates on a single representative URLSpec.Request processing: When a URLSpec has multiple candidates,
processRequestWithCandidatesconstructs the OAS route directly for each candidate (bypassing the OAS router which cannot distinguish structurally identical parameterized paths) and runs fullopenapi3filter.ValidateRequestper candidate. The first candidate that passes full validation (including path parameter schema, headers, query params, body) wins. If no candidate matches, the request is rejected with a clear error.Key design decisions
FindSpecMatchesStatusor core URLSpec matching, avoiding blast radius to other middleware.openapi3filter.ValidateRequestper candidate rather than just regex pattern matching, correctly handlingtype,enum,format, and other JSON Schema constraints on path parameters.routers.Routedirectly from the OAS spec path items instead of using the OAS router, which cannot distinguish between structurally identical parameterized paths.Related Issue
TT-16890
Motivation and Context
OAS API definitions can have multiple endpoints with the same path structure but different path parameter schemas and different validation requirements (e.g., different required headers). Before this fix, only one endpoint's validation rules would ever be applied, causing incorrect validation behavior for the other endpoint(s).
How This Has Been Tested
Unit test (
TestGroupCollapsedValidateRequestSpecs): Verifies the grouping logic handles no-collision, same regex+method collision, different-method non-collision, and three-way collision cases.Integration test (
TestSameBasePathDifferentParamSchemas): Sets up two endpoints (/employees/{prct}with pattern^[a-z]$requiring headerdef, and/employees/{zd}with pattern[1-9]requiring headerabc) and verifies:/employees/awith headerdef-> 200 (matches{prct})/employees/5with headerabc-> 200 (matches{zd})/employees/awithout header -> 422 (matches{prct}but fails header validation)/employees/5without header -> 422 (matches{zd}but fails header validation)/employees/!!!-> 422 (matches neither param schema)All existing tests pass with no regressions:
TestValidateRequest*,TestStaticPathTakesPrecedenceOverParameterised,TestSortURLSpecsByPathPriority,TestStaticPathPriorityWithPrefixMatching,TestMockResponseStaticPathPriority.