fix(go,csharp,python,ruby,php,rust): strip query params from WireMock urlPathTemplate#16693
fix(go,csharp,python,ruby,php,rust): strip query params from WireMock urlPathTemplate#16693dvdaruri-art wants to merge 2 commits into
Conversation
…add as queryParameters matchers Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
| // Strip query string — query parameters embedded in the path (e.g. Stainless | ||
| // overload paths like "?stainless_overload=branchFrom") must be matched via | ||
| // the separate queryParameters field, not as part of urlPathTemplate. | ||
| const queryIndex = path.indexOf("?"); | ||
| if (queryIndex !== -1) { | ||
| path = path.substring(0, queryIndex); | ||
| } |
There was a problem hiding this comment.
🔴 Shared buildUrlPathTemplate now strips query strings from urlPathTemplate, breaking key lookups in Python, Ruby, PHP, and Rust generators
The buildUrlPathTemplate method in mock-utils now strips query strings from the urlPathTemplate field of WireMockMapping. Only the Go v2 and C# generators were updated to use the new metadata.fullPathTemplate for disambiguation. The Python (generators/python-v2/sdk/src/wire-tests/WireTestGenerator.ts:769), Ruby (generators/ruby-v2/sdk/src/wire-tests/WireTestGenerator.ts:562), PHP (generators/php/sdk/src/wire-tests/WireTestGenerator.ts:431), and Rust (generators/rust/sdk/src/wire-tests/WireTestGenerator.ts:540) generators still key their wireMockConfigContent map by mapping.request.urlPathTemplate. When processing endpoints with embedded query strings (e.g., /path?stainless_overload=foo), the stored key is now "POST - /path" but their buildBasePath methods construct lookup keys with the query string intact ("POST - /path?stainless_overload=foo"), causing a mismatch. For Rust, this throws a fatal GeneratorError.internalError. For Ruby, it logs a warning and returns an unsubstituted path. For Python and PHP, the mapping lookup silently fails and path parameters are not substituted.
Affected consumer code patterns (all unchanged by this PR)
All four generators do:
// getWireMockConfigContent() - uses urlPathTemplate which now lacks query string
const key = this.wiremockMappingKey({ requestMethod: mapping.request.method, requestUrlPathTemplate: mapping.request.urlPathTemplate });
// buildBasePath() - uses raw endpoint.fullPath which still has query string
let basePath = endpoint.fullPath.head + parts;
const mappingKey = this.wiremockMappingKey({ requestMethod: endpoint.method, requestUrlPathTemplate: basePath });Prompt for agents
The buildUrlPathTemplate method in mock-utils now strips query strings from urlPathTemplate, but only the Go v2 and C# generators were updated to handle this change. The Python v2, Ruby v2, PHP, and Rust generators still use mapping.request.urlPathTemplate as the key in getWireMockConfigContent() and construct lookup keys from endpoint.fullPath (which still includes query strings) in buildBasePath().
To fix this, each of the four affected generators needs two changes:
1. In getWireMockConfigContent(): Use mapping.metadata.fullPathTemplate ?? mapping.request.urlPathTemplate for the key (same as the Go v2 fix)
2. In buildBasePath(): Use the full path (including query string) for the mapping key lookup, then strip the query string from the actual base path used for URL construction
Affected files:
- generators/python-v2/sdk/src/wire-tests/WireTestGenerator.ts (getWireMockConfigContent at line 763, buildBasePath at line 779)
- generators/ruby-v2/sdk/src/wire-tests/WireTestGenerator.ts (getWireMockConfigContent at line 556, buildBasePath around line 390)
- generators/php/sdk/src/wire-tests/WireTestGenerator.ts (getWireMockConfigContent at line 427, buildBasePath at line 437)
- generators/rust/sdk/src/wire-tests/WireTestGenerator.ts (getWireMockConfigContent at line 534, buildBasePath at line 408)
See the Go v2 WireTestGenerator.ts lines 46-61 and 814-836 for the reference implementation of both fixes.
Was this helpful? React with 👍 or 👎 to provide feedback.
| let fullPath = | ||
| endpoint.fullPath.head + | ||
| endpoint.fullPath.parts.map((part) => `{${part.pathParameter}}${part.tail}`).join(""); | ||
|
|
||
| if (!basePath.startsWith("/")) { | ||
| basePath = `/${basePath}`; | ||
| if (!fullPath.startsWith("/")) { | ||
| fullPath = `/${fullPath}`; | ||
| } | ||
|
|
||
| // Use the full path (with query string) for the mapping key lookup, | ||
| // since getWireMockConfigContent keys by fullPathTemplate when available. | ||
| const mappingKey = this.wiremockMappingKey({ | ||
| requestMethod: endpoint.method, | ||
| requestUrlPathTemplate: basePath | ||
| requestUrlPathTemplate: fullPath |
There was a problem hiding this comment.
🚩 Fragment handling inconsistency between buildRawFullPath and Go v2 buildBasePath
The buildRawFullPath method in packages/commons/mock-utils/src/index.ts:446-449 strips URL fragments (e.g., #refresh) from paths, but the Go v2 buildBasePath at generators/go-v2/sdk/src/wire-tests/WireTestGenerator.ts:816-818 does NOT strip fragments when constructing the lookup key. For endpoints with fragments (like /oauth2/token#refresh), fullPathTemplate would be undefined (since buildRawFullPath produces the same as urlPathTemplate after fragment stripping), so the stored key would be "POST - /oauth2/token". But buildBasePath would produce "POST - /oauth2/token#refresh" as the lookup key. This is a pre-existing mismatch (it existed before this PR in the old code where fragments weren't stripped from the lookup key either), but it's worth noting that this PR doesn't fix it. If fragment-path endpoints exist in Go API specs, they'd still cause a fatal error at the throw GeneratorError.internalError on line 841.
Was this helpful? React with 👍 or 👎 to provide feedback.
…mplate in additional generators Apply the same fullPathTemplate fix to Python v2, Ruby v2, PHP, and Rust generators. Uses mapping.metadata.fullPathTemplate (with fallback to mapping.request.urlPathTemplate) as the key in getWireMockConfigContent(), and strips query strings from basePath in buildBasePath() while preserving the full path for mapping lookup. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
SDK Generation Benchmark ResultsComparing PR branch against median of 5 nightly run(s) on Full benchmark table (click to expand)
main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via |
Description
Fixes WireMock wire test generation for endpoints whose OpenAPI paths contain embedded query strings (e.g. Stainless overload pattern
?stainless_overload=methodName). WireMock'surlPathTemplateonly matches the path portion — query params placed there cause stubs to never match.Changes Made
packages/commons/mock-utils/src/index.ts?, split it: path goes tourlPathTemplate, query params go to a newqueryParametersmatcher blockmetadata.fullPathTemplatefield to preserve the original full path (including query string) for disambiguation when looking up stubssplitPathAndQuery(),parseQueryParams()All 6 generator WireTestGenerators
Applied identical fix pattern across Go v2, C#, Python v2, Ruby v2, PHP, Rust:
generators/go-v2/sdk/src/wire-tests/WireTestGenerator.tsgenerators/csharp/sdk/src/test-generation/mock-server/MockEndpointGenerator.tsgenerators/python-v2/sdk/src/wire-tests/WireTestGenerator.tsgenerators/ruby-v2/sdk/src/wire-tests/WireTestGenerator.tsgenerators/php/sdk/src/wire-tests/WireTestGenerator.tsgenerators/rust/sdk/src/wire-tests/WireTestGenerator.tsChangelog entries added
generators/go/sdk/changes/unreleased/fix-wiremock-query-params.ymlgenerators/csharp/sdk/changes/unreleased/fix-wiremock-query-params.ymlgenerators/python/sdk/changes/unreleased/fix-wiremock-query-params.ymlgenerators/ruby-v2/sdk/changes/unreleased/fix-wiremock-query-params.ymlgenerators/php/sdk/changes/unreleased/fix-wiremock-query-params.ymlgenerators/rust/sdk/changes/unreleased/fix-wiremock-query-params.ymlTesting
pnpm turbo run compile)Link to Devin session: https://app.devin.ai/sessions/95554c85c0ec46eba848a62db064632f
Requested by: @dvdaruri-art