Skip to content

Conversation

@irvinesunday
Copy link
Contributor

Fixes #530
Closes https://github.com/microsoftgraph/microsoft-graph-devx-api/issues/583

This PR:

  • Adds a new boolean setting in OpenApiReaderSettings.cs: LeaveStreamOpen to flag whether or not to leave the stream object open after reading from an OpenApiStreamReader object.
    Creating a StreamReader object within a using statement closes the stream when the Dispose() method of the StreamReader is called.
  • Creates OpenApiStreamReader tests to validate setting the LeaveStreamOpen setting to either true or false.

@irvinesunday irvinesunday self-assigned this Jun 7, 2021
public OpenApiDocument Read(Stream input, out OpenApiDiagnostic diagnostic)
{
using (var reader = new StreamReader(input))
if (_settings.LeaveStreamOpen)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var reader = new StreamReader(input);
var result = new OpenApiTextReaderReader(_settings).Read(reader, out diagnostic);
if (!_settings.LeaveStreamOpen)
   reader.Dispose();
return result;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Much cleaner!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like brackets after if statements though, even for one-liners 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't fight coding preferences. It seems that I'm the only one on the team to like one liners with no brackets 😅

irvinesunday and others added 3 commits June 7, 2021 15:42
- Remove default assignment of false boolean to setting
- Code simplification
…ble' into is/OpenApiStreamReader-configurable
@irvinesunday irvinesunday merged commit 6bb23b6 into vnext Jun 14, 2021
@irvinesunday irvinesunday deleted the is/OpenApiStreamReader-configurable branch June 14, 2021 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenApiStreamReader disposes input stream after reading and it's not configurable

4 participants