mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-05-30 02:20:41 +02:00
Add SystemTextJsonMatchers (#1447)
* SystemTextJsonMatcher * , * . * new projectx * Update test/WireMock.Net.Tests/Pact/PactTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update test/WireMock.Net.Tests/WebSockets/WebSocketIntegrationTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/WireMock.Net/WireMock.Net.csproj Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/WireMock.Net.Minimal/Properties/AssemblyInfo.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * . * more tests * . * . * x * ... * . * fix tests * 0.11.0 * . * delete jsonutils.cs * s * fix findings * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> * Potential fix for pull request finding 'Missing Dispose call on local IDisposable' Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> * JsonConverter 0.12.0 * -- tools --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System.Linq;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NJsonSchema;
|
||||
using NJsonSchema.Extensions;
|
||||
using NSwag;
|
||||
@@ -281,7 +282,7 @@ internal static class SwaggerMapper
|
||||
if (matcher is { Name: nameof(JsonMatcher) })
|
||||
{
|
||||
var pattern = GetPatternAsStringFromMatcher(matcher);
|
||||
if (JsonUtils.TryParseAsJObject(pattern, out var jObject))
|
||||
if (TryParseAsJObject(pattern, out var jObject))
|
||||
{
|
||||
return jObject;
|
||||
}
|
||||
@@ -292,6 +293,39 @@ internal static class SwaggerMapper
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool IsJson(string? value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
value = value!.Trim();
|
||||
|
||||
return (value.StartsWith("{") && value.EndsWith("}")) || (value.StartsWith("[") && value.EndsWith("]"));
|
||||
}
|
||||
|
||||
private static bool TryParseAsJObject(string? strInput, [NotNullWhen(true)] out JObject? value)
|
||||
{
|
||||
value = null;
|
||||
|
||||
if (!IsJson(strInput))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Try to convert this string into a JObject
|
||||
value = JObject.Parse(strInput!);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetContentType(RequestModel request)
|
||||
{
|
||||
var contentType = request.Headers?.FirstOrDefault(h => h.Name == "Content-Type");
|
||||
|
||||
Reference in New Issue
Block a user