Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
2b3abef
Adds nullability check to HasOperations method and updates/refactors …
irvinesunday Jun 7, 2021
6bb23b6
Adds setting to configure leaving stream open (#605)
irvinesunday Jun 14, 2021
0dc267c
Add a mock OpenApiDocument
MaggieKimani1 Oct 12, 2021
0ecca08
Add tests for filtering validation
MaggieKimani1 Oct 12, 2021
2f4a1c8
Add an OpenApi filtering service for filtering an OpenApiDocument bas…
MaggieKimani1 Oct 12, 2021
8e45f8b
Add necessary packages
MaggieKimani1 Oct 12, 2021
f270b90
Simplify using statement and switch condition
MaggieKimani1 Oct 12, 2021
9cda4fb
Use static class reference
MaggieKimani1 Oct 18, 2021
af61c14
Add --filterbyOperationId command option
MaggieKimani1 Oct 18, 2021
d24442d
Add filterByOperationId param and logic
MaggieKimani1 Oct 18, 2021
501e88c
Add static modifier
MaggieKimani1 Oct 18, 2021
d5b1b5e
Clean up and add xml comments
MaggieKimani1 Oct 18, 2021
4016ba1
Add a class that visits the OpenApi operations and returns the search…
MaggieKimani1 Oct 18, 2021
73bef22
Add a search result object model
MaggieKimani1 Oct 18, 2021
a1d46e5
Copies OpenApiOperation references to the new subset document
MaggieKimani1 Oct 18, 2021
68fc2de
Merge branch 'mk/add-filter-commandOption' into mk/add-filter-by-tags
MaggieKimani1 Oct 19, 2021
b3c79eb
Copy OpenApiInfo and components from the source document to the new s…
MaggieKimani1 Oct 20, 2021
cd5f3fa
Add an info object to the mock document
MaggieKimani1 Oct 20, 2021
3c43ea1
Clean up: Remove unnecessary params
MaggieKimani1 Oct 20, 2021
74a336b
Merge branch 'mk/add-filter-commandOption' into mk/add-filter-by-tags
MaggieKimani1 Oct 21, 2021
43f48ec
Remove package reference
MaggieKimani1 Oct 21, 2021
77063ae
Add test cases for filtering OpenApiDocument by tags provided
MaggieKimani1 Oct 25, 2021
8a60acf
Add --filterByTag command option
MaggieKimani1 Oct 25, 2021
c4aed08
Add a tags parameter to the filtering service to allow for slicing of…
MaggieKimani1 Oct 25, 2021
849d841
Add a filterByTag param and logic
MaggieKimani1 Oct 25, 2021
1553a0c
Code refactoring
MaggieKimani1 Oct 26, 2021
9931ddb
Merge branch 'mk/add-filter-commandOption' into mk/add-filter-by-tags
MaggieKimani1 Oct 26, 2021
8ba33cd
Revert "Remove package reference"
MaggieKimani1 Oct 21, 2021
2397e9d
Update the Public API interface text file
MaggieKimani1 Oct 26, 2021
d13dcf4
Remove unnecessary package dependency
MaggieKimani1 Oct 26, 2021
ad0bda0
Fixed spelling of "Path" (from "Past")
peteraritchie Oct 29, 2021
00dd9c4
Allow filtering for multiple operationIds
MaggieKimani1 Nov 1, 2021
3f3dae0
Add check for writing to an already existing file
MaggieKimani1 Nov 1, 2021
b6910f7
Merge branch 'mk/add-filter-commandOption' into mk/add-filter-by-tags
MaggieKimani1 Nov 1, 2021
5a3da1a
Code cleanup
MaggieKimani1 Nov 1, 2021
9af85db
Update the public API text file
MaggieKimani1 Nov 1, 2021
f33d1f6
Add license header
MaggieKimani1 Nov 2, 2021
27ab7f7
Copy over all Info properties
MaggieKimani1 Nov 2, 2021
c3c0abc
Add license header
MaggieKimani1 Nov 2, 2021
dbd8d92
Clean up and add XML documentations for public methods
MaggieKimani1 Nov 2, 2021
a689c36
Copy over extensions object to new document
MaggieKimani1 Nov 2, 2021
8fbb809
Update ci-build.yml for Azure Pipelines
MaggieKimani1 Nov 2, 2021
deaa2fe
Move declaration closer to first reference point
MaggieKimani1 Nov 3, 2021
015b3cd
Code cleanup
MaggieKimani1 Nov 4, 2021
58b380f
Merge pull request #642 from peteraritchie/patch-1
darrelmiller Nov 5, 2021
ac94489
Merge branch 'vnext' into mk/add-filter-commandOption
darrelmiller Nov 5, 2021
d259cc1
Remove [Fact] attribute
MaggieKimani1 Nov 5, 2021
f2102cc
Merge remote-tracking branch 'origin/mk/add-filter-commandOption' int…
MaggieKimani1 Nov 5, 2021
9f46c00
Merge pull request #636 from microsoft/mk/add-filter-commandOption
MaggieKimani1 Nov 5, 2021
d4451e9
Merge remote-tracking branch 'origin/vnext' into mk/add-filter-by-tags
MaggieKimani1 Nov 5, 2021
526162e
Remove unused variable
MaggieKimani1 Nov 5, 2021
1321c1e
Rename project and update namespaces
MaggieKimani1 Nov 8, 2021
fb5512c
Update build script and solution file
MaggieKimani1 Nov 8, 2021
e01b885
Rename the OpenApi.Tool to Hidi
MaggieKimani1 Nov 9, 2021
c900208
Address PR feedback
MaggieKimani1 Nov 9, 2021
d1a13a5
Update package name
MaggieKimani1 Nov 9, 2021
02eeec1
Merge branch 'vnext' into mk/add-cmdtool-build-task
MaggieKimani1 Nov 9, 2021
6acf634
Add validation check and add test
MaggieKimani1 Nov 9, 2021
403a40f
Rename tool to OpenApi.Hidi
MaggieKimani1 Nov 9, 2021
6922d61
Merge pull request #639 from microsoft/mk/add-filter-by-tags
darrelmiller Nov 9, 2021
0e63879
Merge branch 'vnext' into mk/add-cmdtool-build-task
darrelmiller Nov 9, 2021
e9f5257
Merge pull request #644 from microsoft/mk/add-cmdtool-build-task
MaggieKimani1 Nov 9, 2021
ba84828
Merge remote-tracking branch 'origin/vnext' into mk/rename-commandlin…
MaggieKimani1 Nov 10, 2021
97f4ac3
Remove whitespace
MaggieKimani1 Nov 10, 2021
ede11f1
Update solution file with the correct directory path
MaggieKimani1 Nov 10, 2021
431a4e9
Add blank line
MaggieKimani1 Nov 12, 2021
561b07a
Update .sln
MaggieKimani1 Nov 12, 2021
7b678a8
Revert
MaggieKimani1 Nov 12, 2021
733ca6b
Update dll path in launch.json
MaggieKimani1 Nov 12, 2021
520a55e
Update ci-cd.yml and codeql.yml files
MaggieKimani1 Nov 12, 2021
39f5bea
Update the tool's version
MaggieKimani1 Nov 16, 2021
0834f1f
Merge pull request #647 from microsoft/mk/rename-commandline-tool
MaggieKimani1 Nov 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .azure-pipelines/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ steps:
inputs:
testAssemblyVer2: |
**\*.Tests.dll

vsTestVersion: 16.0
codeCoverageEnabled: true

Expand Down Expand Up @@ -94,6 +94,13 @@ steps:
configuration: Release
msbuildArguments: '/t:pack /p:PackageOutputPath=$(Build.ArtifactStagingDirectory) /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg'

- task: MSBuild@1
displayName: 'Pack OpenApi Hidi'
inputs:
solution: src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
configuration: Release
msbuildArguments: '/t:pack /p:PackageOutputPath=$(Build.ArtifactStagingDirectory) /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg'

- task: SFP.build-tasks.custom-build-task-1.EsrpCodeSigning@1
displayName: 'ESRP CodeSigning Nuget Packages'
inputs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
$projectsArray = @(
'.\src\Microsoft.OpenApi\Microsoft.OpenApi.csproj',
'.\src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj',
'.\src\Microsoft.OpenApi.Tool\Microsoft.OpenApi.Tool.csproj'
'.\src\Microsoft.OpenApi.Hidi\Microsoft.OpenApi.Hidi.csproj'
)
$gitNewVersion = if ("${{ steps.tag_generator.outputs.new_version }}") {"${{ steps.tag_generator.outputs.new_version }}"} else {$null}
$projectCurrentVersion = ([xml](Get-Content .\src\Microsoft.OpenApi\Microsoft.OpenApi.csproj)).Project.PropertyGroup.Version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
$projectsArray = @(
'.\src\Microsoft.OpenApi\Microsoft.OpenApi.csproj',
'.\src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj',
'.\src\Microsoft.OpenApi.Tool\Microsoft.OpenApi.Tool.csproj'
'.\src\Microsoft.OpenApi.Hidi\Microsoft.OpenApi.Hidi.csproj'
)

$projectsArray | ForEach-Object {
Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/Microsoft.OpenApi.Tool/bin/Debug/netcoreapp3.1/Microsoft.OpenApi.Tool.dll",
"program": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi/bin/Debug/netcoreapp3.1/Microsoft.OpenApi.Hidi.dll",
"args": [],
"cwd": "${workspaceFolder}/src/Microsoft.OpenApi.Tool",
"cwd": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.OpenApi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{6357D7FD-2
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.SmokeTests", "test\Microsoft.OpenApi.SmokeTests\Microsoft.OpenApi.SmokeTests.csproj", "{AD79B61D-88CF-497C-9ED5-41AE3867C5AC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.Tool", "src\Microsoft.OpenApi.Tool\Microsoft.OpenApi.Tool.csproj", "{254841B5-7DAC-4D1D-A9C5-44FE5CE467BE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.Hidi", "src\Microsoft.OpenApi.Hidi\Microsoft.OpenApi.Hidi.csproj", "{254841B5-7DAC-4D1D-A9C5-44FE5CE467BE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
10 changes: 5 additions & 5 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
@echo off
Echo Building Microsoft.OpenApi
Echo Building Microsoft.OpenApi

SET PROJ=%~dp0src\Microsoft.OpenApi\Microsoft.OpenApi.csproj
SET PROJ=%~dp0src\Microsoft.OpenApi\Microsoft.OpenApi.csproj
dotnet msbuild %PROJ% /t:restore /p:Configuration=Release
dotnet msbuild %PROJ% /t:build /p:Configuration=Release
dotnet msbuild %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts

Echo Building Microsoft.OpenApi.Readers

SET PROJ=%~dp0src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj
SET PROJ=%~dp0src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj
dotnet msbuild %PROJ% /t:restore /p:Configuration=Release
dotnet msbuild %PROJ% /t:build /p:Configuration=Release
dotnet msbuild %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts

Echo Building Microsoft.OpenApi.Tool
Echo Building Microsoft.OpenApi.Hidi

SET PROJ=%~dp0src\Microsoft.OpenApi.Tool\Microsoft.OpenApi.Tool.csproj
SET PROJ=%~dp0src\Microsoft.OpenApi.Hidi\Microsoft.OpenApi.Hidi.csproj
dotnet msbuild %PROJ% /t:restore /p:Configuration=Release
dotnet msbuild %PROJ% /t:build /p:Configuration=Release
dotnet msbuild %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts
Expand Down
8 changes: 4 additions & 4 deletions install-tool.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$latest = Get-ChildItem .\artifacts\ Microsoft.OpenApi.Tool* | select-object -Last 1
$latest = Get-ChildItem .\artifacts\Microsoft.OpenApi.Hidi* | select-object -Last 1
$version = $latest.Name.Split(".")[3..5] | join-string -Separator "."

if (Test-Path -Path ./artifacts/openapi-parser.exe) {
dotnet tool uninstall --tool-path artifacts Microsoft.OpenApi.Tool
if (Test-Path -Path ./artifacts/hidi.exe) {
dotnet tool uninstall --tool-path artifacts Microsoft.OpenApi.Hidi
}
dotnet tool install --tool-path artifacts --add-source .\artifacts\ --version $version Microsoft.OpenApi.Tool
dotnet tool install --tool-path artifacts --add-source .\artifacts\ --version $version Microsoft.OpenApi.Hidi
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackAsTool>true</PackAsTool>
<ToolCommandName>openapi-parser</ToolCommandName>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>1.3.0-preview</Version>
<Version>0.5.0-preview</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.IO;
using System.Linq;
using System.Net;
Expand All @@ -12,7 +14,7 @@
using Microsoft.OpenApi.Validations;
using Microsoft.OpenApi.Writers;

namespace Microsoft.OpenApi.Tool
namespace Microsoft.OpenApi.Hidi
{
static class OpenApiService
{
Expand All @@ -21,29 +23,55 @@ public static void ProcessOpenApiDocument(
FileInfo output,
OpenApiSpecVersion version,
OpenApiFormat format,
string filterByOperationIds,
string filterByTags,
bool inline,
bool resolveExternal)
{
if (input == null)
if (string.IsNullOrEmpty(input))
{
throw new ArgumentNullException("input");
throw new ArgumentNullException(nameof(input));
}
if(output == null)
{
throw new ArgumentException(nameof(output));
}
if (output.Exists)
{
throw new IOException("The file you're writing to already exists. Please input a new output path.");
}

var stream = GetStream(input);

OpenApiDocument document;

var result = new OpenApiStreamReader(new OpenApiReaderSettings
{
ReferenceResolution = resolveExternal == true ? ReferenceResolutionSetting.ResolveAllReferences : ReferenceResolutionSetting.ResolveLocalReferences,
ReferenceResolution = resolveExternal ? ReferenceResolutionSetting.ResolveAllReferences : ReferenceResolutionSetting.ResolveLocalReferences,
RuleSet = ValidationRuleSet.GetDefaultRuleSet()
}
).ReadAsync(stream).GetAwaiter().GetResult();

OpenApiDocument document;
document = result.OpenApiDocument;

// Check if filter options are provided, then execute
if (!string.IsNullOrEmpty(filterByOperationIds) && !string.IsNullOrEmpty(filterByTags))
{
throw new InvalidOperationException("Cannot filter by operationIds and tags at the same time.");
}

if (!string.IsNullOrEmpty(filterByOperationIds))
{
var predicate = OpenApiFilterService.CreatePredicate(operationIds: filterByOperationIds);
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
}
if (!string.IsNullOrEmpty(filterByTags))
{
var predicate = OpenApiFilterService.CreatePredicate(tags: filterByTags);
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
}

var context = result.OpenApiDiagnostic;

if (context.Errors.Count != 0)
if (context.Errors.Count > 0)
{
var errorReport = new StringBuilder();

Expand All @@ -52,43 +80,26 @@ public static void ProcessOpenApiDocument(
errorReport.AppendLine(error.ToString());
}

throw new ArgumentException(String.Join(Environment.NewLine, context.Errors.Select(e => e.Message).ToArray()));
throw new ArgumentException(string.Join(Environment.NewLine, context.Errors.Select(e => e.Message).ToArray()));
}

using (var outputStream = output?.Create())
{
TextWriter textWriter;
using var outputStream = output?.Create();

if (outputStream != null)
{
textWriter = new StreamWriter(outputStream);
}
else
{
textWriter = Console.Out;
}
var textWriter = outputStream != null ? new StreamWriter(outputStream) : Console.Out;

var settings = new OpenApiWriterSettings()
{
ReferenceInline = inline == true ? ReferenceInlineSetting.InlineLocalReferences : ReferenceInlineSetting.DoNotInlineReferences
};
IOpenApiWriter writer;
switch (format)
{
case OpenApiFormat.Json:
writer = new OpenApiJsonWriter(textWriter, settings);
break;
case OpenApiFormat.Yaml:
writer = new OpenApiYamlWriter(textWriter, settings);
break;
default:
throw new ArgumentException("Unknown format");
}

document.Serialize(writer, version);
var settings = new OpenApiWriterSettings()
{
ReferenceInline = inline ? ReferenceInlineSetting.InlineLocalReferences : ReferenceInlineSetting.DoNotInlineReferences
};
IOpenApiWriter writer = format switch
{
OpenApiFormat.Json => new OpenApiJsonWriter(textWriter, settings),
OpenApiFormat.Yaml => new OpenApiYamlWriter(textWriter, settings),
_ => throw new ArgumentException("Unknown format"),
};
document.Serialize(writer, version);

textWriter.Flush();
}
textWriter.Flush();
}

private static Stream GetStream(string input)
Expand Down Expand Up @@ -127,7 +138,6 @@ internal static void ValidateOpenApiDocument(string input)

document = new OpenApiStreamReader(new OpenApiReaderSettings
{
//ReferenceResolution = resolveExternal == true ? ReferenceResolutionSetting.ResolveAllReferences : ReferenceResolutionSetting.ResolveLocalReferences,
RuleSet = ValidationRuleSet.GetDefaultRuleSet()
}
).Read(stream, out var context);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,15 @@
using System;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.Threading.Tasks;
using Microsoft.OpenApi;

namespace Microsoft.OpenApi.Tool
namespace Microsoft.OpenApi.Hidi
{
class Program
static class Program
{
static async Task<int> OldMain(string[] args)
{

var command = new RootCommand
{
new Option("--input", "Input OpenAPI description file path or URL", typeof(string) ),
new Option("--output","Output OpenAPI description file", typeof(FileInfo), arity: ArgumentArity.ZeroOrOne),
new Option("--version", "OpenAPI specification version", typeof(OpenApiSpecVersion)),
new Option("--format", "File format",typeof(OpenApiFormat) ),
new Option("--inline", "Inline $ref instances", typeof(bool) ),
new Option("--resolveExternal","Resolve external $refs", typeof(bool))
};

command.Handler = CommandHandler.Create<string,FileInfo,OpenApiSpecVersion,OpenApiFormat,bool, bool>(
OpenApiService.ProcessOpenApiDocument);

// Parse the incoming args and invoke the handler
return await command.InvokeAsync(args);
}

static async Task<int> Main(string[] args)
{
var rootCommand = new RootCommand() {
Expand All @@ -47,9 +28,11 @@ static async Task<int> Main(string[] args)
new Option("--version", "OpenAPI specification version", typeof(OpenApiSpecVersion)),
new Option("--format", "File format",typeof(OpenApiFormat) ),
new Option("--inline", "Inline $ref instances", typeof(bool) ),
new Option("--resolveExternal","Resolve external $refs", typeof(bool))
new Option("--resolveExternal","Resolve external $refs", typeof(bool)),
new Option("--filterByOperationIds", "Filters OpenApiDocument by OperationId(s) provided", typeof(string)),
new Option("--filterByTags", "Filters OpenApiDocument by Tag(s) provided", typeof(string))
};
transformCommand.Handler = CommandHandler.Create<string, FileInfo, OpenApiSpecVersion, OpenApiFormat, bool, bool>(
transformCommand.Handler = CommandHandler.Create<string, FileInfo, OpenApiSpecVersion, OpenApiFormat, string, string, bool, bool>(
OpenApiService.ProcessOpenApiDocument);

rootCommand.Add(transformCommand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Services;

namespace Microsoft.OpenApi.Tool
namespace Microsoft.OpenApi.Hidi
{
internal class StatsVisitor : OpenApiVisitorBase
{
Expand Down
10 changes: 8 additions & 2 deletions src/Microsoft.OpenApi.Readers/OpenApiReaderSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// Licensed under the MIT license.

using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Interfaces;
Expand Down Expand Up @@ -61,11 +61,17 @@ public class OpenApiReaderSettings
public Uri BaseUrl { get; set; }

/// <summary>
/// Function used to provide an alternative loader for accessing external references.
/// Function used to provide an alternative loader for accessing external references.
/// </summary>
/// <remarks>
/// Default loader will attempt to dereference http(s) urls and file urls.
/// </remarks>
public IStreamLoader CustomExternalLoader { get; set; }

/// <summary>
/// Whether to leave the <see cref="Stream"/> object open after reading
/// from an <see cref="OpenApiStreamReader"/> object.
/// </summary>
public bool LeaveStreamOpen { get; set; }
}
}
18 changes: 11 additions & 7 deletions src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// Licensed under the MIT license.

using System.IO;
using System.Threading.Tasks;
Expand Down Expand Up @@ -29,14 +29,18 @@ public OpenApiStreamReader(OpenApiReaderSettings settings = null)
/// Reads the stream input and parses it into an Open API document.
/// </summary>
/// <param name="input">Stream containing OpenAPI description to parse.</param>
/// <param name="diagnostic">Returns diagnostic object containing errors detected during parsing</param>
/// <returns>Instance of newly created OpenApiDocument</returns>
/// <param name="diagnostic">Returns diagnostic object containing errors detected during parsing.</param>
/// <returns>Instance of newly created OpenApiDocument.</returns>
public OpenApiDocument Read(Stream input, out OpenApiDiagnostic diagnostic)
{
using (var reader = new StreamReader(input))
var reader = new StreamReader(input);
var result = new OpenApiTextReaderReader(_settings).Read(reader, out diagnostic);
if (!_settings.LeaveStreamOpen)
{
return new OpenApiTextReaderReader(_settings).Read(reader, out diagnostic);
reader.Dispose();
}

return result;
}

/// <summary>
Expand All @@ -50,8 +54,8 @@ public async Task<ReadResult> ReadAsync(Stream input)
if (input is MemoryStream)
{
bufferedStream = (MemoryStream)input;
}
else
}
else
{
// Buffer stream so that OpenApiTextReaderReader can process it synchronously
// YamlDocument doesn't support async reading.
Expand Down
Loading