File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -97,10 +97,15 @@ def find_path_item(request_path)
9797 found = @static [ request_path ]
9898 return [ found , { } ] if found
9999
100- @dynamic . find do |_path , path_item |
100+ matches = @dynamic . filter_map do |_path , path_item |
101101 params = path_item [ :template ] . match ( request_path )
102- return [ path_item , params ] if params
102+ next unless params
103+
104+ [ path_item , params ]
103105 end
106+ return matches . first if matches . length == 1
107+
108+ matches &.min_by { |match | match [ 1 ] . values . sum ( &:length ) }
104109 end
105110 end
106111end
Original file line number Diff line number Diff line change 88 [
99 double ( path : '/{id}' , request_method : 'get' ) ,
1010 double ( path : '/{id}' , request_method : 'patch' ) ,
11- double ( path : '/a' , request_method : 'get' )
11+ double ( path : '/a' , request_method : 'get' ) ,
12+ double ( path : '/a{format}' , request_method : 'get' )
1213 ]
1314 end
1415
3031 expect ( router . match ( 'GET' , '/c/d' ) . error ) . to have_attributes ( type : :not_found )
3132 end
3233
34+ it 'can match a path fragment with a variable' do
35+ match = router . match ( 'GET' , '/a.json' )
36+ expect ( match . request_definition . path ) . to eq ( '/a{format}' )
37+ expect ( match . request_definition ) . to be ( requests [ 3 ] )
38+ end
39+
3340 it 'returns an incomplete match for unknown request method' do
3441 expect ( router . match ( 'DELETE' , '/b' ) . error ) . to have_attributes ( type : :method_not_allowed )
3542 end
You can’t perform that action at this time.
0 commit comments