mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-20 15:31:20 +02:00
Fix WithBody when using Pact and added more nullable annotations (#783)
* More nullable annotations * . * . * FIX * pact * . * p * xxx * ... * auth * array * ...
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DevLab.JmesPath.Interop;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Extensions;
|
||||
using WireMock.Matchers;
|
||||
@@ -76,10 +77,25 @@ internal static class PactMapper
|
||||
{
|
||||
Status = MapStatusCode(response.StatusCode),
|
||||
Headers = MapResponseHeaders(response.Headers),
|
||||
Body = response.BodyAsJson
|
||||
Body = MapBody(response)
|
||||
};
|
||||
}
|
||||
|
||||
private static object? MapBody(ResponseModel? response)
|
||||
{
|
||||
if (response?.BodyAsJson != null)
|
||||
{
|
||||
return response.BodyAsJson;
|
||||
}
|
||||
|
||||
if (response?.Body != null) // In case the body is a string, try to deserialize into object, else just return the string
|
||||
{
|
||||
return JsonUtils.TryDeserializeObject<object?>(response.Body) ?? response.Body;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static int MapStatusCode(object? statusCode)
|
||||
{
|
||||
if (statusCode is string statusCodeAsString)
|
||||
@@ -138,13 +154,13 @@ internal static class PactMapper
|
||||
return jsonMatcher?.Pattern;
|
||||
}
|
||||
|
||||
private static string GetPatternAsStringFromMatchers(MatcherModel[]? matchers, string defaultValue)
|
||||
{
|
||||
if (matchers != null && matchers.Any() && matchers[0].Pattern is string patternAsString)
|
||||
{
|
||||
return patternAsString;
|
||||
}
|
||||
//private static string GetPatternAsStringFromMatchers(MatcherModel[]? matchers, string defaultValue)
|
||||
//{
|
||||
// if (matchers != null && matchers.Any() && matchers[0].Pattern is string patternAsString)
|
||||
// {
|
||||
// return patternAsString;
|
||||
// }
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
// return defaultValue;
|
||||
//}
|
||||
}
|
||||
Reference in New Issue
Block a user