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

Update JSONPathMatcher.cs to cover the string path selection to a child #993

Merged
merged 6 commits into from
Aug 17, 2023

Conversation

DayLightDancer
Copy link
Contributor

The .SelectToken method accept string path selection and JSONPath queries. The current code works only for the queries because the result is JObject. When the string path is selected the result is JValue and event with a valid result the code the code doesn't return valued result.
https://www.newtonsoft.com/json/help/html/SelectToken.htm

The .SelectToken method accept string path selection and JSONPath queries. The current code works only for the queries because the result is JObject. When the string path is selected the result is JValue and event with a valid result the code the code doesn't return valued result.
https://www.newtonsoft.com/json/help/html/SelectToken.htm
Update JSONPathMatcher.cs to cover the string path selection to a child
@StefH
Copy link
Collaborator

StefH commented Aug 15, 2023

@DayLightDancer
Can you please also add a unit test for this scenario?

@DayLightDancer
Copy link
Contributor Author

Added the unit tests. I am not able to run the entire solution locally so the tests are created and run on separate solution and added in the existed file.

test/WireMock.Net.Tests/Matchers/JsonPathMatcherTests.cs Outdated Show resolved Hide resolved
test/WireMock.Net.Tests/Matchers/JsonPathMatcherTests.cs Outdated Show resolved Hide resolved
@@ -123,7 +123,12 @@ private double IsMatch(JToken jToken)
{
var array = ConvertJTokenToJArrayIfNeeded(jToken);

return MatchScores.ToScore(_patterns.Select(pattern => array.SelectToken(pattern.GetPattern())?.Any() == true).ToArray(), MatchOperator);
// The SelectToken method can accept string path to a child token ( i.e. “Manufacturers[0].Products[0].Price”) in that cat it will return a JValue(some type) which not implement the IEnumerable interface.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the comment to this?

// The SelectToken method can accept a string path to a child token ( i.e. "Manufacturers[0].Products[0].Price"). In that case it will return a JValue (some type) which does not implement the IEnumerable interface.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please only write this 1 line comment

@StefH
Copy link
Collaborator

StefH commented Aug 15, 2023

Thanks.

Can you take a look at the comments?

@DayLightDancer
Copy link
Contributor Author

I've addressed the comments

@DayLightDancer
Copy link
Contributor Author

HI, Please tell me if there is anything to do with that PR and when I can expect the new build?

@StefH
Copy link
Collaborator

StefH commented Aug 16, 2023

You set the comments to resolved, but did you also commit your latest changes?

@DayLightDancer
Copy link
Contributor Author

DayLightDancer commented Aug 17, 2023

I think so. I've edited the files in place. I will appreciate any help complete that PR.

@StefH
Copy link
Collaborator

StefH commented Aug 17, 2023

it seems that the files are not changed, can you please double check?

@DayLightDancer
Copy link
Contributor Author

it seems that the files are not changed, can you please double check?

Yes. I will in few ours. But this is what is see
image

@StefH StefH self-requested a review August 17, 2023 14:39
@StefH
Copy link
Collaborator

StefH commented Aug 17, 2023

This one is not yet done:
image

@DayLightDancer
Copy link
Contributor Author

This one is not yet done: image

I found the problem:
image
Do you know how to solve it?(The commit doesn't belong to any branch)

@StefH
Copy link
Collaborator

StefH commented Aug 17, 2023

Replace it by a one line:

// The SelectToken method can accept a string path to a child token ( i.e. "Manufacturers[0].Products[0].Price"). In that case it will return a JValue (some type) which does not implement the IEnumerable interface.

@DayLightDancer
Copy link
Contributor Author

Can you check it, now?

@StefH
Copy link
Collaborator

StefH commented Aug 17, 2023

I will merge this one and update it myself.

@@ -123,7 +123,12 @@ private double IsMatch(JToken jToken)
{
var array = ConvertJTokenToJArrayIfNeeded(jToken);

return MatchScores.ToScore(_patterns.Select(pattern => array.SelectToken(pattern.GetPattern())?.Any() == true).ToArray(), MatchOperator);
// The SelectToken method can accept string path to a child token ( i.e. “Manufacturers[0].Products[0].Price”) in that cat it will return a JValue(some type) which not implement the IEnumerable interface.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please only write this 1 line comment

@StefH StefH merged commit 8adf34f into WireMock-Net:master Aug 17, 2023
4 of 6 checks passed
@DayLightDancer
Copy link
Contributor Author

I will merge this one and update it myself.

Thank you verry much. I really appreciate it.

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

Successfully merging this pull request may close these issues.

None yet

2 participants