Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Similar endpoints #49

Open
jgbrittos opened this issue Apr 5, 2019 · 4 comments
Open

Similar endpoints #49

jgbrittos opened this issue Apr 5, 2019 · 4 comments

Comments

@jgbrittos
Copy link

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")
}
`

@lightsprint09
Copy link

We have the same problem.

 router["/reisen"] = AdvancedResponse(stubFile: "ReisenResponse", mapper: mapper)
 router["/reisen/details"] = AdvancedResponse(stubFile: "ReiseDetailsResponse", mapper: mapper)

returns always /reisen/details

@rahvii
Copy link

rahvii commented May 31, 2019

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.

@pizerg
Copy link

pizerg commented Jul 26, 2019

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
}

@CocoaBob
Copy link

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$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants