Skip to content

Commit f517deb

Browse files
committed
fix: potential NRT for net8 build
1 parent a201aa2 commit f517deb

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

src/Microsoft.OpenApi/Models/OpenApiComponents.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ private void RenderComponents(IOpenApiWriter writer, Action<IOpenApiWriter, IOpe
318318
{
319319
var loops = writer.GetSettings().LoopDetector.Loops;
320320
writer.WriteStartObject();
321-
if (loops.TryGetValue(typeof(OpenApiSchema), out List<object> schemas))
321+
if (loops.TryGetValue(typeof(OpenApiSchema), out var schemas))
322322
{
323323
writer.WriteOptionalMap(OpenApiConstants.Schemas, Schemas, callback);
324324
}

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public void SerializeAsV2(IOpenApiWriter writer)
238238
{
239239
var loops = writer.GetSettings().LoopDetector.Loops;
240240

241-
if (loops.TryGetValue(typeof(OpenApiSchema), out List<object> schemas))
241+
if (loops.TryGetValue(typeof(OpenApiSchema), out var schemas))
242242
{
243243
var openApiSchemas = schemas.Cast<OpenApiSchema>().Distinct().ToList()
244244
.ToDictionary<OpenApiSchema, string>(k => k.Reference.Id);
@@ -409,14 +409,15 @@ private static void WriteHostInfoV2(IOpenApiWriter writer, IList<OpenApiServer>?
409409
return url;
410410
})
411411
.Where(
412-
u => Uri.Compare(
412+
u => u is not null &&
413+
Uri.Compare(
413414
u,
414415
firstServerUrl,
415416
UriComponents.Host | UriComponents.Port | UriComponents.Path,
416417
UriFormat.SafeUnescaped,
417418
StringComparison.OrdinalIgnoreCase) ==
418419
0 && u.IsAbsoluteUri)
419-
.Select(u => u.Scheme)
420+
.Select(u => u!.Scheme)
420421
.Distinct()
421422
.ToList();
422423

@@ -464,10 +465,12 @@ public async Task<string> GetHashCodeAsync(CancellationToken cancellationToken =
464465
SerializeAsV3(openApiJsonWriter);
465466
await openApiJsonWriter.FlushAsync(cancellationToken).ConfigureAwait(false);
466467

468+
#if NET5_0_OR_GREATER
469+
await cryptoStream.FlushFinalBlockAsync(cancellationToken).ConfigureAwait(false);
470+
#else
467471
cryptoStream.FlushFinalBlock();
468-
var hash = sha.Hash;
469-
470-
return ConvertByteArrayToString(hash);
472+
#endif
473+
return ConvertByteArrayToString(sha.Hash ?? []);
471474
}
472475

473476
private static string ConvertByteArrayToString(byte[] hash)

src/Microsoft.OpenApi/Models/OpenApiOperation.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,11 @@ public void SerializeAsV2(IOpenApiWriter writer)
283283
{
284284
var produces = Responses
285285
.Where(static r => r.Value.Content != null)
286-
.SelectMany(static r => r.Value.Content?.Keys)
286+
.SelectMany(static r => r.Value.Content?.Keys ?? [])
287287
.Concat(
288288
Responses
289289
.Where(static r => r.Value.Reference is {HostDocument: not null})
290-
.SelectMany(static r => r.Value.Content?.Keys))
290+
.SelectMany(static r => r.Value.Content?.Keys ?? []))
291291
.Distinct(StringComparer.OrdinalIgnoreCase)
292292
.ToArray();
293293

src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs

+4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ public static async Task<ReadResult> LoadAsync(Stream input, string format = nul
129129
var result = await InternalLoadAsync(preparedStream, format, settings, cancellationToken).ConfigureAwait(false);
130130
if (!settings.LeaveStreamOpen)
131131
{
132+
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP || NET5_0_OR_GREATER
133+
await input.DisposeAsync().ConfigureAwait(false);
134+
#else
132135
input.Dispose();
136+
#endif
133137
}
134138
return result;
135139
}

0 commit comments

Comments
 (0)