Skip to content

Commit

Permalink
FixMapping[] for WireMock.Org REST API (#1023)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH authored Dec 6, 2023
1 parent c193bcf commit 932dde0
Show file tree
Hide file tree
Showing 8 changed files with 371 additions and 382 deletions.
16 changes: 8 additions & 8 deletions src/WireMock.Net/Server/WireMockServer.ImportWireMockOrg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using WireMock.ResponseBuilders;
using WireMock.Util;
using Stef.Validation;
using OrgMappings = WireMock.Org.Abstractions.Mappings;
using OrgMapping = WireMock.Org.Abstractions.Mapping;

namespace WireMock.Server;

Expand All @@ -25,14 +25,14 @@ public void ReadStaticWireMockOrgMappingAndAddOrUpdate(string path)
{
Guard.NotNull(path, nameof(path));

string filenameWithoutExtension = Path.GetFileNameWithoutExtension(path);
var filenameWithoutExtension = Path.GetFileNameWithoutExtension(path);

if (FileHelper.TryReadMappingFileWithRetryAndDelay(_settings.FileSystemHandler, path, out var value))
{
var mappings = DeserializeJsonToArray<OrgMappings>(value);
var mappings = DeserializeJsonToArray<OrgMapping>(value);
foreach (var mapping in mappings)
{
if (mappings.Length == 1 && Guid.TryParse(filenameWithoutExtension, out Guid guidFromFilename))
if (mappings.Length == 1 && Guid.TryParse(filenameWithoutExtension, out var guidFromFilename))
{
ConvertWireMockOrgMappingAndRegisterAsRespondProvider(mapping, guidFromFilename, path);
}
Expand All @@ -48,10 +48,10 @@ private IResponseMessage MappingsPostWireMockOrg(IRequestMessage requestMessage)
{
try
{
var mappingModels = DeserializeRequestMessageToArray<OrgMappings>(requestMessage);
var mappingModels = DeserializeRequestMessageToArray<OrgMapping>(requestMessage);
if (mappingModels.Length == 1)
{
Guid? guid = ConvertWireMockOrgMappingAndRegisterAsRespondProvider(mappingModels[0]);
var guid = ConvertWireMockOrgMappingAndRegisterAsRespondProvider(mappingModels[0]);
return ResponseMessageBuilder.Create(201, "Mapping added", guid);
}

Expand All @@ -74,7 +74,7 @@ private IResponseMessage MappingsPostWireMockOrg(IRequestMessage requestMessage)
}
}

private Guid? ConvertWireMockOrgMappingAndRegisterAsRespondProvider(OrgMappings mapping, Guid? guid = null, string? path = null)
private Guid? ConvertWireMockOrgMappingAndRegisterAsRespondProvider(Org.Abstractions.Mapping mapping, Guid? guid = null, string? path = null)
{
var requestBuilder = Request.Create();

Expand Down Expand Up @@ -159,7 +159,7 @@ private IResponseMessage MappingsPostWireMockOrg(IRequestMessage requestMessage)
}
}

IResponseBuilder responseBuilder = Response.Create();
var responseBuilder = Response.Create();

var response = mapping.Response;
if (response != null)
Expand Down
11 changes: 5 additions & 6 deletions src/WireMock.Org.Abstractions/GetAdminMappingsResult.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace WireMock.Org.Abstractions
namespace WireMock.Org.Abstractions;

public class GetAdminMappingsResult
{
public class GetAdminMappingsResult
{
public Mappings Mappings { get; set; }
public Mapping[] Mappings { get; set; }

public Meta Meta { get; set; }
}
public Meta Meta { get; set; }
}
58 changes: 58 additions & 0 deletions src/WireMock.Org.Abstractions/Mapping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace WireMock.Org.Abstractions;

public class Mapping
{
/// <summary>
/// This stub mapping's unique identifier
/// </summary>
public string Id { get; set; }

/// <summary>
/// Alias for the id
/// </summary>
public string Uuid { get; set; }

/// <summary>
/// The stub mapping's name
/// </summary>
public string Name { get; set; }

public MappingsRequest Request { get; set; }

public MappingsResponse Response { get; set; }

/// <summary>
/// Indicates that the stub mapping should be persisted immediately on create/update/delete and survive resets to default.
/// </summary>
public bool Persistent { get; set; }

/// <summary>
/// This stub mapping's priority relative to others. 1 is highest.
/// </summary>
public int Priority { get; set; }

/// <summary>
/// The name of the scenario that this stub mapping is part of
/// </summary>
public string ScenarioName { get; set; }

/// <summary>
/// The required state of the scenario in order for this stub to be matched.
/// </summary>
public string RequiredScenarioState { get; set; }

/// <summary>
/// The new state for the scenario to be updated to after this stub is served.
/// </summary>
public string NewScenarioState { get; set; }

/// <summary>
/// A map of the names of post serve action extensions to trigger and their parameters.
/// </summary>
public object PostServeActions { get; set; }

/// <summary>
/// Arbitrary metadata to be used for e.g. tagging, documentation. Can also be used to find and remove stubs.
/// </summary>
public object Metadata { get; set; }
}
59 changes: 0 additions & 59 deletions src/WireMock.Org.Abstractions/Mappings.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace WireMock.Org.Abstractions
namespace WireMock.Org.Abstractions;

public class PostAdminMappingsFindByMetadataResult
{
public class PostAdminMappingsFindByMetadataResult
{
public Mappings Mappings { get; set; }
public Mapping[] Mappings { get; set; }

public Meta Meta { get; set; }
}
public Meta Meta { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace WireMock.Org.Abstractions
namespace WireMock.Org.Abstractions;

public class PostAdminRecordingsSnapshotResult
{
public class PostAdminRecordingsSnapshotResult
{
public Mappings Mappings { get; set; }
public Mapping[] Mappings { get; set; }

public Meta Meta { get; set; }
}
public Meta Meta { get; set; }
}
11 changes: 5 additions & 6 deletions src/WireMock.Org.Abstractions/PostAdminRecordingsStopResult.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace WireMock.Org.Abstractions
namespace WireMock.Org.Abstractions;

public class PostAdminRecordingsStopResult
{
public class PostAdminRecordingsStopResult
{
public Mappings Mappings { get; set; }
public Mapping[] Mappings { get; set; }

public Meta Meta { get; set; }
}
public Meta Meta { get; set; }
}
Loading

0 comments on commit 932dde0

Please sign in to comment.