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

Matcher Chaining #761

Closed
tommysitu opened this issue Aug 3, 2018 · 5 comments · Fixed by #1036
Closed

Matcher Chaining #761

tommysitu opened this issue Aug 3, 2018 · 5 comments · Fixed by #1036
Assignees
Milestone

Comments

@tommysitu
Copy link
Member

tommysitu commented Aug 3, 2018

With matcher chaining, one can use JSONPath to get a JSON node, and use other matcher to compare its value. For example:

{
  body: [
    {
      matcher: "jsonpath"
      value: “$.user.id"
      doMatch: {
        matcher: “exact”,
        value: “1"
    }
  ]
}

This removes the stress of composing and testing complex jsonpath/xpath expressions, which may not be supported by the current jsonpath/xpath library hoverfly is using. The matcher will be more readable too.

@kapishmalik
Copy link
Collaborator

@tommysitu can I take this up?

@kapishmalik
Copy link
Collaborator

@tommysitu I am currently working on this request.

@tommysitu
Copy link
Member Author

Some work has been done here to allow one level of nesting for the form matcher: #1025 you might find it useful @kapishmalik

@kapishmalik
Copy link
Collaborator

kapishmalik commented Jan 6, 2023

@tommysitu I was thinking to change return type of all matchers from bool to string, bool...i.e. matchedvalue, ismatched or not so that I keep on iterating till doMatch is nil. Whenever the value of matcher returns false, I should return false otherwise true after iteration. Hope it makes some sense. I m changing return type so that it becomes generic and we can use doMatch with any of matchers. Matched value which we need to return depends on the matcher. It ll be returning context of that matcher that matched. For eg for jsonpathmatcher, I will be returning value of key, jsonpartialmatcher, I will be returning subset of json which matched and so on. Or other approach would be to have separate matching logic in similar way as done in above implemented approach.

Approach 1 will allow any matcher to be used with doMatch and makes it generic.

@kapishmalik
Copy link
Collaborator

kapishmalik commented Jan 7, 2023

@tommysitu I have raised two PRs(#1035 and #1036) for this with two different ways of implementation for the same above approach1. Both implements matcher chaining. IMO, PR #1036 is a better version... whichever makes more sense, we can go with that.

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

Successfully merging a pull request may close this issue.

3 participants