Skip to content

Commit c95dd68

Browse files
extensible-paths (#470)
1 parent 2a1c4b1 commit c95dd68

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

routers/gorillamux/router.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func orderedPaths(paths map[string]*openapi3.PathItem) []string {
128128
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#pathsObject
129129
// When matching URLs, concrete (non-templated) paths would be matched
130130
// before their templated counterparts.
131-
// NOTE: sorting by number of variables ASC then by lexicographical
131+
// NOTE: sorting by number of variables ASC then by descending lexicographical
132132
// order seems to be a good heuristic.
133133
vars := make(map[int][]string)
134134
max := 0
@@ -142,7 +142,7 @@ func orderedPaths(paths map[string]*openapi3.PathItem) []string {
142142
ordered := make([]string, 0, len(paths))
143143
for c := 0; c <= max; c++ {
144144
if ps, ok := vars[c]; ok {
145-
sort.Strings(ps)
145+
sort.Sort(sort.Reverse(sort.StringSlice(ps)))
146146
ordered = append(ordered, ps...)
147147
}
148148
}

routers/gorillamux/router_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ func TestRouter(t *testing.T) {
5959
&openapi3.ParameterRef{Value: openapi3.NewPathParameter("bookid")},
6060
},
6161
},
62-
"/books/{bookid2}.json": &openapi3.PathItem{
62+
"/books/{bookid}.json": &openapi3.PathItem{
6363
Post: booksPOST,
6464
Parameters: openapi3.Parameters{
65-
&openapi3.ParameterRef{Value: openapi3.NewPathParameter("bookid2")},
65+
&openapi3.ParameterRef{Value: openapi3.NewPathParameter("bookid")},
6666
},
6767
},
6868
"/partial": &openapi3.PathItem{
@@ -152,7 +152,7 @@ func TestRouter(t *testing.T) {
152152
"bookid": "War.and.Peace",
153153
})
154154
expect(r, http.MethodPost, "/books/War.and.Peace.json", booksPOST, map[string]string{
155-
"bookid2": "War.and.Peace",
155+
"bookid": "War.and.Peace",
156156
})
157157
expect(r, http.MethodPost, "/partial", nil, nil)
158158

0 commit comments

Comments
 (0)