Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2.0.0-preview5 #2077

Merged
merged 134 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 131 commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
30ee6ed
fix: single copy and maintain for references
baywet Dec 27, 2024
6f4e7a2
fix: uses backing fields instead of schema copy
baywet Dec 27, 2024
0a7b4f6
chore: linting
baywet Dec 30, 2024
10e548a
feat: adds components registration method for schemas
baywet Dec 30, 2024
72db982
chore: linting
baywet Dec 30, 2024
efd2bfb
feat; adds a method to register and add the component schemas
baywet Dec 30, 2024
7994691
fix: null propagation for most failed reference lookup
baywet Dec 30, 2024
e3325b9
fix: aligns missing properties for override
baywet Dec 31, 2024
8d57b81
fix: aligns to null propagation operator
baywet Dec 31, 2024
b727581
fix: updates public api file
baywet Dec 31, 2024
5b4c94e
chore: linting
baywet Dec 31, 2024
e366566
chore: linting
baywet Dec 31, 2024
a231748
chore: linting
baywet Dec 31, 2024
878593b
fix: side effects in tag references
baywet Dec 31, 2024
9db6e2d
fix: potential NRT
baywet Dec 31, 2024
ff1406c
fix: passes missing host document references to all layers
baywet Dec 31, 2024
1368eed
chore(deps): bump coverlet.collector from 6.0.2 to 6.0.3
dependabot[bot] Dec 31, 2024
d5becc5
Merge pull request #2034 from microsoft/dependabot/nuget/coverlet.col…
baywet Dec 31, 2024
df3744d
chore(deps): bump coverlet.msbuild from 6.0.2 to 6.0.3
dependabot[bot] Dec 31, 2024
4a0ef24
Merge pull request #2035 from microsoft/dependabot/nuget/coverlet.msb…
baywet Dec 31, 2024
45329e4
fix: adds missing culture argument to date serialization
baywet Jan 2, 2025
818414d
fix: uses the json node clone API to avoid unecessary allocs
baywet Jan 2, 2025
a6a44a7
fix: date time and date time offset shifting zones
baywet Jan 2, 2025
e861c08
fix: removes all obsolete APIs
baywet Jan 2, 2025
e478b75
chore: updates public api document
baywet Jan 2, 2025
4a50c77
fix: removes useless condition for null check
baywet Jan 2, 2025
5de1bf2
Merge pull request #2037 from microsoft/fix/missing-culture
baywet Jan 3, 2025
6655ded
Merge pull request #2040 from microsoft/chore/remove-obsolete
baywet Jan 3, 2025
af55d61
Merge pull request #2039 from microsoft/fix/json-node-serialization
baywet Jan 3, 2025
ffac64e
Merge pull request #2038 from microsoft/fix/clone-api
baywet Jan 3, 2025
ec9c01b
fix: v2 references for properties do not work as expected
baywet Jan 3, 2025
8b4833c
fix: v2 request body content null propagation
baywet Jan 3, 2025
8d70195
fix: removes redundant assignment
baywet Jan 3, 2025
0ce92cc
fix: conditional version for extension causes invalid json
baywet Jan 3, 2025
4030c1f
Merge pull request #2043 from microsoft/fix/invalid-json-by-extension
baywet Jan 6, 2025
6d064c4
Merge pull request #2042 from microsoft/fix/v2-request-body-content
baywet Jan 6, 2025
f7dbe74
chore: adds unit test for properties references
baywet Jan 6, 2025
ebdbcd8
chore: switches to the other registration method
baywet Jan 6, 2025
8a73b54
fix: adds support for all component types
baywet Jan 6, 2025
45d49f1
chore: updates public api test
baywet Jan 6, 2025
799d161
chore(deps): bump Verify.Xunit from 28.7.0 to 28.8.1
dependabot[bot] Jan 6, 2025
b394a47
Merge pull request #2044 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Jan 6, 2025
aa90edf
Merge pull request #2041 from microsoft/fix/v2-properties-references
baywet Jan 7, 2025
1394da7
Merge pull request #2031 from microsoft/fix/reference-proxy-single-copy
baywet Jan 7, 2025
b69922e
Merge branch 'dev' into fix/tag-references
baywet Jan 8, 2025
66e4101
chore: removes unused method
baywet Jan 8, 2025
88daad5
fix: components schema copy
baywet Jan 8, 2025
9d07ebb
fix: enum parsing when encountering unknown values should not default…
baywet Jan 8, 2025
fd25660
chore: aligns parsing pattern
baywet Jan 8, 2025
97ce7a8
chore(deps): bump xunit from 2.9.2 to 2.9.3
dependabot[bot] Jan 8, 2025
47ad76b
fix: inconsistant API surface usage
baywet Jan 8, 2025
a201aa2
feat: adds a net8 target to benefit from all the conditional compilation
baywet Jan 8, 2025
f517deb
fix: potential NRT for net8 build
baywet Jan 8, 2025
1a1e013
fix: updates public API surface with net8 target
baywet Jan 8, 2025
15c1122
Merge pull request #2050 from microsoft/dependabot/nuget/xunit-2.9.3
baywet Jan 8, 2025
e9e214f
Merge pull request #2051 from microsoft/fix/async-surface
baywet Jan 9, 2025
2348814
Merge branch 'dev' into fix/enum-parsing
MaggieKimani1 Jan 9, 2025
23c8fdf
Merge branch 'dev' into fix/tag-references
baywet Jan 9, 2025
d4e155b
Merge pull request #2049 from microsoft/fix/enum-parsing
baywet Jan 9, 2025
d405592
make IDiagnosticExtensions internal and fix namespace
mus65 Jan 10, 2025
a398fc4
chore(deps): bump xunit.runner.visualstudio from 3.0.0 to 3.0.1
dependabot[bot] Jan 10, 2025
0347f01
Merge pull request #2054 from microsoft/dependabot/nuget/xunit.runner…
baywet Jan 10, 2025
6cf9059
Merge pull request #2053 from mus65/addrangeinternal
MaggieKimani1 Jan 13, 2025
25765f9
chore(deps): bump docker/build-push-action from 6.10.0 to 6.11.0
dependabot[bot] Jan 13, 2025
055a6e1
Merge pull request #2056 from microsoft/dependabot/github_actions/doc…
baywet Jan 13, 2025
8178037
chore(deps): bump Microsoft.Extensions.Logging, Microsoft.Extensions.…
dependabot[bot] Jan 14, 2025
3311cb8
chore(deps): bump Verify.Xunit from 28.8.1 to 28.9.0
dependabot[bot] Jan 14, 2025
105b029
chore(deps): bump System.Formats.Asn1 from 9.0.0 to 9.0.1
dependabot[bot] Jan 14, 2025
b10f79f
Merge pull request #2059 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Jan 14, 2025
22a14ea
Merge pull request #2057 from microsoft/dependabot/nuget/multi-1eea05…
baywet Jan 14, 2025
d087d24
Merge pull request #2061 from microsoft/dependabot/nuget/System.Forma…
baywet Jan 14, 2025
45a544e
Enable trimming for clients using net5 or higher
MaggieKimani1 Jan 15, 2025
a5e9058
Add a reference to readers
MaggieKimani1 Jan 15, 2025
1093d93
Use JsonSerializer context for source generation; compatible with AOT
MaggieKimani1 Jan 15, 2025
8ebab68
Annotate enumType param to preserve metadata during trimming
MaggieKimani1 Jan 15, 2025
ad1d5d7
simplify code
MaggieKimani1 Jan 15, 2025
e809945
Upgrade TFM and update API
MaggieKimani1 Jan 15, 2025
74f2c43
Add workflow to validate project for trimming
MaggieKimani1 Jan 15, 2025
5d56fac
Update .github/workflows/ci-cd.yml
baywet Jan 15, 2025
7880216
chore: migrates of FA to xunit first batch
baywet Jan 15, 2025
1a0153b
chore: FA replacement additional batch
baywet Jan 15, 2025
3ceaa12
chore: removes unused usings
baywet Jan 15, 2025
865872d
chore: FA replacement additional batch
baywet Jan 15, 2025
b15de7a
chore: FA replacement additional batch
baywet Jan 15, 2025
0cca61a
chore: additional FA replacementtttttttttt
baywet Jan 15, 2025
4ecf8a4
chore: additional batch of FA replacement
baywet Jan 15, 2025
d0bacd2
chore: additional FA replacement batch
baywet Jan 15, 2025
d841a2a
chore: additional FA replacement batch
baywet Jan 15, 2025
c3a1fab
chore: additional FA replacement
baywet Jan 15, 2025
19d7935
chore: additional FA replacement batch
baywet Jan 15, 2025
a704fad
chore: additional FA replacement batch
baywet Jan 15, 2025
06e13ff
chore(deps): bump System.Formats.Asn1 and Microsoft.Windows.Compatibi…
dependabot[bot] Jan 15, 2025
717deb0
Merge pull request #2032 from microsoft/fix/tag-references
baywet Jan 15, 2025
7a7bba1
Merge pull request #2065 from microsoft/dependabot/nuget/multi-a1e380…
baywet Jan 15, 2025
c4a446c
Ensure trimmer preserves metadata for DisplayAttribute properties
MaggieKimani1 Jan 16, 2025
e1a3795
Merge remote-tracking branch 'origin/mk/implement-AOT' into mk/implem…
MaggieKimani1 Jan 16, 2025
4357373
Merge branch 'dev' into fix/missing-document-references
baywet Jan 16, 2025
068b8e6
Merge branch 'dev' into chore/reduce-fluent-assertions-dependency
baywet Jan 16, 2025
b63d760
Merge branch 'dev' into fix/reference-copy
baywet Jan 16, 2025
0bf3dbb
Ignore warning
MaggieKimani1 Jan 16, 2025
99c0824
chore: additional FA replacement batch
baywet Jan 16, 2025
18ec0d0
chore: naming convention
baywet Jan 16, 2025
a8153e9
chore: additional FA removal batch
baywet Jan 16, 2025
faca076
chore: linting
baywet Jan 16, 2025
d7c4621
Merge pull request #2033 from microsoft/fix/missing-document-references
baywet Jan 16, 2025
0c8ccf2
Merge branch 'dev' into chore/reduce-fluent-assertions-dependency
baywet Jan 16, 2025
aae81ad
Merge branch 'dev' into fix/reference-copy
baywet Jan 16, 2025
268a398
Fix trimming errors
MaggieKimani1 Jan 16, 2025
d88c36f
Merge pull request #2064 from microsoft/chore/reduce-fluent-assertion…
baywet Jan 16, 2025
88adb9f
Merge branch 'dev' into fix/reference-copy
baywet Jan 16, 2025
7836a2c
Merge branch 'dev' into mk/implement-AOT
baywet Jan 16, 2025
3a35cb9
Add MSBuild property to identify project-specific trimmer warnings
MaggieKimani1 Jan 16, 2025
7e512ab
Resolve trimmer warnings
MaggieKimani1 Jan 16, 2025
7a82174
Revert change
MaggieKimani1 Jan 16, 2025
b4f9c3e
Merge pull request #2063 from microsoft/mk/implement-AOT
MaggieKimani1 Jan 16, 2025
962e929
Replicate copying logic for other component types
MaggieKimani1 Jan 17, 2025
dbf4d39
chore(deps): bump FluentAssertions from 7.0.0 to 7.1.0
dependabot[bot] Jan 17, 2025
7069446
Implement an interface for IOpenApiReferenceable items with a target …
MaggieKimani1 Jan 20, 2025
32f75a1
Add reusable pathItems to components
MaggieKimani1 Jan 20, 2025
733185f
Add test and update API surface
MaggieKimani1 Jan 20, 2025
c87a3c2
Merge pull request #2070 from microsoft/dependabot/nuget/FluentAssert…
baywet Jan 20, 2025
6e904d0
Merge branch 'dev' into fix/reference-copy
baywet Jan 20, 2025
613a8e0
chore(deps): bump docker/build-push-action from 6.11.0 to 6.12.0
dependabot[bot] Jan 20, 2025
e0f9763
chore(deps): bump coverlet.msbuild from 6.0.3 to 6.0.4
dependabot[bot] Jan 20, 2025
81c7474
Merge pull request #2073 from microsoft/dependabot/nuget/coverlet.msb…
baywet Jan 20, 2025
aa44c46
Merge pull request #2071 from microsoft/dependabot/github_actions/doc…
baywet Jan 20, 2025
445b628
chore(deps): bump coverlet.collector from 6.0.3 to 6.0.4
dependabot[bot] Jan 20, 2025
b522f9f
Merge pull request #2072 from microsoft/dependabot/nuget/coverlet.col…
baywet Jan 20, 2025
995528e
Merge pull request #2046 from microsoft/fix/reference-copy
baywet Jan 21, 2025
4a72387
Bump preview versions
MaggieKimani1 Jan 21, 2025
8a83c6f
Merge pull request #2074 from microsoft/chore/bump-preview-versions
MaggieKimani1 Jan 21, 2025
a3d0541
pass host document for reference resolution
MaggieKimani1 Jan 21, 2025
c39fa84
Add test
MaggieKimani1 Jan 21, 2025
9ccdd80
Merge pull request #2076 from microsoft/mk/fix-loading-error
MaggieKimani1 Jan 21, 2025
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
15 changes: 15 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@ jobs:
shell: pwsh
run: |
dotnet test Microsoft.OpenApi.sln -c Release -v n

