mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-28 19:58:09 +02:00
FixMapping[] for WireMock.Org REST API (#1023)
This commit is contained in:
@@ -10,7 +10,7 @@ using WireMock.RequestBuilders;
|
|||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using OrgMappings = WireMock.Org.Abstractions.Mappings;
|
using OrgMapping = WireMock.Org.Abstractions.Mapping;
|
||||||
|
|
||||||
namespace WireMock.Server;
|
namespace WireMock.Server;
|
||||||
|
|
||||||
@@ -25,14 +25,14 @@ public partial class WireMockServer
|
|||||||
{
|
{
|
||||||
Guard.NotNull(path, nameof(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))
|
if (FileHelper.TryReadMappingFileWithRetryAndDelay(_settings.FileSystemHandler, path, out var value))
|
||||||
{
|
{
|
||||||
var mappings = DeserializeJsonToArray<OrgMappings>(value);
|
var mappings = DeserializeJsonToArray<OrgMapping>(value);
|
||||||
foreach (var mapping in mappings)
|
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);
|
ConvertWireMockOrgMappingAndRegisterAsRespondProvider(mapping, guidFromFilename, path);
|
||||||
}
|
}
|
||||||
@@ -48,10 +48,10 @@ public partial class WireMockServer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var mappingModels = DeserializeRequestMessageToArray<OrgMappings>(requestMessage);
|
var mappingModels = DeserializeRequestMessageToArray<OrgMapping>(requestMessage);
|
||||||
if (mappingModels.Length == 1)
|
if (mappingModels.Length == 1)
|
||||||
{
|
{
|
||||||
Guid? guid = ConvertWireMockOrgMappingAndRegisterAsRespondProvider(mappingModels[0]);
|
var guid = ConvertWireMockOrgMappingAndRegisterAsRespondProvider(mappingModels[0]);
|
||||||
return ResponseMessageBuilder.Create(201, "Mapping added", guid);
|
return ResponseMessageBuilder.Create(201, "Mapping added", guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ public partial class WireMockServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
var requestBuilder = Request.Create();
|
||||||
|
|
||||||
@@ -159,7 +159,7 @@ public partial class WireMockServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IResponseBuilder responseBuilder = Response.Create();
|
var responseBuilder = Response.Create();
|
||||||
|
|
||||||
var response = mapping.Response;
|
var response = mapping.Response;
|
||||||
if (response != null)
|
if (response != null)
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
namespace WireMock.Org.Abstractions
|
namespace WireMock.Org.Abstractions;
|
||||||
|
|
||||||
|
public class GetAdminMappingsResult
|
||||||
{
|
{
|
||||||
public class GetAdminMappingsResult
|
public Mapping[] Mappings { get; set; }
|
||||||
{
|
|
||||||
public Mappings Mappings { get; set; }
|
|
||||||
|
|
||||||
public Meta Meta { get; set; }
|
public Meta Meta { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
58
src/WireMock.Org.Abstractions/Mapping.cs
Normal file
58
src/WireMock.Org.Abstractions/Mapping.cs
Normal file
@@ -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; }
|
||||||
|
}
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
namespace WireMock.Org.Abstractions
|
|
||||||
{
|
|
||||||
public class Mappings
|
|
||||||
{
|
|
||||||
/// <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; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
namespace WireMock.Org.Abstractions
|
namespace WireMock.Org.Abstractions;
|
||||||
|
|
||||||
|
public class PostAdminMappingsFindByMetadataResult
|
||||||
{
|
{
|
||||||
public class PostAdminMappingsFindByMetadataResult
|
public Mapping[] Mappings { get; set; }
|
||||||
{
|
|
||||||
public Mappings Mappings { get; set; }
|
|
||||||
|
|
||||||
public Meta Meta { get; set; }
|
public Meta Meta { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
namespace WireMock.Org.Abstractions
|
namespace WireMock.Org.Abstractions;
|
||||||
|
|
||||||
|
public class PostAdminRecordingsSnapshotResult
|
||||||
{
|
{
|
||||||
public class PostAdminRecordingsSnapshotResult
|
public Mapping[] Mappings { get; set; }
|
||||||
{
|
|
||||||
public Mappings Mappings { get; set; }
|
|
||||||
|
|
||||||
public Meta Meta { get; set; }
|
public Meta Meta { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
namespace WireMock.Org.Abstractions
|
namespace WireMock.Org.Abstractions;
|
||||||
|
|
||||||
|
public class PostAdminRecordingsStopResult
|
||||||
{
|
{
|
||||||
public class PostAdminRecordingsStopResult
|
public Mapping[] Mappings { get; set; }
|
||||||
{
|
|
||||||
public Mappings Mappings { get; set; }
|
|
||||||
|
|
||||||
public Meta Meta { get; set; }
|
public Meta Meta { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,18 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AnyOfTypes;
|
using AnyOfTypes;
|
||||||
using RestEase;
|
using RestEase;
|
||||||
using WireMock.Org.Abstractions;
|
using WireMock.Org.Abstractions;
|
||||||
|
|
||||||
namespace WireMock.Org.RestClient
|
namespace WireMock.Org.RestClient;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Summary: WireMockOrg
|
||||||
|
///
|
||||||
|
/// Title : WireMock
|
||||||
|
/// Version: 2.3x
|
||||||
|
/// </summary>
|
||||||
|
public interface IWireMockOrgApi
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Summary: WireMockOrg
|
|
||||||
///
|
|
||||||
/// Title : WireMock
|
|
||||||
/// Version: 2.33.2
|
|
||||||
/// </summary>
|
|
||||||
public interface IWireMockOrgApi
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all stub mappings
|
/// Get all stub mappings
|
||||||
///
|
///
|
||||||
@@ -295,5 +290,4 @@ namespace WireMock.Org.RestClient
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[Post("/__admin/shutdown")]
|
[Post("/__admin/shutdown")]
|
||||||
Task<object> PostAdminShutdownAsync();
|
Task<object> PostAdminShutdownAsync();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user