@@ -56,7 +56,7 @@ func NewRouter(doc *openapi3.T) (routers.Router, error) {
5656
5757 muxRouter := mux .NewRouter ().UseEncodedPath ()
5858 r := & Router {}
59- for _ , path := range orderedPaths ( doc .Paths ) {
59+ for _ , path := range doc .Paths . InMatchingOrder ( ) {
6060 pathItem := doc .Paths [path ]
6161 if len (pathItem .Servers ) > 0 {
6262 if servers , err = makeServers (pathItem .Servers ); err != nil {
@@ -203,31 +203,6 @@ func newSrv(serverURL string, server *openapi3.Server, varsUpdater varsf) (srv,
203203 return svr , nil
204204}
205205
206- func orderedPaths (paths map [string ]* openapi3.PathItem ) []string {
207- // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#pathsObject
208- // When matching URLs, concrete (non-templated) paths would be matched
209- // before their templated counterparts.
210- // NOTE: sorting by number of variables ASC then by descending lexicographical
211- // order seems to be a good heuristic.
212- vars := make (map [int ][]string )
213- max := 0
214- for path := range paths {
215- count := strings .Count (path , "}" )
216- vars [count ] = append (vars [count ], path )
217- if count > max {
218- max = count
219- }
220- }
221- ordered := make ([]string , 0 , len (paths ))
222- for c := 0 ; c <= max ; c ++ {
223- if ps , ok := vars [c ]; ok {
224- sort .Sort (sort .Reverse (sort .StringSlice (ps )))
225- ordered = append (ordered , ps ... )
226- }
227- }
228- return ordered
229- }
230-
231206// Magic strings that temporarily replace "{}" so net/url.Parse() works
232207var blURL , brURL = strings .Repeat ("-" , 50 ), strings .Repeat ("_" , 50 )
233208
0 commit comments