Skip to content

Commit

Permalink
Merge pull request #1582 from microsoft/mk/fix-stream-leave-open
Browse files Browse the repository at this point in the history
Update the OpenApiStreamReader's Read and ReadFragment method to be consistent with ReadAsync
  • Loading branch information
MaggieKimani1 authored Mar 6, 2024
2 parents 2f64478 + d763e53 commit f749231
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,8 @@ public OpenApiStreamReader(OpenApiReaderSettings settings = null)
/// <returns>Instance of newly created OpenApiDocument.</returns>
public OpenApiDocument Read(Stream input, out OpenApiDiagnostic diagnostic)
{
var reader = new StreamReader(input);
var result = new OpenApiTextReaderReader(_settings).Read(reader, out diagnostic);
if (!_settings.LeaveStreamOpen)
{
reader.Dispose();
}

return result;
using var reader = new StreamReader(input, default, true, -1, _settings.LeaveStreamOpen);
return new OpenApiTextReaderReader(_settings).Read(reader, out diagnostic);
}

/// <summary>
Expand Down Expand Up @@ -86,7 +80,7 @@ public async Task<ReadResult> ReadAsync(Stream input, CancellationToken cancella
/// <returns>Instance of newly created OpenApiDocument</returns>
public T ReadFragment<T>(Stream input, OpenApiSpecVersion version, out OpenApiDiagnostic diagnostic) where T : IOpenApiReferenceable
{
using var reader = new StreamReader(input);
using var reader = new StreamReader(input, default, true, -1, _settings.LeaveStreamOpen);
return new OpenApiTextReaderReader(_settings).ReadFragment<T>(reader, version, out diagnostic);
}
}
Expand Down

0 comments on commit f749231

Please sign in to comment.