Skip to content

Commit 8943e2a

Browse files
authored
Merge pull request #2077 from microsoft/dev
Release v2.0.0-preview5
2 parents cce2495 + 9ccdd80 commit 8943e2a

File tree

251 files changed

+2550
-2293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

251 files changed

+2550
-2293
lines changed

.github/workflows/ci-cd.yml

+15
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,18 @@ jobs:
3636
shell: pwsh
3737
run: |
3838
dotnet test Microsoft.OpenApi.sln -c Release -v n
39+
40+
validate-trimming:
41+
name: Validate Project for Trimming
42+
runs-on: windows-latest
43+
steps:
44+
- uses: actions/checkout@v4
45+
46+
- name: Setup .NET
47+
uses: actions/setup-dotnet@v4
48+
with:
49+
dotnet-version: 8.x
50+
51+
- name: Validate Trimming warnings
52+
run: dotnet publish -c Release -r win-x64 /p:TreatWarningsAsErrors=true /warnaserror -f net8.0
53+
working-directory: ./test/Microsoft.OpenApi.Trimming.Tests

.github/workflows/docker.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ jobs:
3030
id: getversion
3131
- name: Push to registry - Nightly
3232
if: ${{ github.ref == 'refs/heads/dev' }}
33-
uses: docker/build-push-action@v6.10.0
33+
uses: docker/build-push-action@v6.12.0
3434
with:
3535
push: true
3636
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly
3737
- name: Push to registry - Release
3838
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/support/v1' }}
39-
uses: docker/build-push-action@v6.10.0
39+
uses: docker/build-push-action@v6.12.0
4040
with:
4141
push: true
4242
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.getversion.outputs.version }}

src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Nullable>enable</Nullable>
1010
<ToolCommandName>hidi</ToolCommandName>
1111
<PackageOutputPath>./../../artifacts</PackageOutputPath>
12-
<Version>2.0.0-preview4</Version>
12+
<Version>2.0.0-preview5</Version>
1313
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
1414
<SignAssembly>true</SignAssembly>
1515
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
@@ -29,10 +29,10 @@
2929

3030
<ItemGroup>
3131
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
32-
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
33-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
32+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.1" />
33+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1" />
3434
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
35-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
35+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.1" />
3636
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
3737
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3838
<PrivateAssets>all</PrivateAssets>

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
113113
var walker = new OpenApiWalker(powerShellFormatter);
114114
walker.Walk(document);
115115
}
116-
WriteOpenApi(options, openApiFormat, openApiVersion, document, logger);
116+
await WriteOpenApiAsync(options, openApiFormat, openApiVersion, document, logger, cancellationToken).ConfigureAwait(false);
117117
}
118118
catch (TaskCanceledException)
119119
{
@@ -191,7 +191,7 @@ private static OpenApiDocument ApplyFilters(HidiOptions options, ILogger logger,
191191
return document;
192192
}
193193

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

217217
var stopwatch = new Stopwatch();
218218
stopwatch.Start();
219-
document.Serialize(writer, openApiVersion);
219+
await document.SerializeAsync(writer, openApiVersion, cancellationToken).ConfigureAwait(false);
220220
stopwatch.Stop();
221221

222222
logger.LogTrace("Finished serializing in {ElapsedMilliseconds}ms", stopwatch.ElapsedMilliseconds);
223-
textWriter.Flush();
223+
await textWriter.FlushAsync(cancellationToken).ConfigureAwait(false);
224224
}
225225
}
226226

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

774774
// Create OpenAIPluginManifest from ApiDependency and OpenAPI document
775775
var manifest = new OpenAIPluginManifest(document.Info?.Title ?? "Title", document.Info?.Title ?? "Title", "https://go.microsoft.com/fwlink/?LinkID=288890", document.Info?.Contact?.Email ?? "[email protected]", document.Info?.License?.Url.ToString() ?? "https://placeholderlicenseurl.com")

src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netstandard2.0;net6.0;</TargetFrameworks>
3+
<TargetFrameworks>netstandard2.0;net8.0;</TargetFrameworks>
44
<!-- net6.0 target is present because of the conditional build in OpenApiYamlReader.Read -->
55
<LangVersion>latest</LangVersion>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
7-
<Version>2.0.0-preview4</Version>
7+
<Version>2.0.0-preview5</Version>
88
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
99
<SignAssembly>true</SignAssembly>
10+
<IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','net5.0'))">true</IsTrimmable>
11+
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','net8.0'))">true</IsAotCompatible>
1012
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
1113
<EmbedUntrackedSources>true</EmbedUntrackedSources>
1214
<NoWarn>NU5048</NoWarn>

