Skip to content

Commit 32c49f5

Browse files
committed
fix(codeconfig): Ensure paths do not have trailing slashes
1 parent 7379665 commit 32c49f5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pkg/codeconfig/codeconfig.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ func (c *codeConfig) apiSpec(api string) (*openapi3.T, error) {
193193
return doc, nil
194194
}
195195

196+
func ensureOneTrailingSlash(p string) string {
197+
if len(p) > 0 && string(p[len(p)-1]) == "/" {
198+
return p
199+
}
200+
return p + "/"
201+
}
202+
196203
func splitPath(workerPath string) (string, openapi3.Parameters) {
197204
normalizedPath := ""
198205
params := make(openapi3.Parameters, 0)
@@ -211,9 +218,9 @@ func splitPath(workerPath string) (string, openapi3.Parameters) {
211218
},
212219
},
213220
})
214-
normalizedPath = normalizedPath + "{" + paramName + "}" + "/"
221+
normalizedPath = ensureOneTrailingSlash(normalizedPath + "{" + paramName + "}")
215222
} else {
216-
normalizedPath = normalizedPath + p + "/"
223+
normalizedPath = ensureOneTrailingSlash(normalizedPath + p)
217224
}
218225
}
219226
// trim off trailing slash

pkg/codeconfig/codeconfig_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ func Test_splitPath(t *testing.T) {
3636
want: "/orders",
3737
want1: openapi3.Parameters{},
3838
},
39+
{
40+
name: "trailing slash",
41+
workerPath: "/orders/",
42+
want: "/orders",
43+
want1: openapi3.Parameters{},
44+
},
3945
{
4046
name: "with param",
4147
workerPath: "/orders/:id",

0 commit comments

Comments
 (0)