Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
</PropertyGroup>

<ItemGroup>
<!--<PackageReference Include="Microsoft.OpenApi.YamlReader" Version="3.7.0" />-->

<ProjectReference Include="..\..\src\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net.OpenApiParser\WireMock.Net.OpenApiParser.csproj" />
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' == 'Release'">
<PackageReference Include="Microsoft.OpenApi" Version="3.7.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.OpenApi" Version="3.10.2" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// Copyright © WireMock.Net


using System.Diagnostics.CodeAnalysis;

namespace System.Collections.Generic;

internal static class DictionaryExtensions
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
29 changes: 29 additions & 0 deletions src/WireMock.Net.OpenApiParser/ILRepack.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8" ?>

<!-- See also https://github.com/ravibpatel/ILRepack.Lib.MSBuild.Task/issues/26 -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="ILRepacker" AfterTargets="Build" Condition="'$(Configuration)' == 'Release'">
<ItemGroup>
<InputAssemblies Include="$(OutputPath)WireMock.Net.OpenApiParser.dll" />
<InputAssemblies Include="@(ReferencePathWithRefAssemblies)" Condition="'%(filename)' == 'Microsoft.OpenApi.YamlReader'" />
<InputAssemblies Include="@(ReferencePathWithRefAssemblies)" Condition="'%(filename)' == 'Microsoft.OpenApi'" />
<LibraryPath Include="%(ReferencePathWithRefAssemblies.RelativeDir)" />
</ItemGroup>

<ItemGroup>
<DoNotInternalizeAssemblies Include="WireMock.Net.OpenApiParser" />
</ItemGroup>

<ILRepack
Parallel="true"
Internalize="true"
RenameInternalized="true"
InternalizeExclude="@(DoNotInternalizeAssemblies)"
InputAssemblies="@(InputAssemblies)"
LibraryPath="@(LibraryPath)"
TargetKind="Dll"
KeyFile="../../src/WireMock.Net/WireMock.Net.snk"
OutputFile="$(OutputPath)$(AssemblyName).dll"
/>
</Target>
</Project>
2 changes: 1 addition & 1 deletion src/WireMock.Net.OpenApiParser/IWireMockOpenApiParser.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
25 changes: 25 additions & 0 deletions src/WireMock.Net.OpenApiParser/Models/OpenApiDiagnostic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

namespace WireMock.Net.OpenApiParser.Models;

/// <summary>
/// Object containing all diagnostic information related to Open API parsing.
/// </summary>
public class OpenApiDiagnostic
{
/// <summary>
/// List of all errors.
/// </summary>
public List<OpenApiError> Errors { get; set; } = [];

/// <summary>
/// List of all warnings
/// </summary>
public List<OpenApiError> Warnings { get; set; } = [];

/// <summary>
/// Open API specification version of the document parsed.
/// </summary>
public OpenApiSpecVersion SpecificationVersion { get; set; }
}
46 changes: 46 additions & 0 deletions src/WireMock.Net.OpenApiParser/Models/OpenApiError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

namespace WireMock.Net.OpenApiParser.Models;

/// <summary>
/// Error related to the Open API Document.
/// </summary>
public class OpenApiError
{
/// <summary>
/// Initializes the <see cref="OpenApiError"/> class.
/// </summary>
public OpenApiError(string? pointer, string message)
{
Pointer = pointer;
Message = message;
}

/// <summary>
/// Initializes a copy of an <see cref="OpenApiError"/> object
/// </summary>
public OpenApiError(OpenApiError error)
{
Pointer = error.Pointer;
Message = error.Message;
}

/// <summary>
/// Message explaining the error.
/// </summary>
public string Message { get; set; }

/// <summary>
/// Pointer to the location of the error.
/// </summary>
public string? Pointer { get; set; }

/// <summary>
/// Gets the string representation of <see cref="OpenApiError"/>.
/// </summary>
public override string ToString()
{
return Message + (!string.IsNullOrEmpty(Pointer) ? " [" + Pointer + "]" : "");
}
}
23 changes: 23 additions & 0 deletions src/WireMock.Net.OpenApiParser/Models/OpenApiMapper.cs
Original file line number Diff line number Diff line change
@@ -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
};
}
}
29 changes: 29 additions & 0 deletions src/WireMock.Net.OpenApiParser/Models/OpenApiSpecVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright © WireMock.Net

namespace WireMock.Net.OpenApiParser.Models;

/// <summary>
/// Represents versions of OpenAPI specification.
/// </summary>
public enum OpenApiSpecVersion
{
/// <summary>
/// Represents OpenAPI V2.0 spec
/// </summary>
OpenApi2_0,

/// <summary>
/// Represents all patches of OpenAPI V3.0 spec (e.g. 3.0.0, 3.0.1)
/// </summary>
OpenApi3_0,

/// <summary>
/// Represents OpenAPI V3.1 spec
/// </summary>
OpenApi3_1,

/// <summary>
/// Represents OpenAPI V3.2 spec
/// </summary>
OpenApi3_2
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright © WireMock.Net

using System;
using Microsoft.OpenApi;

namespace WireMock.Net.OpenApiParser.Settings;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright © WireMock.Net

using System;
using Microsoft.OpenApi;
using RandomDataGenerator.FieldOptions;
using RandomDataGenerator.Randomizers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright © WireMock.Net

using System;
using Microsoft.OpenApi;

namespace WireMock.Net.OpenApiParser.Settings;
Expand Down
1 change: 0 additions & 1 deletion src/WireMock.Net.OpenApiParser/Utils/DateTimeUtils.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright © WireMock.Net

using System;
using System.Globalization;

namespace WireMock.Net.OpenApiParser.Utils;
Expand Down
2 changes: 0 additions & 2 deletions src/WireMock.Net.OpenApiParser/Utils/ExampleValueGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright © WireMock.Net

using System;
using System.Linq;
using System.Text.Json.Nodes;
using Microsoft.OpenApi;
using Stef.Validation;
Expand Down
20 changes: 18 additions & 2 deletions src/WireMock.Net.OpenApiParser/WireMock.Net.OpenApiParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Required" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -40,11 +40,27 @@

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="RamlToOpenApiConverter" Version="0.40.0" />
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.19.1" />
<PackageReference Include="Stef.Validation" Version="0.3.0" />
</ItemGroup>

<!-- https://github.com/wiremock/WireMock.Net/issues/1508 -->
<ItemGroup>
<PackageReference Include="RamlToOpenApiConverter.SourceOnly" Version="0.40.0" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<PackageReference Include="Microsoft.OpenApi.YamlReader" Version="3.10.2" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' == 'Release'">
<!-- Keep at version 2.0.43 (https://github.com/ravibpatel/ILRepack.Lib.MSBuild.Task/issues/80) -->
<PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.43" PrivateAssets="All" />
<PackageReference Include="Microsoft.OpenApi" Version="3.10.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.OpenApi.YamlReader" Version="3.10.2" PrivateAssets="All" />
<PackageReference Include="SharpYaml" Version="2.1.5" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
</ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/WireMock.Net.OpenApiParser/WireMockOpenApiParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down
Loading