Skip to content

Commit

Permalink
Don't strip trailing slashes when generating service profiles
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Leong <[email protected]>
  • Loading branch information
adleong committed Oct 20, 2023
1 parent 166c94f commit a5d7ef2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/profiles/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"io"
"net/http"
"path"
"sort"
"strings"

"github.com/go-openapi/spec"
sp "github.com/linkerd/linkerd2/controller/gen/apis/serviceprofile/v1alpha2"
Expand Down Expand Up @@ -67,9 +67,10 @@ func swaggerToServiceProfile(swagger spec.Swagger, namespace, name, clusterDomai
sort.Strings(paths)
}

base := strings.TrimRight(swagger.BasePath, "/")
for _, relPath := range paths {
item := swagger.Paths.Paths[relPath]
path := path.Join(swagger.BasePath, relPath)
path := base + "/" + strings.TrimLeft(relPath, "/")
pathRegex := PathToRegex(path)
if item.Delete != nil {
spec := MkRouteSpec(path, pathRegex, http.MethodDelete, item.Delete)
Expand Down
12 changes: 12 additions & 0 deletions pkg/profiles/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func TestSwaggerToServiceProfile(t *testing.T) {
},
},
},
"/path/with/trailing/slash/": {
PathItemProps: spec.PathItemProps{
Get: &spec.Operation{},
},
},
},
},
},
Expand Down Expand Up @@ -68,6 +73,13 @@ func TestSwaggerToServiceProfile(t *testing.T) {
IsRetryable: true,
Timeout: "60s",
},
{
Name: "GET /path/with/trailing/slash/",
Condition: &sp.RequestMatch{
PathRegex: "/path/with/trailing/slash/",
Method: "GET",
},
},
},
},
}
Expand Down

0 comments on commit a5d7ef2

Please sign in to comment.