This commit is contained in:
Stef Heyenrath
2026-02-21 16:35:08 +01:00
parent a06a73f65f
commit 43a26ec4bc
11 changed files with 27 additions and 39 deletions

View File

@@ -5,11 +5,11 @@ namespace WireMock.Pact.Models.V2;
public class Interaction
{
public string? Description { get; set; }
public required string Description { get; set; }
public string? ProviderState { get; set; }
public PactRequest Request { get; set; } = new();
public required PactRequest Request { get; set; }
public PactResponse Response { get; set; } = new();
public required PactResponse Response { get; set; }
}

View File

@@ -8,20 +8,20 @@ public class MatchingRule
/// <summary>
/// type or regex
/// </summary>
public string Match { get; set; } = "type";
public required string Match { get; set; }
/// <summary>
/// Used for Match = "type"
/// </summary>
public string Min { get; set; }
public string? Min { get; set; }
/// <summary>
/// Used for Match = "type"
/// </summary>
public string Max { get; set; }
public string? Max { get; set; }
/// <summary>
/// Used for Match = "regex"
/// </summary>
public string Regex { get; set; }
public string? Regex { get; set; }
}

View File

@@ -5,7 +5,7 @@ namespace WireMock.Pact.Models.V2;
public class Metadata
{
public string PactSpecificationVersion { get; set; }
public required string PactSpecificationVersion { get; set; }
public PactSpecification PactSpecification { get; set; } = new PactSpecification();
public required PactSpecification PactSpecification { get; set; }
}

View File

@@ -1,17 +1,15 @@
// Copyright © WireMock.Net
#pragma warning disable CS1591
using System.Collections.Generic;
namespace WireMock.Pact.Models.V2;
public class Pact
{
public Pacticipant Consumer { get; set; }
public required Pacticipant Consumer { get; set; }
public List<Interaction> Interactions { get; set; } = new List<Interaction>();
public required List<Interaction> Interactions { get; set; } = [];
public Metadata Metadata { get; set; }
public Metadata? Metadata { get; set; }
public Pacticipant Provider { get; set; }
public required Pacticipant Provider { get; set; }
}

View File

@@ -1,7 +1,6 @@
// Copyright © WireMock.Net
#pragma warning disable CS1591
using System.Collections.Generic;
using WireMock.Constants;
namespace WireMock.Pact.Models.V2;
@@ -10,9 +9,9 @@ public class PactRequest
{
public IDictionary<string, string>? Headers { get; set; }
public string Method { get; set; } = HttpRequestMethod.GET;
public required string Method { get; set; } = HttpRequestMethod.GET;
public string? Path { get; set; } = "/";
public required string Path { get; set; } = "/";
public string? Query { get; set; }

View File

@@ -1,8 +1,6 @@
// Copyright © WireMock.Net
#pragma warning disable CS1591
using System.Collections.Generic;
namespace WireMock.Pact.Models.V2;
public class PactResponse
@@ -11,5 +9,5 @@ public class PactResponse
public IDictionary<string, string>? Headers { get; set; }
public int Status { get; set; } = 200;
public required int Status { get; set; }
}

View File

@@ -5,9 +5,9 @@ namespace WireMock.Pact.Models.V2;
public class PactRust
{
public string Ffi { get; set; }
public required string Ffi { get; set; }
public string Mockserver { get; set; }
public required string Mockserver { get; set; }
public string Models { get; set; }
public required string Models { get; set; }
}

View File

@@ -5,5 +5,5 @@ namespace WireMock.Pact.Models.V2;
public class PactSpecification
{
public string Version { get; set; } = "2.0";
public required string Version { get; set; } = "2.0";
}

View File

@@ -5,5 +5,5 @@ namespace WireMock.Pact.Models.V2;
public class Pacticipant
{
public string Name { get; set; }
public required string Name { get; set; }
}

View File

@@ -7,7 +7,7 @@ namespace WireMock.Pact.Models.V2;
public class ProviderState
{
public string Name { get; set; }
public required string Name { get; set; }
public IDictionary<string, string> Params { get; set; }
public IDictionary<string, string>? Params { get; set; }
}

View File

@@ -1,8 +1,5 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.Linq;
using WireMock.Admin.Mappings;
using WireMock.Extensions;
using WireMock.Pact.Models.V2;
@@ -28,7 +25,8 @@ internal static class PactMapper
var pact = new Pact.Models.V2.Pact
{
Consumer = new Pacticipant { Name = consumer },
Provider = new Pacticipant { Name = provider }
Provider = new Pacticipant { Name = provider },
Interactions = []
};
foreach (var mapping in server.MappingModels.OrderBy(m => m.Guid))
@@ -42,7 +40,7 @@ internal static class PactMapper
var interaction = new Interaction
{
Description = !string.IsNullOrWhiteSpace(mapping.Description) ? mapping.Description : mapping.Title ?? string.Empty,
Description = mapping.Description ?? mapping.Title ?? string.Empty,
Request = MapRequest(mapping.Request, path),
Response = MapResponse(mapping.Response)
};
@@ -65,13 +63,8 @@ internal static class PactMapper
};
}
private static PactResponse MapResponse(ResponseModel? response)
private static PactResponse MapResponse(ResponseModel response)
{
if (response == null)
{
return new PactResponse();
}
return new PactResponse
{
Status = MapStatusCode(response.StatusCode),