src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Microsoft.OpenApi.Interfaces;
1010
using Microsoft.OpenApi.Reader;
1111
using SharpYaml.Serialization;
12-
using System.Linq;
1312
using Microsoft.OpenApi.Models;
1413
using System;
1514
using System.Text;
@@ -86,6 +85,7 @@ public static ReadResult Read(JsonNode jsonNode, OpenApiReaderSettings settings,
8685
/// <inheritdoc/>
8786
public T ReadFragment<T>(MemoryStream input,
8887
OpenApiSpecVersion version,
88+
OpenApiDocument openApiDocument,
8989
out OpenApiDiagnostic diagnostic,
9090
OpenApiReaderSettings settings = null) where T : IOpenApiElement
9191
{
@@ -105,13 +105,13 @@ public T ReadFragment<T>(MemoryStream input,
105105
return default;
106106
}
107107

108-
return ReadFragment<T>(jsonNode, version, out diagnostic, settings);
108+
return ReadFragment<T>(jsonNode, version, openApiDocument, out diagnostic, settings);
109109
}
110110

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

117117
/// <summary>

src/Microsoft.OpenApi.Workbench/MainModel.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ internal async Task ParseDocumentAsync()
270270

271271
stopwatch.Reset();
272272
stopwatch.Start();
273-
Output = WriteContents(document);
273+
Output = await WriteContentsAsync(document);
274274
stopwatch.Stop();
275275

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

306-
document.Serialize(
306+
await document.SerializeAsync(
307307
outputStream,
308308
Version,
309309
Format,
310-
new()
310+
(Writers.OpenApiWriterSettings)new()
311311
{
312312
InlineLocalReferences = InlineLocal,
313313
InlineExternalReferences = InlineExternal
314314
});
315315

316316
outputStream.Position = 0;
317317

318-
return new StreamReader(outputStream).ReadToEnd();
318+
return await new StreamReader(outputStream).ReadToEndAsync();
319319
}
320320

321321
private static MemoryStream CreateStream(string text)

src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1414
<PrivateAssets>all</PrivateAssets>
1515
</PackageReference>
16-
<PackageReference Include="Microsoft.Windows.Compatibility" Version="9.0.0" />
16+
<PackageReference Include="Microsoft.Windows.Compatibility" Version="9.0.1" />
1717
<!-- Microsoft.Windows.Compatibility 8.0.8 depends on 8.0.0 this dependency can be removed once they update theirs -->
18-
<PackageReference Include="System.Formats.Asn1" Version="9.0.0" />
18+
<PackageReference Include="System.Formats.Asn1" Version="9.0.1" />
1919
</ItemGroup>
2020
<ItemGroup>
2121
<Resource Include="Themes\Metro\HowToApplyTheme.txt" />

src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs

+41-22
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
using System.Globalization;
55
using System.IO;
6+
using System.Threading;
7+
using System.Threading.Tasks;
68
using Microsoft.OpenApi.Exceptions;
79
using Microsoft.OpenApi.Interfaces;
810
using Microsoft.OpenApi.Properties;
@@ -22,10 +24,11 @@ public static class OpenApiSerializableExtensions
2224
/// <param name="element">The Open API element.</param>
2325
/// <param name="stream">The output stream.</param>
2426
/// <param name="specVersion">The Open API specification version.</param>
25-
public static void SerializeAsJson<T>(this T element, Stream stream, OpenApiSpecVersion specVersion)
27+
/// <param name="cancellationToken">The cancellation token.</param>
28+
public static Task SerializeAsJsonAsync<T>(this T element, Stream stream, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default)
2629
where T : IOpenApiSerializable
2730
{
28-
element.Serialize(stream, specVersion, OpenApiFormat.Json);
31+
return element.SerializeAsync(stream, specVersion, OpenApiFormat.Json, cancellationToken);
2932
}
3033

3134
/// <summary>
@@ -35,10 +38,11 @@ public static void SerializeAsJson<T>(this T element, Stream stream, OpenApiSpec
3538
/// <param name="element">The Open API element.</param>
3639
/// <param name="stream">The output stream.</param>
3740
/// <param name="specVersion">The Open API specification version.</param>
38-
public static void SerializeAsYaml<T>(this T element, Stream stream, OpenApiSpecVersion specVersion)
41+
/// <param name="cancellationToken">The cancellation token.</param>
42+
public static Task SerializeAsYamlAsync<T>(this T element, Stream stream, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default)
3943
where T : IOpenApiSerializable
4044
{
41-
element.Serialize(stream, specVersion, OpenApiFormat.Yaml);
45+
return element.SerializeAsync(stream, specVersion, OpenApiFormat.Yaml, cancellationToken);
4246
}
4347

4448
/// <summary>
@@ -50,14 +54,16 @@ public static void SerializeAsYaml<T>(this T element, Stream stream, OpenApiSpec
5054
/// <param name="stream">The given stream.</param>
5155
/// <param name="specVersion">The Open API specification version.</param>
5256
/// <param name="format">The output format (JSON or YAML).</param>
53-
public static void Serialize<T>(
57+
/// <param name="cancellationToken">The cancellation token.</param>
58+
public static Task SerializeAsync<T>(
5459
this T element,
5560
Stream stream,
5661
OpenApiSpecVersion specVersion,
57-
OpenApiFormat format)
62+
OpenApiFormat format,
63+
CancellationToken cancellationToken = default)
5864
where T : IOpenApiSerializable
5965
{
60-
element.Serialize(stream, specVersion, format, null);
66+
return element.SerializeAsync(stream, specVersion, format, null, cancellationToken);
6167
}
6268

6369
/// <summary>
@@ -70,12 +76,14 @@ public static void Serialize<T>(
7076
/// <param name="specVersion">The Open API specification version.</param>
7177
/// <param name="format">The output format (JSON or YAML).</param>
7278
/// <param name="settings">Provide configuration settings for controlling writing output</param>
73-
public static void Serialize<T>(
79+
/// <param name="cancellationToken">The cancellation token.</param>
80+
public static Task SerializeAsync<T>(
7481
this T element,
7582
Stream stream,
7683
OpenApiSpecVersion specVersion,
7784
OpenApiFormat format,
78-
OpenApiWriterSettings settings)
85+
OpenApiWriterSettings settings,
86+
CancellationToken cancellationToken = default)
7987
where T : IOpenApiSerializable
8088
{
8189
Utils.CheckArgumentNull(stream);
@@ -88,7 +96,7 @@ public static void Serialize<T>(
8896
OpenApiFormat.Yaml => new OpenApiYamlWriter(streamWriter, settings),
8997
_ => throw new OpenApiException(string.Format(SRResource.OpenApiFormatNotSupported, format)),
9098
};
91-
element.Serialize(writer, specVersion);
99+
return element.SerializeAsync(writer, specVersion, cancellationToken);
92100
}
93101

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

125-
writer.Flush();
134+
return writer.FlushAsync(cancellationToken);
126135
}
127136

128137
/// <summary>
@@ -131,12 +140,14 @@ public static void Serialize<T>(this T element, IOpenApiWriter writer, OpenApiSp
131140
/// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
132141
/// <param name="element">The Open API element.</param>
133142
/// <param name="specVersion">The Open API specification version.</param>
134-
public static string SerializeAsJson<T>(
143+
/// <param name="cancellationToken">The cancellation token.</param>
144+
public static Task<string> SerializeAsJsonAsync<T>(
135145
this T element,
136-
OpenApiSpecVersion specVersion)
146+
OpenApiSpecVersion specVersion,
147+
CancellationToken cancellationToken = default)
137148
where T : IOpenApiSerializable
138149
{
139-
return element.Serialize(specVersion, OpenApiFormat.Json);
150+
return element.SerializeAsync(specVersion, OpenApiFormat.Json, cancellationToken);
140151
}
141152

142153
/// <summary>
@@ -145,12 +156,14 @@ public static string SerializeAsJson<T>(
145156
/// <typeparam name="T">the <see cref="IOpenApiSerializable"/></typeparam>
146157
/// <param name="element">The Open API element.</param>
147158
/// <param name="specVersion">The Open API specification version.</param>
148-
public static string SerializeAsYaml<T>(
159+
/// <param name="cancellationToken">The cancellation token.</param>
160+
public static Task<string> SerializeAsYamlAsync<T>(
149161
this T element,
150-
OpenApiSpecVersion specVersion)
162+
OpenApiSpecVersion specVersion,
163+
CancellationToken cancellationToken = default)
151164
where T : IOpenApiSerializable
152165
{
153-
return element.Serialize(specVersion, OpenApiFormat.Yaml);
166+
return element.SerializeAsync(specVersion, OpenApiFormat.Yaml, cancellationToken);
154167
}
155168

156169
/// <summary>
@@ -160,20 +173,26 @@ public static string SerializeAsYaml<T>(
160173
/// <param name="element">The Open API element.</param>
161174
/// <param name="specVersion">The Open API specification version.</param>
162175
/// <param name="format">Open API document format.</param>
163-
public static string Serialize<T>(
176+
/// <param name="cancellationToken">The cancellation token.</param>
177+
public static async Task<string> SerializeAsync<T>(
164178
this T element,
165179
OpenApiSpecVersion specVersion,
166-
OpenApiFormat format)
180+
OpenApiFormat format,
181+
CancellationToken cancellationToken = default)
167182
where T : IOpenApiSerializable
168183
{
169184
Utils.CheckArgumentNull(element);
170185

171186
using var stream = new MemoryStream();
172-
element.Serialize(stream, specVersion, format);
187+
await element.SerializeAsync(stream, specVersion, format, cancellationToken).ConfigureAwait(false);
173188
stream.Position = 0;
174189

175190
using var streamReader = new StreamReader(stream);
176-
return streamReader.ReadToEnd();
191+
#if NET7_0_OR_GREATER
192+
return await streamReader.ReadToEndAsync(cancellationToken).ConfigureAwait(false);
193+
#else
194+
return await streamReader.ReadToEndAsync().ConfigureAwait(false);
195+
#endif
177196
}
178197
}
179198
}

0 commit comments

Comments
 (0)