diff --git a/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs b/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs index ae01833fb..c9431de98 100644 --- a/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs +++ b/src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs @@ -41,14 +41,8 @@ public OpenApiStreamReader(OpenApiReaderSettings settings = null) /// Instance of newly created OpenApiDocument. 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); } /// @@ -86,7 +80,7 @@ public async Task ReadAsync(Stream input, CancellationToken cancella /// Instance of newly created OpenApiDocument public T ReadFragment(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(reader, version, out diagnostic); } }