From f527489fae43b57cd9f7486cf5a8ef6b4eee5f9f Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 13:31:40 +0000 Subject: [PATCH] fix: an interaction matches a path the spec writes with a trailing slash The generated client builds its URL with url.JoinPath, which drops a trailing slash, so a spec path such as /v7/finance/options/{ticker}/ is called as /v7/finance/options/ONDS. The matcher split the template into one segment more and found no operation for the recording. It now drops a trailing slash on both sides, as the client does. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019QCb1AfnATvpBQCH3PrX7Y --- interactions.go | 5 +++-- interactions_test.go | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/interactions.go b/interactions.go index a9da4ace..4c7e43af 100644 --- a/interactions.go +++ b/interactions.go @@ -416,8 +416,9 @@ func literalSegments(template string) int { // value reports whether the match was segment-for-segment exact; callers should // prefer an exact match over a wildcard one. func matchPathTemplate(template, path string) (params map[string]string, matched, exact bool) { - tParts := strings.Split(template, "/") - pParts := strings.Split(path, "/") + // The client builds its URL with url.JoinPath, which drops a trailing slash, so neither side's counts. + tParts := strings.Split(strings.TrimSuffix(template, "/"), "/") + pParts := strings.Split(strings.TrimSuffix(path, "/"), "/") if len(tParts) > len(pParts) { return nil, false, false diff --git a/interactions_test.go b/interactions_test.go index 1b0d9b8b..d972f557 100644 --- a/interactions_test.go +++ b/interactions_test.go @@ -163,6 +163,9 @@ func TestMatchPathTemplate(t *testing.T) { // trailing wildcard param consuming multiple slash-separated segments {"/package/{path}", "/package/github.com/google/go-cmp/cmp", true, "path", "github.com/google/go-cmp/cmp"}, {"/package/{path}", "/package/single", true, "path", "single"}, + // a trailing slash in the spec, which the client's url.JoinPath drops + {"/v7/finance/options/{ticker}/", "/v7/finance/options/ONDS", true, "ticker", "ONDS"}, + {"/v7/finance/options/{ticker}", "/v7/finance/options/ONDS/", true, "ticker", "ONDS"}, } for _, tc := range tests {