Similar endpoints
When I ran this code from Router class in Playgrounds always print "matches" for similar endpoints. In my case, Ambassador is returning the same JSON response to both endpoints and I don't know why...Is there a chance that similar endpoints make Ambassador confused? (Sometimes work sometimes don't)
` let path = "foo/bar/10/xyz" let searchPath = "foo/bar/10/xyz/asd" let regex = try! NSRegularExpression(pattern: path, options: []) let matches = regex.matches(in: searchPath, options: [], range: NSRange(location: 0, length: searchPath.count))
if !matches.isEmpty { print("match") } else { print("no match") } `
We have the same problem.
router["/reisen"] = AdvancedResponse(stubFile: "ReisenResponse", mapper: mapper)
router["/reisen/details"] = AdvancedResponse(stubFile: "ReiseDetailsResponse", mapper: mapper)
returns always /reisen/details
Yeah we have the same problems with a test that requieres mutiple calls to a service with similar paths, the Router seems to get whatever it finds first and replies with that. The problem is in the loop/regex algorithm here: private func matchRoute(to searchPath: String) -> (WebApp, [String])?.
In our case we added these search paths:
"/some/path""/some/path/specific"
The second will get the response from the first since Regex will match with the first path it finds, causing the loop to end early without checking if there are more positive matches.
I had a similar issue #51 , as a workaround we're using a custom DefaultRouter class with the following route matcher:
private func matchRoute(to searchPath: String) -> (WebApp, [String])? {
if(routes.keys.contains(searchPath)){
return (routes[searchPath]!, [searchPath])
}
return nil
}
As they are regex strings, we can add begin & end symbols in router paths, to make sure they are matched exactly. For example:
^/some/path$^/some/path/specific$