Skip to content

Commit

Permalink
Merge pull request #1006 from microsoft/ma/readasync-filter-errors
Browse files Browse the repository at this point in the history
Separate warnings and errors in Open API YAML reader ReadAsync method
  • Loading branch information
millicentachieng authored Sep 9, 2022
2 parents 6ff3176 + 6cdceb0 commit 0b710d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi.Readers</Title>
<PackageId>Microsoft.OpenApi.Readers</PackageId>
<Version>1.4.0</Version>
<Version>1.4.1</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
12 changes: 8 additions & 4 deletions src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public OpenApiDocument Read(YamlDocument input, out OpenApiDiagnostic diagnostic
if (_settings.RuleSet != null && _settings.RuleSet.Rules.Count > 0)
{
var openApiErrors = document.Validate(_settings.RuleSet);
foreach (var item in openApiErrors.Where(e => e is OpenApiValidatorError))
foreach (var item in openApiErrors.OfType<OpenApiValidatorError>())
{
diagnostic.Errors.Add(item);
}
foreach (var item in openApiErrors.Where(e => e is OpenApiValidatorWarning))
foreach (var item in openApiErrors.OfType<OpenApiValidatorWarning>())
{
diagnostic.Warnings.Add(item);
}
Expand Down Expand Up @@ -114,11 +114,15 @@ public async Task<ReadResult> ReadAsync(YamlDocument input)
// Validate the document
if (_settings.RuleSet != null && _settings.RuleSet.Rules.Count > 0)
{
var errors = document.Validate(_settings.RuleSet);
foreach (var item in errors)
var openApiErrors = document.Validate(_settings.RuleSet);
foreach (var item in openApiErrors.OfType<OpenApiValidatorError>())
{
diagnostic.Errors.Add(item);
}
foreach (var item in openApiErrors.OfType<OpenApiValidatorWarning>())
{
diagnostic.Warnings.Add(item);
}
}

return new ReadResult()
Expand Down

0 comments on commit 0b710d5

Please sign in to comment.