mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-23 09:15:06 +01:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6e4608039 | ||
|
|
57f89a06e1 | ||
|
|
4d80eb53fe | ||
|
|
13c002fede | ||
|
|
9db6e800ad | ||
|
|
897ee9ffe3 | ||
|
|
8865543bf1 | ||
|
|
48cfd2d20e | ||
|
|
71d2660aff | ||
|
|
7f2a42de96 |
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,3 +1,14 @@
|
|||||||
|
# 1.4.28 (01 December 2021)
|
||||||
|
- [#686](https://github.com/WireMock-Net/WireMock.Net/pull/686) - [Snyk] Security upgrade Microsoft.Owin from 4.0.0 to 4.1.1 [dependencies] contributed by [snyk-bot](https://github.com/snyk-bot)
|
||||||
|
- [#688](https://github.com/WireMock-Net/WireMock.Net/pull/688) - Bump System.Text.Encodings.Web from 4.5.0 to 4.5.1 in /examples/WireMock.Net.Console.Net472.Classic [dependencies] contributed by [dependabot[bot]](https://github.com/apps/dependabot)
|
||||||
|
- [#689](https://github.com/WireMock-Net/WireMock.Net/pull/689) - Upgrade some NuGet's (Codecov, coverlet, Moq and NFluent) [dependencies] contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#691](https://github.com/WireMock-Net/WireMock.Net/pull/691) - Update the OpenApiPathsMapper to handle Value/Wildcard [feature] contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#694](https://github.com/WireMock-Net/WireMock.Net/pull/694) - RamlToOpenAPI updated to 0.5.0 contributed by [mcheguini](https://github.com/mcheguini)
|
||||||
|
- [#695](https://github.com/WireMock-Net/WireMock.Net/pull/695) - Allow configure IgnoreCase in settings [feature] contributed by [leolplex](https://github.com/leolplex)
|
||||||
|
- [#696](https://github.com/WireMock-Net/WireMock.Net/pull/696) - Filter required property in headers, query params, request body [feature] contributed by [leolplex](https://github.com/leolplex)
|
||||||
|
- [#666](https://github.com/WireMock-Net/WireMock.Net/issues/666) - Example is not working as expected [bug]
|
||||||
|
- [#692](https://github.com/WireMock-Net/WireMock.Net/issues/692) - Case insensitive and ignoring optional path and header parameters in OpenApiPathsMapper [feature]
|
||||||
|
|
||||||
# 1.4.27 (17 November 2021)
|
# 1.4.27 (17 November 2021)
|
||||||
- [#678](https://github.com/WireMock-Net/WireMock.Net/pull/678) - Support RequestBody [feature] contributed by [leolplex](https://github.com/leolplex)
|
- [#678](https://github.com/WireMock-Net/WireMock.Net/pull/678) - Support RequestBody [feature] contributed by [leolplex](https://github.com/leolplex)
|
||||||
- [#680](https://github.com/WireMock-Net/WireMock.Net/pull/680) - Support examples in properties [feature] contributed by [leolplex](https://github.com/leolplex)
|
- [#680](https://github.com/WireMock-Net/WireMock.Net/pull/680) - Support examples in properties [feature] contributed by [leolplex](https://github.com/leolplex)
|
||||||
@@ -136,6 +147,7 @@
|
|||||||
- [#549](https://github.com/WireMock-Net/WireMock.Net/issues/549) - WithProxy(...) does not save the mappings to file [bug]
|
- [#549](https://github.com/WireMock-Net/WireMock.Net/issues/549) - WithProxy(...) does not save the mappings to file [bug]
|
||||||
|
|
||||||
# 1.3.8 (03 December 2020)
|
# 1.3.8 (03 December 2020)
|
||||||
|
- [#539](https://github.com/WireMock-Net/WireMock.Net/pull/539) - Support for partial JSON matching contributed by [gleb-osokin](https://github.com/gleb-osokin)
|
||||||
- [#542](https://github.com/WireMock-Net/WireMock.Net/pull/542) - Create dotnet-wiremock tool [feature] contributed by [StefH](https://github.com/StefH)
|
- [#542](https://github.com/WireMock-Net/WireMock.Net/pull/542) - Create dotnet-wiremock tool [feature] contributed by [StefH](https://github.com/StefH)
|
||||||
- [#543](https://github.com/WireMock-Net/WireMock.Net/pull/543) - Add support for .NET 5 [feature] contributed by [StefH](https://github.com/StefH)
|
- [#543](https://github.com/WireMock-Net/WireMock.Net/pull/543) - Add support for .NET 5 [feature] contributed by [StefH](https://github.com/StefH)
|
||||||
- [#544](https://github.com/WireMock-Net/WireMock.Net/pull/544) - Use Java 11 in Azure Pipelines (needed for SonarCloud) [feature] contributed by [StefH](https://github.com/StefH)
|
- [#544](https://github.com/WireMock-Net/WireMock.Net/pull/544) - Use Java 11 in Azure Pipelines (needed for SonarCloud) [feature] contributed by [StefH](https://github.com/StefH)
|
||||||
@@ -143,9 +155,6 @@
|
|||||||
- [#547](https://github.com/WireMock-Net/WireMock.Net/pull/547) - Fix Proxying with SSL and NetCoreApp3.1 [bug] contributed by [StefH](https://github.com/StefH)
|
- [#547](https://github.com/WireMock-Net/WireMock.Net/pull/547) - Fix Proxying with SSL and NetCoreApp3.1 [bug] contributed by [StefH](https://github.com/StefH)
|
||||||
- [#524](https://github.com/WireMock-Net/WireMock.Net/issues/524) - Proxying with SSL Not Working in .NET Core 3.1 [bug]
|
- [#524](https://github.com/WireMock-Net/WireMock.Net/issues/524) - Proxying with SSL Not Working in .NET Core 3.1 [bug]
|
||||||
|
|
||||||
# 1.3.7 (17 November 2020)
|
|
||||||
- [#539](https://github.com/WireMock-Net/WireMock.Net/pull/539) - Support for partial JSON matching contributed by [gleb-osokin](https://github.com/gleb-osokin)
|
|
||||||
|
|
||||||
# 1.3.6 (10 November 2020)
|
# 1.3.6 (10 November 2020)
|
||||||
- [#529](https://github.com/WireMock-Net/WireMock.Net/pull/529) - Add assertions for ClientIP, Url and ProxyUrl [feature] contributed by [akamud](https://github.com/akamud)
|
- [#529](https://github.com/WireMock-Net/WireMock.Net/pull/529) - Add assertions for ClientIP, Url and ProxyUrl [feature] contributed by [akamud](https://github.com/akamud)
|
||||||
- [#535](https://github.com/WireMock-Net/WireMock.Net/pull/535) - WithCallback should use also use enum HttpStatusCode [bug] contributed by [StefH](https://github.com/StefH)
|
- [#535](https://github.com/WireMock-Net/WireMock.Net/pull/535) - WithCallback should use also use enum HttpStatusCode [bug] contributed by [StefH](https://github.com/StefH)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VersionPrefix>1.4.27</VersionPrefix>
|
<VersionPrefix>1.4.28</VersionPrefix>
|
||||||
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
|
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
|
||||||
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
||||||
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
rem https://github.com/StefH/GitHubReleaseNotes
|
rem https://github.com/StefH/GitHubReleaseNotes
|
||||||
|
|
||||||
SET version=1.4.27
|
SET version=1.4.28
|
||||||
|
|
||||||
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate --version %version% --token %GH_TOKEN%
|
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate --version %version% --token %GH_TOKEN%
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
# 1.4.27 (17 November 2021)
|
# 1.4.28 (01 December 2021)
|
||||||
- #678 Support RequestBody [feature]
|
- #686 [Snyk] Security upgrade Microsoft.Owin from 4.0.0 to 4.1.1 [dependencies]
|
||||||
- #680 Support examples in properties [feature]
|
- #688 Bump System.Text.Encodings.Web from 4.5.0 to 4.5.1 in /examples/WireMock.Net.Console.Net472.Classic [dependencies]
|
||||||
- #681 Support enums in properties [feature]
|
- #689 Upgrade some NuGet's (Codecov, coverlet, Moq and NFluent) [dependencies]
|
||||||
|
- #691 Update the OpenApiPathsMapper to handle Value/Wildcard [feature]
|
||||||
|
- #694 RamlToOpenAPI updated to 0.5.0
|
||||||
|
- #695 Allow configure IgnoreCase in settings [feature]
|
||||||
|
- #696 Filter required property in headers, query params, request body [feature]
|
||||||
|
- #666 Example is not working as expected [bug]
|
||||||
|
- #692 Case insensitive and ignoring optional path and header parameters in OpenApiPathsMapper [feature]
|
||||||
|
|
||||||
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md
|
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net472" />
|
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net472" />
|
||||||
<package id="System.Security.Cryptography.Cng" version="4.5.0" targetFramework="net472" />
|
<package id="System.Security.Cryptography.Cng" version="4.5.0" targetFramework="net472" />
|
||||||
<package id="System.Security.Principal.Windows" version="4.5.0" targetFramework="net472" />
|
<package id="System.Security.Principal.Windows" version="4.5.0" targetFramework="net472" />
|
||||||
<package id="System.Text.Encodings.Web" version="4.5.0" targetFramework="net472" />
|
<package id="System.Text.Encodings.Web" version="4.5.1" targetFramework="net472" />
|
||||||
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net472" />
|
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net472" />
|
||||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||||
<package id="WireMock.Net" version="1.4.2" targetFramework="net472" />
|
<package id="WireMock.Net" version="1.4.2" targetFramework="net472" />
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ namespace WireMock.Net.OpenApiParser.ConsoleApp
|
|||||||
private const string Folder = "OpenApiFiles";
|
private const string Folder = "OpenApiFiles";
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var serverOpenAPIExamples = Run.RunServer(Path.Combine(Folder, "openAPIExamples.yaml"), "http://localhost:9091/");
|
var serverOpenAPIExamples = Run.RunServer(Path.Combine(Folder, "openAPIExamples.yaml"), "https://localhost:9091/");
|
||||||
var serverPetstore_V2_json = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V2.0.json"), "http://localhost:9092/");
|
var serverPetstore_V2_json = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V2.0.json"), "https://localhost:9092/");
|
||||||
var serverPetstore_V2_yaml = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V2.0.yaml"), "http://localhost:9093/");
|
var serverPetstore_V2_yaml = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V2.0.yaml"), "https://localhost:9093/");
|
||||||
var serverPetstore_V300_yaml = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V3.0.0.yaml"), "http://localhost:9094/");
|
var serverPetstore_V300_yaml = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V3.0.0.yaml"), "https://localhost:9094/");
|
||||||
var serverPetstore_V302_json = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V3.0.2.json"), "http://localhost:9095/");
|
var serverPetstore_V302_json = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V3.0.2.json"), "https://localhost:9095/");
|
||||||
|
|
||||||
Console.WriteLine("Press any key to stop the servers");
|
Console.WriteLine("Press any key to stop the servers");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace WireMock.Net.OpenApiParser.ConsoleApp
|
|||||||
{
|
{
|
||||||
public static class Run
|
public static class Run
|
||||||
{
|
{
|
||||||
public static WireMockServer RunServer(string path, string url)
|
public static WireMockServer RunServer(string path, string url, bool dynamicExamples = true)
|
||||||
{
|
{
|
||||||
var server = WireMockServer.Start(new WireMockServerSettings
|
var server = WireMockServer.Start(new WireMockServerSettings
|
||||||
{
|
{
|
||||||
@@ -31,7 +31,9 @@ namespace WireMock.Net.OpenApiParser.ConsoleApp
|
|||||||
|
|
||||||
var settings = new WireMockOpenApiParserSettings
|
var settings = new WireMockOpenApiParserSettings
|
||||||
{
|
{
|
||||||
PathPatternToUse = ExampleValueType.Wildcard
|
DynamicExamples = dynamicExamples,
|
||||||
|
PathPatternToUse = ExampleValueType.Wildcard,
|
||||||
|
HeaderPatternToUse = ExampleValueType.Wildcard
|
||||||
};
|
};
|
||||||
|
|
||||||
server.WithMappingFromOpenApiFile(path, settings, out var diag);
|
server.WithMappingFromOpenApiFile(path, settings, out var diag);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -2,6 +2,5 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<packageSources>
|
<packageSources>
|
||||||
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
|
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
|
||||||
<add key="coverlet" value="https://f.feedz.io/marcorossignoli/coverletunofficial/nuget/index.json" />
|
|
||||||
</packageSources>
|
</packageSources>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#if NET46 || NETSTANDARD2_0
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace WireMock.Net.OpenApiParser.Extensions
|
||||||
|
{
|
||||||
|
internal static class DictionaryExtensions
|
||||||
|
{
|
||||||
|
public static bool TryAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value)
|
||||||
|
{
|
||||||
|
if (dictionary is null || dictionary.ContainsKey(key))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
dictionary[key] = value;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -8,6 +8,7 @@ using Microsoft.OpenApi.Models;
|
|||||||
using Microsoft.OpenApi.Writers;
|
using Microsoft.OpenApi.Writers;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using Stef.Validation;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Net.OpenApiParser.Extensions;
|
using WireMock.Net.OpenApiParser.Extensions;
|
||||||
using WireMock.Net.OpenApiParser.Settings;
|
using WireMock.Net.OpenApiParser.Settings;
|
||||||
@@ -18,12 +19,14 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
|||||||
{
|
{
|
||||||
internal class OpenApiPathsMapper
|
internal class OpenApiPathsMapper
|
||||||
{
|
{
|
||||||
|
private const string HeaderContentType = "Content-Type";
|
||||||
|
|
||||||
private readonly WireMockOpenApiParserSettings _settings;
|
private readonly WireMockOpenApiParserSettings _settings;
|
||||||
private readonly ExampleValueGenerator _exampleValueGenerator;
|
private readonly ExampleValueGenerator _exampleValueGenerator;
|
||||||
|
|
||||||
public OpenApiPathsMapper(WireMockOpenApiParserSettings settings)
|
public OpenApiPathsMapper(WireMockOpenApiParserSettings settings)
|
||||||
{
|
{
|
||||||
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
_settings = Guard.NotNull(settings, nameof(settings));
|
||||||
_exampleValueGenerator = new ExampleValueGenerator(settings);
|
_exampleValueGenerator = new ExampleValueGenerator(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +63,7 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
|||||||
MapSchemaToObject(responseSchema);
|
MapSchemaToObject(responseSchema);
|
||||||
|
|
||||||
var requestBodyModel = new BodyModel();
|
var requestBodyModel = new BodyModel();
|
||||||
if (operation.RequestBody != null && operation.RequestBody.Content != null)
|
if (operation.RequestBody != null && operation.RequestBody.Content != null && operation.RequestBody.Required)
|
||||||
{
|
{
|
||||||
var request = operation.RequestBody.Content;
|
var request = operation.RequestBody.Content;
|
||||||
TryGetContent(request, out OpenApiMediaType requestContent, out string requestContentType);
|
TryGetContent(request, out OpenApiMediaType requestContent, out string requestContentType);
|
||||||
@@ -108,11 +111,15 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var requestBodyModel = new BodyModel();
|
return new BodyModel
|
||||||
requestBodyModel.Matcher = new MatcherModel();
|
{
|
||||||
requestBodyModel.Matcher.Name = "JsonMatcher";
|
Matcher = new MatcherModel
|
||||||
requestBodyModel.Matcher.Pattern = JsonConvert.SerializeObject(requestBody, Formatting.Indented);
|
{
|
||||||
return requestBodyModel;
|
Name = "JsonMatcher",
|
||||||
|
Pattern = JsonConvert.SerializeObject(requestBody, Formatting.Indented),
|
||||||
|
IgnoreCase = _settings.RequestBodyIgnoreCase
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryGetContent(IDictionary<string, OpenApiMediaType> contents, out OpenApiMediaType openApiMediaType, out string contentType)
|
private bool TryGetContent(IDictionary<string, OpenApiMediaType> contents, out OpenApiMediaType openApiMediaType, out string contentType)
|
||||||
@@ -243,10 +250,11 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool propertyIsNullable = openApiSchema.Nullable || (openApiSchema.TryGetXNullable(out bool x) && x);
|
// bool propertyIsNullable = openApiSchema.Nullable || (openApiSchema.TryGetXNullable(out bool x) && x);
|
||||||
return new JProperty(key, _exampleValueGenerator.GetExampleValue(openApiSchema));
|
return new JProperty(key, _exampleValueGenerator.GetExampleValue(openApiSchema));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string MapPathWithParameters(string path, IEnumerable<OpenApiParameter> parameters)
|
private string MapPathWithParameters(string path, IEnumerable<OpenApiParameter> parameters)
|
||||||
{
|
{
|
||||||
if (parameters == null)
|
if (parameters == null)
|
||||||
@@ -257,7 +265,8 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
|||||||
string newPath = path;
|
string newPath = path;
|
||||||
foreach (var parameter in parameters)
|
foreach (var parameter in parameters)
|
||||||
{
|
{
|
||||||
newPath = newPath.Replace($"{{{parameter.Name}}}", GetExampleValue(parameter.Schema, _settings.PathPatternToUse));
|
var exampleMatcherModel = GetExampleMatcherModel(parameter.Schema, _settings.PathPatternToUse);
|
||||||
|
newPath = newPath.Replace($"{{{parameter.Name}}}", exampleMatcherModel.Pattern as string);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newPath;
|
return newPath;
|
||||||
@@ -271,11 +280,11 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
|||||||
}
|
}
|
||||||
|
|
||||||
OpenApiServer server = servers.First();
|
OpenApiServer server = servers.First();
|
||||||
Uri uriResult;
|
if (Uri.TryCreate(server.Url, UriKind.RelativeOrAbsolute, out Uri uriResult))
|
||||||
if (Uri.TryCreate(server.Url, UriKind.RelativeOrAbsolute, out uriResult))
|
|
||||||
{
|
{
|
||||||
return uriResult.IsAbsoluteUri ? uriResult.AbsolutePath : uriResult.ToString();
|
return uriResult.IsAbsoluteUri ? uriResult.AbsolutePath : uriResult.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,19 +313,12 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
|||||||
{
|
{
|
||||||
var mappedHeaders = headers.ToDictionary(
|
var mappedHeaders = headers.ToDictionary(
|
||||||
item => item.Key,
|
item => item.Key,
|
||||||
item => GetExampleValue(null, _settings.HeaderPatternToUse) as object
|
item => GetExampleMatcherModel(null, _settings.HeaderPatternToUse).Pattern
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(responseContentType))
|
if (!string.IsNullOrEmpty(responseContentType))
|
||||||
{
|
{
|
||||||
if (!mappedHeaders.ContainsKey("Content-Type"))
|
mappedHeaders.TryAdd(HeaderContentType, responseContentType);
|
||||||
{
|
|
||||||
mappedHeaders.Add("Content-Type", responseContentType);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mappedHeaders["Content-Type"] = responseContentType;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mappedHeaders.Keys.Any() ? mappedHeaders : null;
|
return mappedHeaders.Keys.Any() ? mappedHeaders : null;
|
||||||
@@ -325,16 +327,14 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
|||||||
private IList<ParamModel> MapQueryParameters(IEnumerable<OpenApiParameter> queryParameters)
|
private IList<ParamModel> MapQueryParameters(IEnumerable<OpenApiParameter> queryParameters)
|
||||||
{
|
{
|
||||||
var list = queryParameters
|
var list = queryParameters
|
||||||
|
.Where(req => req.Required)
|
||||||
.Select(qp => new ParamModel
|
.Select(qp => new ParamModel
|
||||||
{
|
{
|
||||||
Name = qp.Name,
|
Name = qp.Name,
|
||||||
|
IgnoreCase = _settings.QueryParameterPatternIgnoreCase,
|
||||||
Matchers = new[]
|
Matchers = new[]
|
||||||
{
|
{
|
||||||
new MatcherModel
|
GetExampleMatcherModel(qp.Schema, _settings.QueryParameterPatternToUse)
|
||||||
{
|
|
||||||
Name = "ExactMatcher",
|
|
||||||
Pattern = GetDefaultValueAsStringForSchemaType(qp.Schema)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.ToList();
|
.ToList();
|
||||||
@@ -345,16 +345,14 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
|||||||
private IList<HeaderModel> MapRequestHeaders(IEnumerable<OpenApiParameter> headers)
|
private IList<HeaderModel> MapRequestHeaders(IEnumerable<OpenApiParameter> headers)
|
||||||
{
|
{
|
||||||
var list = headers
|
var list = headers
|
||||||
|
.Where(req => req.Required)
|
||||||
.Select(qp => new HeaderModel
|
.Select(qp => new HeaderModel
|
||||||
{
|
{
|
||||||
Name = qp.Name,
|
Name = qp.Name,
|
||||||
|
IgnoreCase = _settings.HeaderPatternIgnoreCase,
|
||||||
Matchers = new[]
|
Matchers = new[]
|
||||||
{
|
{
|
||||||
new MatcherModel
|
GetExampleMatcherModel(qp.Schema, _settings.HeaderPatternToUse)
|
||||||
{
|
|
||||||
Name = "ExactMatcher",
|
|
||||||
Pattern = GetDefaultValueAsStringForSchemaType(qp.Schema)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.ToList();
|
.ToList();
|
||||||
@@ -362,30 +360,26 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
|||||||
return list.Any() ? list : null;
|
return list.Any() ? list : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetDefaultValueAsStringForSchemaType(OpenApiSchema schema)
|
private MatcherModel GetExampleMatcherModel(OpenApiSchema schema, ExampleValueType type)
|
||||||
|
{
|
||||||
|
return type switch
|
||||||
|
{
|
||||||
|
ExampleValueType.Value => new MatcherModel { Name = "ExactMatcher", Pattern = GetExampleValueAsStringForSchemaType(schema), IgnoreCase = _settings.IgnoreCaseExampleValues },
|
||||||
|
|
||||||
|
_ => new MatcherModel { Name = "WildcardMatcher", Pattern = "*" }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetExampleValueAsStringForSchemaType(OpenApiSchema schema)
|
||||||
{
|
{
|
||||||
var value = _exampleValueGenerator.GetExampleValue(schema);
|
var value = _exampleValueGenerator.GetExampleValue(schema);
|
||||||
|
|
||||||
switch (value)
|
return value switch
|
||||||
{
|
{
|
||||||
case string valueAsString:
|
string valueAsString => valueAsString,
|
||||||
return valueAsString;
|
|
||||||
|
|
||||||
default:
|
_ => value.ToString(),
|
||||||
return value.ToString();
|
};
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetExampleValue(OpenApiSchema schema, ExampleValueType type)
|
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case ExampleValueType.Value:
|
|
||||||
return GetDefaultValueAsStringForSchemaType(schema);
|
|
||||||
|
|
||||||
default:
|
|
||||||
return "*";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using WireMock.Net.OpenApiParser.Types;
|
using WireMock.Net.OpenApiParser.Types;
|
||||||
|
|
||||||
namespace WireMock.Net.OpenApiParser.Settings
|
namespace WireMock.Net.OpenApiParser.Settings
|
||||||
{
|
{
|
||||||
@@ -23,12 +23,41 @@ namespace WireMock.Net.OpenApiParser.Settings
|
|||||||
public ExampleValueType HeaderPatternToUse { get; set; } = ExampleValueType.Value;
|
public ExampleValueType HeaderPatternToUse { get; set; } = ExampleValueType.Value;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The example values to use
|
/// The example value type to use when generating a Query Parameter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IWireMockOpenApiParserExampleValues ExampleValues { get; set; } = new WireMockOpenApiParserExampleValues();
|
public ExampleValueType QueryParameterPatternToUse { get; set; } = ExampleValueType.Value;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Are examples generated dynamically?
|
/// The example values to use.
|
||||||
|
///
|
||||||
|
/// Default implementations are:
|
||||||
|
/// - <see cref="WireMockOpenApiParserExampleValues"/>
|
||||||
|
/// - <see cref="WireMockOpenApiParserDynamicExampleValues"/>
|
||||||
|
/// </summary>
|
||||||
|
public IWireMockOpenApiParserExampleValues ExampleValues { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is a Header match case insensitive? (default is true).
|
||||||
|
/// </summary>
|
||||||
|
public bool HeaderPatternIgnoreCase { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is a Query Parameter match case insensitive? (default is true).
|
||||||
|
/// </summary>
|
||||||
|
public bool QueryParameterPatternIgnoreCase { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is a Request Body match case insensitive? (default is true).
|
||||||
|
/// </summary>
|
||||||
|
public bool RequestBodyIgnoreCase { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Is a ExampleValue match case insensitive? (default is true).
|
||||||
|
/// </summary>
|
||||||
|
public bool IgnoreCaseExampleValues { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Are examples generated dynamically? (default is false).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool DynamicExamples { get; set; } = false;
|
public bool DynamicExamples { get; set; } = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace WireMock.Net.OpenApiParser.Types
|
namespace WireMock.Net.OpenApiParser.Types
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The example value to use
|
/// The example value to use
|
||||||
@@ -6,7 +6,9 @@
|
|||||||
public enum ExampleValueType
|
public enum ExampleValueType
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Use a generated example value based on the SchemaType (default).
|
/// 1. Use a generated example value based on the SchemaType (default).
|
||||||
|
/// 2. If there is no example value defined in the schema,
|
||||||
|
/// then the <see cref="Settings.IWireMockOpenApiParserExampleValues"/> will be used (custom, fixed or dynamic).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Value,
|
Value,
|
||||||
|
|
||||||
|
|||||||
@@ -17,13 +17,17 @@ namespace WireMock.Net.OpenApiParser.Utils
|
|||||||
{
|
{
|
||||||
_settings = Guard.NotNull(settings, nameof(settings));
|
_settings = Guard.NotNull(settings, nameof(settings));
|
||||||
|
|
||||||
if (_settings.DynamicExamples)
|
// Check if user provided an own implementation
|
||||||
|
if (settings.ExampleValues is null)
|
||||||
{
|
{
|
||||||
_settings.ExampleValues = new WireMockOpenApiParserDynamicExampleValues();
|
if (_settings.DynamicExamples)
|
||||||
}
|
{
|
||||||
else
|
_settings.ExampleValues = new WireMockOpenApiParserDynamicExampleValues();
|
||||||
{
|
}
|
||||||
_settings.ExampleValues = new WireMockOpenApiParserExampleValues();
|
else
|
||||||
|
{
|
||||||
|
_settings.ExampleValues = new WireMockOpenApiParserExampleValues();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,6 +109,7 @@ namespace WireMock.Net.OpenApiParser.Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IOpenApiAny GetRandomEnumValue(IList<IOpenApiAny> schemaEnum)
|
private static IOpenApiAny GetRandomEnumValue(IList<IOpenApiAny> schemaEnum)
|
||||||
{
|
{
|
||||||
if (schemaEnum?.Count > 0)
|
if (schemaEnum?.Count > 0)
|
||||||
@@ -113,7 +118,8 @@ namespace WireMock.Net.OpenApiParser.Utils
|
|||||||
int randomEnum = new Random().Next(0, maxValue);
|
int randomEnum = new Random().Next(0, maxValue);
|
||||||
return schemaEnum[randomEnum];
|
return schemaEnum[randomEnum];
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||||
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3" />
|
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3" />
|
||||||
<PackageReference Include="RamlToOpenApiConverter" Version="0.4.3" />
|
<PackageReference Include="RamlToOpenApiConverter" Version="0.5.0" />
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
|
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.13" />
|
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.13" />
|
||||||
|
|||||||
@@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
|
||||||
<PackageReference Include="Microsoft.AspNet.WebApi.OwinSelfHost" Version="5.2.6" />
|
<PackageReference Include="Microsoft.AspNet.WebApi.OwinSelfHost" Version="5.2.6" />
|
||||||
<PackageReference Include="Microsoft.Owin" Version="4.0.0" />
|
<PackageReference Include="Microsoft.Owin" Version="4.1.1" />
|
||||||
<PackageReference Include="Microsoft.Owin.Host.HttpListener" Version="4.0.0" />
|
<PackageReference Include="Microsoft.Owin.Host.HttpListener" Version="4.0.0" />
|
||||||
<PackageReference Include="Microsoft.Owin.Hosting" Version="4.0.0" />
|
<PackageReference Include="Microsoft.Owin.Hosting" Version="4.0.0" />
|
||||||
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||||
|
|||||||
@@ -32,8 +32,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Codecov" Version="1.10.0" />
|
<PackageReference Include="Codecov" Version="1.13.0" />
|
||||||
<PackageReference Include="coverlet.msbuild" Version="3.0.2">
|
<PackageReference Include="coverlet.msbuild" Version="3.1.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
@@ -44,18 +44,18 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="coverlet.collector" Version="3.0.2">
|
<PackageReference Include="coverlet.collector" Version="3.1.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
|
||||||
<PackageReference Include="Moq" Version="4.16.0" />
|
<PackageReference Include="Moq" Version="4.16.1" />
|
||||||
<PackageReference Include="System.Threading" Version="4.3.0" />
|
<PackageReference Include="System.Threading" Version="4.3.0" />
|
||||||
<PackageReference Include="RestEase" Version="1.5.5" />
|
<PackageReference Include="RestEase" Version="1.5.5" />
|
||||||
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.13" />
|
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.13" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||||
<PackageReference Include="NFluent" Version="2.7.1" />
|
<PackageReference Include="NFluent" Version="2.7.2" />
|
||||||
<!--<PackageReference Include="OpenCover" Version="4.7.922" />-->
|
<!--<PackageReference Include="OpenCover" Version="4.7.922" />-->
|
||||||
<!--<PackageReference Include="ReportGenerator" Version="4.8.1" />-->
|
<!--<PackageReference Include="ReportGenerator" Version="4.8.1" />-->
|
||||||
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
|
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
|
||||||
|
|||||||
Reference in New Issue
Block a user