mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 17:28:55 +02:00
Update comment in JsonPathMatcher.cs
This commit is contained in:
@@ -123,12 +123,9 @@ public class JsonPathMatcher : IStringMatcher, IObjectMatcher
|
|||||||
{
|
{
|
||||||
var array = ConvertJTokenToJArrayIfNeeded(jToken);
|
var array = ConvertJTokenToJArrayIfNeeded(jToken);
|
||||||
|
|
||||||
// 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.
|
// The SelectToken method can accept a string path to a child token ( i.e. "Manufacturers[0].Products[0].Price").
|
||||||
// Using ?.Any() == true relays that we use a JSONPath queries and the SelectToken will return a JObject ( implements the IEnumerable interface).
|
// In that case it will return a JValue (some type) which does not implement the IEnumerable interface.
|
||||||
// So the current code works only when the JSONPath is expression and not when we pass a valid string path to child.
|
return MatchScores.ToScore(_patterns.Select(pattern => array.SelectToken(pattern.GetPattern()) != null).ToArray(), MatchOperator);
|
||||||
// My suggestion is to roll back to != null to cover the both cases.
|
|
||||||
|
|
||||||
return MatchScores.ToScore(_patterns.Select(pattern => array.SelectToken(pattern.GetPattern()) != null ).ToArray(), MatchOperator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/WireMock-Net/WireMock.Net/issues/965
|
// https://github.com/WireMock-Net/WireMock.Net/issues/965
|
||||||
@@ -143,9 +140,9 @@ public class JsonPathMatcher : IStringMatcher, IObjectMatcher
|
|||||||
var item = property.First();
|
var item = property.First();
|
||||||
if (item is JArray)
|
if (item is JArray)
|
||||||
{
|
{
|
||||||
return jToken;
|
return jToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JObject
|
return new JObject
|
||||||
{
|
{
|
||||||
[property.Path] = new JArray(item)
|
[property.Path] = new JArray(item)
|
||||||
|
|||||||
Reference in New Issue
Block a user