validate-trimming:
name: Validate Project for Trimming
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

- name: Validate Trimming warnings
run: dotnet publish -c Release -r win-x64 /p:TreatWarningsAsErrors=true /warnaserror -f net8.0
working-directory: ./test/Microsoft.OpenApi.Trimming.Tests
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ jobs:
id: getversion
- name: Push to registry - Nightly
if: ${{ github.ref == 'refs/heads/dev' }}
uses: docker/build-push-action@v6.10.0
uses: docker/build-push-action@v6.12.0
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly
- name: Push to registry - Release
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/support/v1' }}
uses: docker/build-push-action@v6.10.0
uses: docker/build-push-action@v6.12.0
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.getversion.outputs.version }}
8 changes: 4 additions & 4 deletions src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Nullable>enable</Nullable>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>2.0.0-preview4</Version>
<Version>2.0.0-preview5</Version>
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
<SignAssembly>true</SignAssembly>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
Expand All @@ -29,10 +29,10 @@

<ItemGroup>
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
10 changes: 5 additions & 5 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
var walker = new OpenApiWalker(powerShellFormatter);
walker.Walk(document);
}
WriteOpenApi(options, openApiFormat, openApiVersion, document, logger);
await WriteOpenApiAsync(options, openApiFormat, openApiVersion, document, logger, cancellationToken).ConfigureAwait(false);
}
catch (TaskCanceledException)
{
Expand Down Expand Up @@ -191,7 +191,7 @@ private static OpenApiDocument ApplyFilters(HidiOptions options, ILogger logger,
return document;
}

private static void WriteOpenApi(HidiOptions options, OpenApiFormat openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument document, ILogger logger)
private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument document, ILogger logger, CancellationToken cancellationToken)
{
using (logger.BeginScope("Output"))
{
Expand All @@ -216,11 +216,11 @@ private static void WriteOpenApi(HidiOptions options, OpenApiFormat openApiForma

var stopwatch = new Stopwatch();
stopwatch.Start();
document.Serialize(writer, openApiVersion);
await document.SerializeAsync(writer, openApiVersion, cancellationToken).ConfigureAwait(false);
stopwatch.Stop();

logger.LogTrace("Finished serializing in {ElapsedMilliseconds}ms", stopwatch.ElapsedMilliseconds);
textWriter.Flush();
await textWriter.FlushAsync(cancellationToken).ConfigureAwait(false);
}
}

Expand Down Expand Up @@ -769,7 +769,7 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
// Write OpenAPI to Output folder
options.Output = new(Path.Combine(options.OutputFolder, "openapi.json"));
options.TerseOutput = true;
WriteOpenApi(options, OpenApiFormat.Json, OpenApiSpecVersion.OpenApi3_1, document, logger);
await WriteOpenApiAsync(options, OpenApiFormat.Json, OpenApiSpecVersion.OpenApi3_1, document, logger, cancellationToken).ConfigureAwait(false);

// Create OpenAIPluginManifest from ApiDependency and OpenAPI document
var manifest = new OpenAIPluginManifest(document.Info?.Title ?? "Title", document.Info?.Title ?? "Title", "https://go.microsoft.com/fwlink/?LinkID=288890", document.Info?.Contact?.Email ?? "placeholder@contoso.com", document.Info?.License?.Url.ToString() ?? "https://placeholderlicenseurl.com")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0;</TargetFrameworks>
<!-- net6.0 target is present because of the conditional build in OpenApiYamlReader.Read -->
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.0.0-preview4</Version>
<Version>2.0.0-preview5</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<SignAssembly>true</SignAssembly>
<IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','net5.0'))">true</IsTrimmable>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','net8.0'))">true</IsAotCompatible>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<NoWarn>NU5048</NoWarn>
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Reader;
using SharpYaml.Serialization;
using System.Linq;
using Microsoft.OpenApi.Models;
using System;
using System.Text;
Expand Down Expand Up @@ -86,6 +85,7 @@ public static ReadResult Read(JsonNode jsonNode, OpenApiReaderSettings settings,
/// <inheritdoc/>
public T ReadFragment<T>(MemoryStream input,
OpenApiSpecVersion version,
OpenApiDocument openApiDocument,
out OpenApiDiagnostic diagnostic,
OpenApiReaderSettings settings = null) where T : IOpenApiElement
{
Expand All @@ -105,13 +105,13 @@ public T ReadFragment<T>(MemoryStream input,
return default;
}

return ReadFragment<T>(jsonNode, version, out diagnostic, settings);
return ReadFragment<T>(jsonNode, version, openApiDocument, out diagnostic, settings);
}

/// <inheritdoc/>
public static T ReadFragment<T>(JsonNode input, OpenApiSpecVersion version, out OpenApiDiagnostic diagnostic, OpenApiReaderSettings settings = null) where T : IOpenApiElement
public static T ReadFragment<T>(JsonNode input, OpenApiSpecVersion version, OpenApiDocument openApiDocument, out OpenApiDiagnostic diagnostic, OpenApiReaderSettings settings = null) where T : IOpenApiElement
{
return _jsonReader.ReadFragment<T>(input, version, out diagnostic, settings);
return _jsonReader.ReadFragment<T>(input, version, openApiDocument, out diagnostic, settings);
}

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions src/Microsoft.OpenApi.Workbench/MainModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ internal async Task ParseDocumentAsync()

stopwatch.Reset();
stopwatch.Start();
Output = WriteContents(document);
Output = await WriteContentsAsync(document);
stopwatch.Stop();

RenderTime = $"{stopwatch.ElapsedMilliseconds} ms";
Expand Down Expand Up @@ -299,23 +299,23 @@ internal async Task ParseDocumentAsync()
/// <summary>
/// Write content from the given document based on the format and version set in this class.
/// </summary>
private string WriteContents(OpenApiDocument document)
private async Task<string> WriteContentsAsync(OpenApiDocument document)
{
var outputStream = new MemoryStream();

document.Serialize(
await document.SerializeAsync(
outputStream,
Version,
Format,
new()
(Writers.OpenApiWriterSettings)new()
{
InlineLocalReferences = InlineLocal,
InlineExternalReferences = InlineExternal
});

outputStream.Position = 0;

return new StreamReader(outputStream).ReadToEnd();
return await new StreamReader(outputStream).ReadToEndAsync();
}

private static MemoryStream CreateStream(string text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="9.0.0" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="9.0.1" />
<!-- Microsoft.Windows.Compatibility 8.0.8 depends on 8.0.0 this dependency can be removed once they update theirs -->
<PackageReference Include="System.Formats.Asn1" Version="9.0.0" />
<PackageReference Include="System.Formats.Asn1" Version="9.0.1" />
</ItemGroup>
<ItemGroup>
<Resource Include="Themes\Metro\HowToApplyTheme.txt" />
Expand Down
63 changes: 41 additions & 22 deletions src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System.Globalization;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Properties;
Expand All @@ -22,10 +24,11 @@
/// <param name="element">The Open API element.</param>
/// <param name="stream">The output stream.</param>
/// <param name="specVersion">The Open API specification version.</param>
public static void SerializeAsJson<T>(this T element, Stream stream, OpenApiSpecVersion specVersion)
/// <param name="cancellationToken">The cancellation token.</param>
public static Task SerializeAsJsonAsync<T>(this T element, Stream stream, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default)

Check warning on line 28 in src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

All 'SerializeAsJsonAsync' method overloads should be adjacent. (https://rules.sonarsource.com/csharp/RSPEC-4136)
where T : IOpenApiSerializable
{
element.Serialize(stream, specVersion, OpenApiFormat.Json);
return element.SerializeAsync(stream, specVersion, OpenApiFormat.Json, cancellationToken);
}

/// <summary>
Expand All @@ -35,10 +38,11 @@
/// <param name="element">The Open API element.</param>
/// <param name="stream">The output stream.</param>
/// <param name="specVersion">The Open API specification version.</param>
public static void SerializeAsYaml<T>(this T element, Stream stream, OpenApiSpecVersion specVersion)
/// <param name="cancellationToken">The cancellation token.</param>
public static Task SerializeAsYamlAsync<T>(this T element, Stream stream, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default)

Check warning on line 42 in src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

All 'SerializeAsYamlAsync' method overloads should be adjacent. (https://rules.sonarsource.com/csharp/RSPEC-4136)
where T : IOpenApiSerializable
{
element.Serialize(stream, specVersion, OpenApiFormat.Yaml);
return element.SerializeAsync(stream, specVersion, OpenApiFormat.Yaml, cancellationToken);
}

/// <summary>
Expand All @@ -50,14 +54,16 @@
/// <param name="stream">The given stream.</param>
/// <param name="specVersion">The Open API specification version.</param>
/// <param name="format">The output format (JSON or YAML).</param>
public static void Serialize<T>(
/// <param name="cancellationToken">The cancellation token.</param>
public static Task SerializeAsync<T>(
this T element,
Stream stream,
OpenApiSpecVersion specVersion,
OpenApiFormat format)
OpenApiFormat format,
CancellationToken cancellationToken = default)
where T : IOpenApiSerializable
{
element.Serialize(stream, specVersion, format, null);
return element.SerializeAsync(stream, specVersion, format, null, cancellationToken);
}

/// <summary>
Expand All @@ -70,12 +76,14 @@
/// <param name="specVersion">The Open API specification version.</param>
/// <param name="format">The output format (JSON or YAML).</param>
/// <param name="settings">Provide configuration settings for controlling writing output</param>
public static void Serialize<T>(
/// <param name="cancellationToken">The cancellation token.</param>
public static Task SerializeAsync<T>(
this T element,
Stream stream,
OpenApiSpecVersion specVersion,
OpenApiFormat format,
OpenApiWriterSettings settings)
OpenApiWriterSettings settings,
CancellationToken cancellationToken = default)
where T : IOpenApiSerializable
{
Utils.CheckArgumentNull(stream);
Expand All @@ -88,7 +96,7 @@
OpenApiFormat.Yaml => new OpenApiYamlWriter(streamWriter, settings),
_ => throw new OpenApiException(string.Format(SRResource.OpenApiFormatNotSupported, format)),
};
element.Serialize(writer, specVersion);
return element.SerializeAsync(writer, specVersion, cancellationToken);
}

/// <summary>
Expand All @@ -98,7 +106,8 @@
/// <param name="element">The Open API element.</param>
/// <param name="writer">The output writer.</param>
/// <param name="specVersion">Version of the specification the output should conform to</param>
public static void Serialize<T>(this T element, IOpenApiWriter writer, OpenApiSpecVersion specVersion)
/// <param name="cancellationToken">The cancellation token.</param>
public static Task SerializeAsync<T>(this T element, IOpenApiWriter writer, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default)
where T : IOpenApiSerializable
{
Utils.CheckArgumentNull(element);
Expand All @@ -122,7 +131,7 @@
throw new OpenApiException(string.Format(SRResource.OpenApiSpecVersionNotSupported, specVersion));
}

writer.Flush();
return writer.FlushAsync(cancellationToken);
}

/// <summary>
Expand All @@ -131,12 +140,14 @@
/// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
/// <param name="element">The Open API element.</param>
/// <param name="specVersion">The Open API specification version.</param>
public static string SerializeAsJson<T>(
/// <param name="cancellationToken">The cancellation token.</param>
public static Task<string> SerializeAsJsonAsync<T>(
this T element,
OpenApiSpecVersion specVersion)
OpenApiSpecVersion specVersion,
CancellationToken cancellationToken = default)
where T : IOpenApiSerializable
{
return element.Serialize(specVersion, OpenApiFormat.Json);
return element.SerializeAsync(specVersion, OpenApiFormat.Json, cancellationToken);
}

/// <summary>
Expand All @@ -145,12 +156,14 @@
/// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
/// <param name="element">The Open API element.</param>
/// <param name="specVersion">The Open API specification version.</param>
public static string SerializeAsYaml<T>(
/// <param name="cancellationToken">The cancellation token.</param>
public static Task<string> SerializeAsYamlAsync<T>(
this T element,
OpenApiSpecVersion specVersion)
OpenApiSpecVersion specVersion,
CancellationToken cancellationToken = default)
where T : IOpenApiSerializable
{
return element.Serialize(specVersion, OpenApiFormat.Yaml);
return element.SerializeAsync(specVersion, OpenApiFormat.Yaml, cancellationToken);
}

/// <summary>
Expand All @@ -160,20 +173,26 @@
/// <param name="element">The Open API element.</param>
/// <param name="specVersion">The Open API specification version.</param>
/// <param name="format">Open API document format.</param>
public static string Serialize<T>(
/// <param name="cancellationToken">The cancellation token.</param>
public static async Task<string> SerializeAsync<T>(
this T element,
OpenApiSpecVersion specVersion,
OpenApiFormat format)
OpenApiFormat format,
CancellationToken cancellationToken = default)
where T : IOpenApiSerializable
{
Utils.CheckArgumentNull(element);

using var stream = new MemoryStream();
element.Serialize(stream, specVersion, format);
await element.SerializeAsync(stream, specVersion, format, cancellationToken).ConfigureAwait(false);
stream.Position = 0;

using var streamReader = new StreamReader(stream);
return streamReader.ReadToEnd();
#if NET7_0_OR_GREATER
return await streamReader.ReadToEndAsync(cancellationToken).ConfigureAwait(false);
#else
return await streamReader.ReadToEndAsync().ConfigureAwait(false);
#endif
}
}
}
Loading
Loading