mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-26 02:51:04 +01:00
* Fix construction of path in OpenApiParser (#1265) * Server-Sent Events (#1269) * Server Side Events * fixes * await HandleSseStringAsync(responseMessage, response, bodyData); * 1.7.5-preview-01 * IBlockingQueue * 1.7.5-preview-02 (03 April 2025) * IBlockingQueue * ... * Support OpenApi V31 (#1279) * Support OpenApi V31 * Update src/WireMock.Net.OpenApiParser/Extensions/OpenApiSchemaExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fx --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add ProtoDefinitionHelper.FromDirectory (#1263) * Add ProtoDefinitionHelper.FromDirectory * . * unix-windows * move test * imports in the proto files indeed should use a forward slash * updates * . * private Func<IdOrTexts> ProtoDefinitionFunc() * OpenTelemetry * . * fix path utils --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
96 lines
4.3 KiB
C#
96 lines
4.3 KiB
C#
// Copyright © WireMock.Net
|
|
|
|
using System.IO;
|
|
using System.Linq;
|
|
using JetBrains.Annotations;
|
|
using Microsoft.OpenApi.Models;
|
|
using Microsoft.OpenApi.Reader;
|
|
using Stef.Validation;
|
|
using WireMock.Net.OpenApiParser.Settings;
|
|
using WireMock.Server;
|
|
|
|
namespace WireMock.Net.OpenApiParser.Extensions;
|
|
|
|
/// <summary>
|
|
/// Some extension methods for <see cref="IWireMockServer"/>.
|
|
/// </summary>
|
|
public static class WireMockServerExtensions
|
|
{
|
|
/// <summary>
|
|
/// Register the mappings via an OpenAPI (swagger) V2/V3/V3.1 file.
|
|
/// </summary>
|
|
/// <param name="server">The WireMockServer instance</param>
|
|
/// <param name="path">Path containing OpenAPI file to parse and use the mappings.</param>
|
|
/// <param name="diagnostic">Returns diagnostic object containing errors detected during parsing</param>
|
|
[PublicAPI]
|
|
public static IWireMockServer WithMappingFromOpenApiFile(this IWireMockServer server, string path, out OpenApiDiagnostic diagnostic)
|
|
{
|
|
return WithMappingFromOpenApiFile(server, path, new WireMockOpenApiParserSettings(), out diagnostic);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register the mappings via an OpenAPI (swagger) V2/V3/V3.1 file.
|
|
/// </summary>
|
|
/// <param name="server">The WireMockServer instance</param>
|
|
/// <param name="path">Path containing OpenAPI file to parse and use the mappings.</param>
|
|
/// <param name="settings">Additional settings</param>
|
|
/// <param name="diagnostic">Returns diagnostic object containing errors detected during parsing</param>
|
|
[PublicAPI]
|
|
public static IWireMockServer WithMappingFromOpenApiFile(this IWireMockServer server, string path, WireMockOpenApiParserSettings settings, out OpenApiDiagnostic diagnostic)
|
|
{
|
|
Guard.NotNull(server);
|
|
Guard.NotNullOrEmpty(path);
|
|
|
|
var mappings = new WireMockOpenApiParser().FromFile(path, settings, out diagnostic);
|
|
|
|
return server.WithMapping(mappings.ToArray());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register the mappings via an OpenAPI (swagger) V2/V3/V3.1 stream.
|
|
/// </summary>
|
|
/// <param name="server">The WireMockServer instance</param>
|
|
/// <param name="stream">Stream containing OpenAPI description to parse and use the mappings.</param>
|
|
/// <param name="diagnostic">Returns diagnostic object containing errors detected during parsing</param>
|
|
[PublicAPI]
|
|
public static IWireMockServer WithMappingFromOpenApiStream(this IWireMockServer server, Stream stream, out OpenApiDiagnostic diagnostic)
|
|
{
|
|
return WithMappingFromOpenApiStream(server, stream, new WireMockOpenApiParserSettings(), out diagnostic);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register the mappings via an OpenAPI (swagger) V2/V3/V3.1 stream.
|
|
/// </summary>
|
|
/// <param name="server">The WireMockServer instance</param>
|
|
/// <param name="stream">Stream containing OpenAPI description to parse and use the mappings.</param>
|
|
/// <param name="settings">Additional settings</param>
|
|
/// <param name="diagnostic">Returns diagnostic object containing errors detected during parsing</param>
|
|
[PublicAPI]
|
|
public static IWireMockServer WithMappingFromOpenApiStream(this IWireMockServer server, Stream stream, WireMockOpenApiParserSettings settings, out OpenApiDiagnostic diagnostic)
|
|
{
|
|
Guard.NotNull(server);
|
|
Guard.NotNull(stream);
|
|
Guard.NotNull(settings);
|
|
|
|
var mappings = new WireMockOpenApiParser().FromStream(stream, settings, out diagnostic);
|
|
|
|
return server.WithMapping(mappings.ToArray());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Register the mappings via an OpenAPI (swagger) V2/V3/V3.1 document.
|
|
/// </summary>
|
|
/// <param name="server">The WireMockServer instance</param>
|
|
/// <param name="document">The OpenAPI document to use as mappings.</param>
|
|
/// <param name="settings">Additional settings [optional].</param>
|
|
[PublicAPI]
|
|
public static IWireMockServer WithMappingFromOpenApiDocument(this IWireMockServer server, OpenApiDocument document, WireMockOpenApiParserSettings? settings = null)
|
|
{
|
|
Guard.NotNull(server);
|
|
Guard.NotNull(document);
|
|
|
|
var mappings = new WireMockOpenApiParser().FromDocument(document, settings);
|
|
|
|
return server.WithMapping(mappings.ToArray());
|
|
}
|
|
} |