Skip to content

Commit

Permalink
fix: potential NRT for net8 build
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet committed Jan 8, 2025
1 parent a201aa2 commit f517deb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Models/OpenApiComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ private void RenderComponents(IOpenApiWriter writer, Action<IOpenApiWriter, IOpe
{
var loops = writer.GetSettings().LoopDetector.Loops;
writer.WriteStartObject();
if (loops.TryGetValue(typeof(OpenApiSchema), out List<object> schemas))
if (loops.TryGetValue(typeof(OpenApiSchema), out var schemas))
{
writer.WriteOptionalMap(OpenApiConstants.Schemas, Schemas, callback);
}
Expand Down
15 changes: 9 additions & 6 deletions src/Microsoft.OpenApi/Models/OpenApiDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public void SerializeAsV2(IOpenApiWriter writer)
{
var loops = writer.GetSettings().LoopDetector.Loops;

if (loops.TryGetValue(typeof(OpenApiSchema), out List<object> schemas))
if (loops.TryGetValue(typeof(OpenApiSchema), out var schemas))
{
var openApiSchemas = schemas.Cast<OpenApiSchema>().Distinct().ToList()
.ToDictionary<OpenApiSchema, string>(k => k.Reference.Id);
Expand Down Expand Up @@ -409,14 +409,15 @@ private static void WriteHostInfoV2(IOpenApiWriter writer, IList<OpenApiServer>?
return url;
})
.Where(
u => Uri.Compare(
u => u is not null &&
Uri.Compare(
u,
firstServerUrl,
UriComponents.Host | UriComponents.Port | UriComponents.Path,
UriFormat.SafeUnescaped,
StringComparison.OrdinalIgnoreCase) ==
0 && u.IsAbsoluteUri)
.Select(u => u.Scheme)
.Select(u => u!.Scheme)
.Distinct()
.ToList();

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

#if NET5_0_OR_GREATER
await cryptoStream.FlushFinalBlockAsync(cancellationToken).ConfigureAwait(false);
#else
cryptoStream.FlushFinalBlock();
var hash = sha.Hash;

return ConvertByteArrayToString(hash);
#endif
return ConvertByteArrayToString(sha.Hash ?? []);
}

private static string ConvertByteArrayToString(byte[] hash)
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,11 @@ public void SerializeAsV2(IOpenApiWriter writer)
{
var produces = Responses
.Where(static r => r.Value.Content != null)
.SelectMany(static r => r.Value.Content?.Keys)
.SelectMany(static r => r.Value.Content?.Keys ?? [])
.Concat(
Responses
.Where(static r => r.Value.Reference is {HostDocument: not null})
.SelectMany(static r => r.Value.Content?.Keys))
.SelectMany(static r => r.Value.Content?.Keys ?? []))
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToArray();

Expand Down
4 changes: 4 additions & 0 deletions src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ public static async Task<ReadResult> LoadAsync(Stream input, string format = nul
var result = await InternalLoadAsync(preparedStream, format, settings, cancellationToken).ConfigureAwait(false);
if (!settings.LeaveStreamOpen)
{
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP || NET5_0_OR_GREATER
await input.DisposeAsync().ConfigureAwait(false);
#else
input.Dispose();
#endif
}
return result;
}
Expand Down

0 comments on commit f517deb

Please sign in to comment.