mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 01:08:49 +02:00
@@ -1,5 +1,6 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using Microsoft.OpenApi.Any;
|
using Microsoft.OpenApi.Any;
|
||||||
using Microsoft.OpenApi.Interfaces;
|
using Microsoft.OpenApi.Interfaces;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
@@ -16,7 +17,7 @@ internal static class OpenApiSchemaExtensions
|
|||||||
{
|
{
|
||||||
value = false;
|
value = false;
|
||||||
|
|
||||||
if (schema.Extensions.TryGetValue("x-nullable", out IOpenApiExtension e) && e is OpenApiBoolean openApiBoolean)
|
if (schema.Extensions.TryGetValue("x-nullable", out var e) && e is OpenApiBoolean openApiBoolean)
|
||||||
{
|
{
|
||||||
value = openApiBoolean.Value;
|
value = openApiBoolean.Value;
|
||||||
return true;
|
return true;
|
||||||
@@ -27,32 +28,30 @@ internal static class OpenApiSchemaExtensions
|
|||||||
|
|
||||||
public static SchemaType GetSchemaType(this OpenApiSchema? schema)
|
public static SchemaType GetSchemaType(this OpenApiSchema? schema)
|
||||||
{
|
{
|
||||||
switch (schema?.Type)
|
if (schema == null)
|
||||||
{
|
{
|
||||||
case "object":
|
return SchemaType.Unknown;
|
||||||
return SchemaType.Object;
|
|
||||||
|
|
||||||
case "array":
|
|
||||||
return SchemaType.Array;
|
|
||||||
|
|
||||||
case "integer":
|
|
||||||
return SchemaType.Integer;
|
|
||||||
|
|
||||||
case "number":
|
|
||||||
return SchemaType.Number;
|
|
||||||
|
|
||||||
case "boolean":
|
|
||||||
return SchemaType.Boolean;
|
|
||||||
|
|
||||||
case "string":
|
|
||||||
return SchemaType.String;
|
|
||||||
|
|
||||||
case "file":
|
|
||||||
return SchemaType.File;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return SchemaType.Unknown;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (schema.Type == null)
|
||||||
|
{
|
||||||
|
if (schema.AllOf.Any() || schema.AnyOf.Any())
|
||||||
|
{
|
||||||
|
return SchemaType.Object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return schema.Type switch
|
||||||
|
{
|
||||||
|
"object" => SchemaType.Object,
|
||||||
|
"array" => SchemaType.Array,
|
||||||
|
"integer" => SchemaType.Integer,
|
||||||
|
"number" => SchemaType.Number,
|
||||||
|
"boolean" => SchemaType.Boolean,
|
||||||
|
"string" => SchemaType.String,
|
||||||
|
"file" => SchemaType.File,
|
||||||
|
_ => SchemaType.Unknown
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SchemaFormat GetSchemaFormat(this OpenApiSchema? schema)
|
public static SchemaFormat GetSchemaFormat(this OpenApiSchema? schema)
|
||||||
|
|||||||
@@ -193,7 +193,8 @@ internal class OpenApiPathsMapper
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
jArray.Add(MapSchemaToObject(schema.Items, name));
|
var arrayItem = MapSchemaToObject(schema.Items, name: null); // Set name to null to force JObject instead of JProperty
|
||||||
|
jArray.Add(arrayItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,12 +220,9 @@ internal class OpenApiPathsMapper
|
|||||||
|
|
||||||
if (schema.AllOf.Count > 0)
|
if (schema.AllOf.Count > 0)
|
||||||
{
|
{
|
||||||
foreach (var property in schema.AllOf)
|
foreach (var group in schema.AllOf.SelectMany(p => p.Properties).GroupBy(x => x.Key))
|
||||||
{
|
{
|
||||||
foreach (var item in property.Properties)
|
propertyAsJObject.Add(MapPropertyAsJObject(group.First().Value, group.Key));
|
||||||
{
|
|
||||||
propertyAsJObject.Add(MapPropertyAsJObject(item.Value, item.Key));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,27 +39,35 @@ public class WireMockOpenApiParserSettings
|
|||||||
public IWireMockOpenApiParserExampleValues? ExampleValues { get; set; }
|
public IWireMockOpenApiParserExampleValues? ExampleValues { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is a Header match case insensitive? (default is true).
|
/// Is a Header match case-insensitive?
|
||||||
|
///
|
||||||
|
/// Default is <c>true</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool HeaderPatternIgnoreCase { get; set; } = true;
|
public bool HeaderPatternIgnoreCase { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is a Query Parameter match case insensitive? (default is true).
|
/// Is a Query Parameter match case-insensitive?
|
||||||
|
///
|
||||||
|
/// Default is <c>true</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool QueryParameterPatternIgnoreCase { get; set; } = true;
|
public bool QueryParameterPatternIgnoreCase { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is a Request Body match case insensitive? (default is true).
|
/// Is a Request Body match case-insensitive?
|
||||||
|
///
|
||||||
|
/// Default is <c>true</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool RequestBodyIgnoreCase { get; set; } = true;
|
public bool RequestBodyIgnoreCase { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is a ExampleValue match case insensitive? (default is true).
|
/// Is a ExampleValue match case-insensitive?
|
||||||
|
///
|
||||||
|
/// Default is <c>true</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IgnoreCaseExampleValues { get; set; } = true;
|
public bool IgnoreCaseExampleValues { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Are examples generated dynamically? (default is false).
|
/// Are examples generated dynamically?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool DynamicExamples { get; set; } = false;
|
public bool DynamicExamples { get; set; }
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,51 @@
|
|||||||
|
#if !(NET452 || NET461 || NETCOREAPP3_1)
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Moq;
|
||||||
|
using VerifyXunit;
|
||||||
|
using WireMock.Net.OpenApiParser;
|
||||||
|
using WireMock.Net.OpenApiParser.Settings;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace WireMock.Net.Tests.OpenApiParser;
|
||||||
|
|
||||||
|
[UsesVerify]
|
||||||
|
public class WireMockOpenApiParserTests
|
||||||
|
{
|
||||||
|
private readonly Mock<IWireMockOpenApiParserExampleValues> _exampleValuesMock = new();
|
||||||
|
|
||||||
|
private readonly WireMockOpenApiParser _sut = new();
|
||||||
|
|
||||||
|
public WireMockOpenApiParserTests()
|
||||||
|
{
|
||||||
|
_exampleValuesMock.SetupGet(e => e.Boolean).Returns(true);
|
||||||
|
_exampleValuesMock.SetupGet(e => e.Integer).Returns(42);
|
||||||
|
_exampleValuesMock.SetupGet(e => e.Float).Returns(1.1f);
|
||||||
|
_exampleValuesMock.SetupGet(e => e.Double).Returns(2.2d);
|
||||||
|
_exampleValuesMock.SetupGet(e => e.String).Returns("example-string");
|
||||||
|
_exampleValuesMock.SetupGet(e => e.Object).Returns("example-object");
|
||||||
|
_exampleValuesMock.SetupGet(e => e.Bytes).Returns("Stef"u8.ToArray());
|
||||||
|
_exampleValuesMock.SetupGet(e => e.Date).Returns(() => new DateTime(2024, 6, 19));
|
||||||
|
_exampleValuesMock.SetupGet(e => e.DateTime).Returns(() => new DateTime(2024, 6, 19, 12, 34, 56, DateTimeKind.Utc));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task FromText_ShouldReturnMappings()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var settings = new WireMockOpenApiParserSettings
|
||||||
|
{
|
||||||
|
ExampleValues = _exampleValuesMock.Object
|
||||||
|
};
|
||||||
|
|
||||||
|
var openApiDocument = await File.ReadAllTextAsync(Path.Combine("OpenApiParser", "payroc-openapi-spec.yaml"));
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var mappings = _sut.FromText(openApiDocument, settings, out _);
|
||||||
|
|
||||||
|
// Verify
|
||||||
|
await Verifier.Verify(mappings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
24187
test/WireMock.Net.Tests/OpenApiParser/payroc-openapi-spec.yaml
Normal file
24187
test/WireMock.Net.Tests/OpenApiParser/payroc-openapi-spec.yaml
Normal file
File diff suppressed because it is too large
Load Diff
@@ -128,6 +128,9 @@
|
|||||||
<None Update="OpenApiParser\*.yml">
|
<None Update="OpenApiParser\*.yml">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
<None Update="OpenApiParser\*.yaml">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
<None Update="cert.pem">
|
<None Update="cert.pem">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
|||||||
Reference in New Issue
Block a user