Skip to content

Commit

Permalink
extensible-paths (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
general-kroll-4-life authored Jan 4, 2022
1 parent 2a1c4b1 commit c95dd68
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions routers/gorillamux/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func orderedPaths(paths map[string]*openapi3.PathItem) []string {
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#pathsObject
// When matching URLs, concrete (non-templated) paths would be matched
// before their templated counterparts.
// NOTE: sorting by number of variables ASC then by lexicographical
// NOTE: sorting by number of variables ASC then by descending lexicographical
// order seems to be a good heuristic.
vars := make(map[int][]string)
max := 0
Expand All @@ -142,7 +142,7 @@ func orderedPaths(paths map[string]*openapi3.PathItem) []string {
ordered := make([]string, 0, len(paths))
for c := 0; c <= max; c++ {
if ps, ok := vars[c]; ok {
sort.Strings(ps)
sort.Sort(sort.Reverse(sort.StringSlice(ps)))
ordered = append(ordered, ps...)
}
}
Expand Down
6 changes: 3 additions & 3 deletions routers/gorillamux/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func TestRouter(t *testing.T) {
&openapi3.ParameterRef{Value: openapi3.NewPathParameter("bookid")},
},
},
"/books/{bookid2}.json": &openapi3.PathItem{
"/books/{bookid}.json": &openapi3.PathItem{
Post: booksPOST,
Parameters: openapi3.Parameters{
&openapi3.ParameterRef{Value: openapi3.NewPathParameter("bookid2")},
&openapi3.ParameterRef{Value: openapi3.NewPathParameter("bookid")},
},
},
"/partial": &openapi3.PathItem{
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestRouter(t *testing.T) {
"bookid": "War.and.Peace",
})
expect(r, http.MethodPost, "/books/War.and.Peace.json", booksPOST, map[string]string{
"bookid2": "War.and.Peace",
"bookid": "War.and.Peace",
})
expect(r, http.MethodPost, "/partial", nil, nil)

Expand Down

0 comments on commit c95dd68

Please sign in to comment.