Skip to content

Commit

Permalink
Merge pull request #1585 from microsoft/vnext
Browse files Browse the repository at this point in the history
master release
  • Loading branch information
baywet authored Mar 6, 2024
2 parents 522f703 + a2185ea commit ec6a1d4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.6.13</Version>
<Version>1.6.14</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<SignAssembly>true</SignAssembly>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
Expand Down
14 changes: 4 additions & 10 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 All @@ -73,7 +67,7 @@ public async Task<ReadResult> ReadAsync(Stream input, CancellationToken cancella
bufferedStream.Position = 0;
}

using var reader = new StreamReader(bufferedStream);
using var reader = new StreamReader(bufferedStream, default, true, -1, _settings.LeaveStreamOpen);
return await new OpenApiTextReaderReader(_settings).ReadAsync(reader, cancellationToken);
}

Expand All @@ -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
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>Latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.6.13</Version>
<Version>1.6.14</Version>
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
<SignAssembly>true</SignAssembly>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,21 @@ public void StreamShouldNotCloseIfLeaveStreamOpenSettingEqualsTrue()
reader.Read(stream, out _);
Assert.True(stream.CanRead);
}

[Fact]
public async void StreamShouldNotBeDisposedIfLeaveStreamOpenSettingIsTrue()
{
var memoryStream = new MemoryStream();
using var fileStream = Resources.GetStream(Path.Combine(SampleFolderPath, "petStore.yaml"));

await fileStream.CopyToAsync(memoryStream);
memoryStream.Position = 0;
var stream = memoryStream;

var reader = new OpenApiStreamReader(new() { LeaveStreamOpen = true });
_ = await reader.ReadAsync(stream);
stream.Seek(0, SeekOrigin.Begin); // does not throw an object disposed exception
Assert.True(stream.CanRead);
}
}
}

0 comments on commit ec6a1d4

Please sign in to comment.