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:
Stef Heyenrath
2022-08-11 10:57:33 +02:00
committed by GitHub
parent b1af37f044
commit d2a1d0f069
87 changed files with 2578 additions and 2455 deletions

View File

@@ -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;
//}
}