mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-27 11:51:56 +01:00
Swagger support (#749)
* r * fix * sw * x * s * . * . * . * CreateTypeFromJObject * . * . * f * c * . * . * . * . * . * . * ok * , * . * . * . * . * n * pact * fix * schema * null * fluent * r * -p * . * . * refs * .
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
namespace WireMock.Admin.Mappings
|
||||
namespace WireMock.Admin.Mappings
|
||||
{
|
||||
/// <summary>
|
||||
/// Body Model
|
||||
@@ -9,11 +9,11 @@
|
||||
/// <summary>
|
||||
/// Gets or sets the matcher.
|
||||
/// </summary>
|
||||
public MatcherModel Matcher { get; set; }
|
||||
public MatcherModel? Matcher { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the matchers.
|
||||
/// </summary>
|
||||
public MatcherModel[] Matchers { get; set; }
|
||||
public MatcherModel[]? Matchers { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace WireMock.Admin.Mappings;
|
||||
|
||||
/// <summary>
|
||||
/// Cookie Model
|
||||
/// </summary>
|
||||
[FluentBuilder.AutoGenerateBuilder]
|
||||
public class CookieModel
|
||||
namespace WireMock.Admin.Mappings
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// Cookie Model
|
||||
/// </summary>
|
||||
public string Name { get; set; } = null!;
|
||||
[FluentBuilder.AutoGenerateBuilder]
|
||||
public class CookieModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the matchers.
|
||||
/// </summary>
|
||||
public IList<MatcherModel>? Matchers { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the matchers.
|
||||
/// </summary>
|
||||
public IList<MatcherModel>? Matchers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ignore case.
|
||||
/// </summary>
|
||||
public bool? IgnoreCase { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the ignore case.
|
||||
/// </summary>
|
||||
public bool? IgnoreCase { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reject on match.
|
||||
/// </summary>
|
||||
public bool? RejectOnMatch { get; set; }
|
||||
/// <summary>
|
||||
/// Reject on match.
|
||||
/// </summary>
|
||||
public bool? RejectOnMatch { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -14,17 +14,17 @@ namespace WireMock.Admin.Mappings
|
||||
/// <summary>
|
||||
/// Gets or sets the pattern. Can be a string (default) or an object.
|
||||
/// </summary>
|
||||
public object Pattern { get; set; }
|
||||
public object? Pattern { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the patterns. Can be array of strings (default) or an array of objects.
|
||||
/// </summary>
|
||||
public object[] Patterns { get; set; }
|
||||
public object[]? Patterns { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the pattern as a file.
|
||||
/// </summary>
|
||||
public string PatternAsFile { get; set; }
|
||||
public string? PatternAsFile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ignore case.
|
||||
@@ -36,4 +36,4 @@ namespace WireMock.Admin.Mappings
|
||||
/// </summary>
|
||||
public bool? RejectOnMatch { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace WireMock.Admin.Mappings
|
||||
namespace WireMock.Admin.Mappings
|
||||
{
|
||||
/// <summary>
|
||||
/// PathModel
|
||||
@@ -9,6 +9,6 @@
|
||||
/// <summary>
|
||||
/// Gets or sets the matchers.
|
||||
/// </summary>
|
||||
public MatcherModel[] Matchers { get; set; }
|
||||
public MatcherModel[]? Matchers { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Linq;
|
||||
using WireMock.Admin.Mappings;
|
||||
|
||||
namespace WireMock.Extensions;
|
||||
|
||||
public static class RequestModelExtensions
|
||||
{
|
||||
public static string? GetPathAsString(this RequestModel request)
|
||||
{
|
||||
var path = request.Path switch
|
||||
{
|
||||
string pathAsString => pathAsString,
|
||||
PathModel pathModel => pathModel.Matchers?.FirstOrDefault()?.Pattern as string,
|
||||
_ => null
|
||||
};
|
||||
|
||||
return FixPath(path);
|
||||
}
|
||||
|
||||
private static string? FixPath(string? path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
return path!.StartsWith("/") ? path : $"/{path}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using WireMock.Admin.Mappings;
|
||||
|
||||
namespace WireMock.Extensions;
|
||||
|
||||
public static class ResponseModelExtensions
|
||||
{
|
||||
private const string DefaultStatusCode = "200";
|
||||
|
||||
public static string GetStatusCodeAsString(this ResponseModel response)
|
||||
{
|
||||
return response.StatusCode switch
|
||||
{
|
||||
string statusCodeAsString => statusCodeAsString,
|
||||
|
||||
int statusCodeAsInt => statusCodeAsInt.ToString(),
|
||||
|
||||
_ => response.StatusCode?.ToString() ?? DefaultStatusCode
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
@@ -13,7 +13,7 @@ namespace WireMock
|
||||
/// <summary>
|
||||
/// The Body.
|
||||
/// </summary>
|
||||
IBodyData BodyData { get; }
|
||||
IBodyData? BodyData { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the body destination (SameAsSource, String or Bytes).
|
||||
|
||||
Reference in New Issue
Block a user