From ce2f781fe5c3ce7c83b2e583646068ba7136cc63 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 21 Sep 2026 20:38:30 +0200 Subject: [PATCH] Revert to RamlToOpenApiConverter.SourceOnly --- ...reMock.Net.OpenApiParser.ConsoleApp.csproj | 4 +- .../Extensions/DictionaryExtensions.cs | 3 -- .../Extensions/WireMockServerExtensions.cs | 2 +- .../ILRepack.targets | 29 ++++++++++++ .../IWireMockOpenApiParser.cs | 2 +- .../Models/OpenApiDiagnostic.cs | 25 ++++++++++ .../Models/OpenApiError.cs | 46 +++++++++++++++++++ .../Models/OpenApiMapper.cs | 23 ++++++++++ .../Models/OpenApiSpecVersion.cs | 29 ++++++++++++ .../IWireMockOpenApiParserExampleValues.cs | 1 - ...reMockOpenApiParserDynamicExampleValues.cs | 1 - .../WireMockOpenApiParserExampleValues.cs | 1 - .../Utils/DateTimeUtils.cs | 1 - .../Utils/ExampleValueGenerator.cs | 2 - .../WireMock.Net.OpenApiParser.csproj | 20 +++++++- .../WireMockOpenApiParser.cs | 4 +- 16 files changed, 176 insertions(+), 17 deletions(-) create mode 100644 src/WireMock.Net.OpenApiParser/ILRepack.targets create mode 100644 src/WireMock.Net.OpenApiParser/Models/OpenApiDiagnostic.cs create mode 100644 src/WireMock.Net.OpenApiParser/Models/OpenApiError.cs create mode 100644 src/WireMock.Net.OpenApiParser/Models/OpenApiMapper.cs create mode 100644 src/WireMock.Net.OpenApiParser/Models/OpenApiSpecVersion.cs diff --git a/examples/WireMock.Net.OpenApiParser.ConsoleApp/WireMock.Net.OpenApiParser.ConsoleApp.csproj b/examples/WireMock.Net.OpenApiParser.ConsoleApp/WireMock.Net.OpenApiParser.ConsoleApp.csproj index e35ba9fde..310ef0635 100644 --- a/examples/WireMock.Net.OpenApiParser.ConsoleApp/WireMock.Net.OpenApiParser.ConsoleApp.csproj +++ b/examples/WireMock.Net.OpenApiParser.ConsoleApp/WireMock.Net.OpenApiParser.ConsoleApp.csproj @@ -6,15 +6,13 @@ - - - + diff --git a/src/WireMock.Net.OpenApiParser/Extensions/DictionaryExtensions.cs b/src/WireMock.Net.OpenApiParser/Extensions/DictionaryExtensions.cs index aec4ac2ff..5a5ea0b8d 100644 --- a/src/WireMock.Net.OpenApiParser/Extensions/DictionaryExtensions.cs +++ b/src/WireMock.Net.OpenApiParser/Extensions/DictionaryExtensions.cs @@ -1,8 +1,5 @@ // Copyright © WireMock.Net - -using System.Diagnostics.CodeAnalysis; - namespace System.Collections.Generic; internal static class DictionaryExtensions diff --git a/src/WireMock.Net.OpenApiParser/Extensions/WireMockServerExtensions.cs b/src/WireMock.Net.OpenApiParser/Extensions/WireMockServerExtensions.cs index 7e763b557..bde129122 100644 --- a/src/WireMock.Net.OpenApiParser/Extensions/WireMockServerExtensions.cs +++ b/src/WireMock.Net.OpenApiParser/Extensions/WireMockServerExtensions.cs @@ -1,8 +1,8 @@ // Copyright © WireMock.Net using JetBrains.Annotations; -using Microsoft.OpenApi.Reader; using Stef.Validation; +using WireMock.Net.OpenApiParser.Models; using WireMock.Net.OpenApiParser.Settings; using WireMock.Server; diff --git a/src/WireMock.Net.OpenApiParser/ILRepack.targets b/src/WireMock.Net.OpenApiParser/ILRepack.targets new file mode 100644 index 000000000..71bd22d44 --- /dev/null +++ b/src/WireMock.Net.OpenApiParser/ILRepack.targets @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/WireMock.Net.OpenApiParser/IWireMockOpenApiParser.cs b/src/WireMock.Net.OpenApiParser/IWireMockOpenApiParser.cs index 7c4515587..c09fa6e7d 100644 --- a/src/WireMock.Net.OpenApiParser/IWireMockOpenApiParser.cs +++ b/src/WireMock.Net.OpenApiParser/IWireMockOpenApiParser.cs @@ -1,7 +1,7 @@ // Copyright © WireMock.Net -using Microsoft.OpenApi.Reader; using WireMock.Admin.Mappings; +using WireMock.Net.OpenApiParser.Models; using WireMock.Net.OpenApiParser.Settings; namespace WireMock.Net.OpenApiParser; diff --git a/src/WireMock.Net.OpenApiParser/Models/OpenApiDiagnostic.cs b/src/WireMock.Net.OpenApiParser/Models/OpenApiDiagnostic.cs new file mode 100644 index 000000000..220932449 --- /dev/null +++ b/src/WireMock.Net.OpenApiParser/Models/OpenApiDiagnostic.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +namespace WireMock.Net.OpenApiParser.Models; + +/// +/// Object containing all diagnostic information related to Open API parsing. +/// +public class OpenApiDiagnostic +{ + /// + /// List of all errors. + /// + public List Errors { get; set; } = []; + + /// + /// List of all warnings + /// + public List Warnings { get; set; } = []; + + /// + /// Open API specification version of the document parsed. + /// + public OpenApiSpecVersion SpecificationVersion { get; set; } +} \ No newline at end of file diff --git a/src/WireMock.Net.OpenApiParser/Models/OpenApiError.cs b/src/WireMock.Net.OpenApiParser/Models/OpenApiError.cs new file mode 100644 index 000000000..b3d8bbe0b --- /dev/null +++ b/src/WireMock.Net.OpenApiParser/Models/OpenApiError.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +namespace WireMock.Net.OpenApiParser.Models; + +/// +/// Error related to the Open API Document. +/// +public class OpenApiError +{ + /// + /// Initializes the class. + /// + public OpenApiError(string? pointer, string message) + { + Pointer = pointer; + Message = message; + } + + /// + /// Initializes a copy of an object + /// + public OpenApiError(OpenApiError error) + { + Pointer = error.Pointer; + Message = error.Message; + } + + /// + /// Message explaining the error. + /// + public string Message { get; set; } + + /// + /// Pointer to the location of the error. + /// + public string? Pointer { get; set; } + + /// + /// Gets the string representation of . + /// + public override string ToString() + { + return Message + (!string.IsNullOrEmpty(Pointer) ? " [" + Pointer + "]" : ""); + } +} \ No newline at end of file diff --git a/src/WireMock.Net.OpenApiParser/Models/OpenApiMapper.cs b/src/WireMock.Net.OpenApiParser/Models/OpenApiMapper.cs new file mode 100644 index 000000000..b203c7f10 --- /dev/null +++ b/src/WireMock.Net.OpenApiParser/Models/OpenApiMapper.cs @@ -0,0 +1,23 @@ +// Copyright © WireMock.Net + +using MicrosoftOpenApiDiagnostic = Microsoft.OpenApi.Reader.OpenApiDiagnostic; + +namespace WireMock.Net.OpenApiParser.Models; + +internal static class OpenApiMapper +{ + internal static OpenApiDiagnostic? Map(MicrosoftOpenApiDiagnostic? openApiDiagnostic) + { + if (openApiDiagnostic == null) + { + return null; + } + + return new OpenApiDiagnostic + { + Errors = openApiDiagnostic.Errors.Select(e => new OpenApiError(e.Pointer, e.Message)).ToList(), + Warnings = openApiDiagnostic.Warnings.Select(e => new OpenApiError(e.Pointer, e.Message)).ToList(), + SpecificationVersion = (OpenApiSpecVersion)openApiDiagnostic.SpecificationVersion + }; + } +} \ No newline at end of file diff --git a/src/WireMock.Net.OpenApiParser/Models/OpenApiSpecVersion.cs b/src/WireMock.Net.OpenApiParser/Models/OpenApiSpecVersion.cs new file mode 100644 index 000000000..31433dd40 --- /dev/null +++ b/src/WireMock.Net.OpenApiParser/Models/OpenApiSpecVersion.cs @@ -0,0 +1,29 @@ +// Copyright © WireMock.Net + +namespace WireMock.Net.OpenApiParser.Models; + +/// +/// Represents versions of OpenAPI specification. +/// +public enum OpenApiSpecVersion +{ + /// + /// Represents OpenAPI V2.0 spec + /// + OpenApi2_0, + + /// + /// Represents all patches of OpenAPI V3.0 spec (e.g. 3.0.0, 3.0.1) + /// + OpenApi3_0, + + /// + /// Represents OpenAPI V3.1 spec + /// + OpenApi3_1, + + /// + /// Represents OpenAPI V3.2 spec + /// + OpenApi3_2 +} \ No newline at end of file diff --git a/src/WireMock.Net.OpenApiParser/Settings/IWireMockOpenApiParserExampleValues.cs b/src/WireMock.Net.OpenApiParser/Settings/IWireMockOpenApiParserExampleValues.cs index 6c3b39538..689469537 100644 --- a/src/WireMock.Net.OpenApiParser/Settings/IWireMockOpenApiParserExampleValues.cs +++ b/src/WireMock.Net.OpenApiParser/Settings/IWireMockOpenApiParserExampleValues.cs @@ -1,6 +1,5 @@ // Copyright © WireMock.Net -using System; using Microsoft.OpenApi; namespace WireMock.Net.OpenApiParser.Settings; diff --git a/src/WireMock.Net.OpenApiParser/Settings/WireMockOpenApiParserDynamicExampleValues.cs b/src/WireMock.Net.OpenApiParser/Settings/WireMockOpenApiParserDynamicExampleValues.cs index 0f27bf31b..26ce5719f 100644 --- a/src/WireMock.Net.OpenApiParser/Settings/WireMockOpenApiParserDynamicExampleValues.cs +++ b/src/WireMock.Net.OpenApiParser/Settings/WireMockOpenApiParserDynamicExampleValues.cs @@ -1,6 +1,5 @@ // Copyright © WireMock.Net -using System; using Microsoft.OpenApi; using RandomDataGenerator.FieldOptions; using RandomDataGenerator.Randomizers; diff --git a/src/WireMock.Net.OpenApiParser/Settings/WireMockOpenApiParserExampleValues.cs b/src/WireMock.Net.OpenApiParser/Settings/WireMockOpenApiParserExampleValues.cs index 5acec53a5..132d86e11 100644 --- a/src/WireMock.Net.OpenApiParser/Settings/WireMockOpenApiParserExampleValues.cs +++ b/src/WireMock.Net.OpenApiParser/Settings/WireMockOpenApiParserExampleValues.cs @@ -1,6 +1,5 @@ // Copyright © WireMock.Net -using System; using Microsoft.OpenApi; namespace WireMock.Net.OpenApiParser.Settings; diff --git a/src/WireMock.Net.OpenApiParser/Utils/DateTimeUtils.cs b/src/WireMock.Net.OpenApiParser/Utils/DateTimeUtils.cs index e31785490..40ac33809 100644 --- a/src/WireMock.Net.OpenApiParser/Utils/DateTimeUtils.cs +++ b/src/WireMock.Net.OpenApiParser/Utils/DateTimeUtils.cs @@ -1,6 +1,5 @@ // Copyright © WireMock.Net -using System; using System.Globalization; namespace WireMock.Net.OpenApiParser.Utils; diff --git a/src/WireMock.Net.OpenApiParser/Utils/ExampleValueGenerator.cs b/src/WireMock.Net.OpenApiParser/Utils/ExampleValueGenerator.cs index 1ee9920f5..6a09e8741 100644 --- a/src/WireMock.Net.OpenApiParser/Utils/ExampleValueGenerator.cs +++ b/src/WireMock.Net.OpenApiParser/Utils/ExampleValueGenerator.cs @@ -1,7 +1,5 @@ // Copyright © WireMock.Net -using System; -using System.Linq; using System.Text.Json.Nodes; using Microsoft.OpenApi; using Stef.Validation; diff --git a/src/WireMock.Net.OpenApiParser/WireMock.Net.OpenApiParser.csproj b/src/WireMock.Net.OpenApiParser/WireMock.Net.OpenApiParser.csproj index 3a6031267..14cffae46 100644 --- a/src/WireMock.Net.OpenApiParser/WireMock.Net.OpenApiParser.csproj +++ b/src/WireMock.Net.OpenApiParser/WireMock.Net.OpenApiParser.csproj @@ -23,7 +23,7 @@ true - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -40,11 +40,27 @@ - + + + + + + + + + + + + + + + + + diff --git a/src/WireMock.Net.OpenApiParser/WireMockOpenApiParser.cs b/src/WireMock.Net.OpenApiParser/WireMockOpenApiParser.cs index 5d675ef32..379f65766 100644 --- a/src/WireMock.Net.OpenApiParser/WireMockOpenApiParser.cs +++ b/src/WireMock.Net.OpenApiParser/WireMockOpenApiParser.cs @@ -9,7 +9,9 @@ using RamlToOpenApiConverter; using WireMock.Admin.Mappings; using WireMock.Net.OpenApiParser.Mappers; +using WireMock.Net.OpenApiParser.Models; using WireMock.Net.OpenApiParser.Settings; +using OpenApiDiagnostic = WireMock.Net.OpenApiParser.Models.OpenApiDiagnostic; namespace WireMock.Net.OpenApiParser; @@ -125,7 +127,7 @@ private bool TryRead(Stream stream, [NotNullWhen(true)] out OpenApiDocument? ope var result = OpenApiDocument.Load(memoryStream, settings: _readerSettings); - diagnostic = result.Diagnostic ?? new OpenApiDiagnostic(); + diagnostic = OpenApiMapper.Map(result.Diagnostic) ?? new OpenApiDiagnostic(); openApiDocument = result.Document; return openApiDocument != null && !diagnostic.Errors.Any(); }