Skip to content

Conversation

@MaggieKimani1
Copy link
Contributor

@MaggieKimani1 MaggieKimani1 commented Feb 7, 2024

This PR is an implementation of the loading design proposed as part of this conversation: #1446 (comment) which seeks to resolve the issue highlighted in #1434

It involves:

  • Creating a static factory for loading/parsing any OpenAPI model object that implements the Load/LoadAsync/Parse pattern as per this implementation https://learn.microsoft.com/en-us/dotnet/api/system.xml.linq.xdocument.load?view=net-7.0
  • Introducing static Load/LoadAsync/Parse methods in the OpenAPI document class to eliminate the discovery issue
  • Adding a registry class that allows users to register different OpenAPI format providers and their implementations
  • Moves the loading code into the core library so that people who only want to load JSON don't need a dependency on the third party YAML library
  • Short-circuits parsing of JSON documents by avoiding the YAML parser.

Fixes #1434
Fixes #1447

Comment on lines 42 to 60
foreach (var item in referenceCollector.References)
{
// If not already in workspace, load it and process references
if (!_workspace.Contains(item.ExternalResource))
{
var input = await _loader.LoadAsync(new(item.ExternalResource, UriKind.RelativeOrAbsolute));
var result = await reader.ReadAsync(input, _readerSettings, cancellationToken);
// Merge diagnostics
if (result.OpenApiDiagnostic != null)
{
diagnostic.AppendDiagnostic(result.OpenApiDiagnostic, item.ExternalResource);
}
if (result.OpenApiDocument != null)
{
var loadDiagnostic = await LoadAsync(item, result.OpenApiDocument, format, diagnostic, cancellationToken);
diagnostic = loadDiagnostic;
}
}
}

Check notice

Code scanning / CodeQL

Missed opportunity to use Where

This foreach loop [implicitly filters its target sequence](1) - consider filtering the sequence explicitly using '.Where(...)'.
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
70.3% Coverage on New Code (required ≥ 80%)
13.8% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

idea Catch issues before they fail your Quality Gate with our IDE extension SonarLint SonarLint

Copy link
Member

@darrelmiller darrelmiller left a comment

Choose a reason for hiding this comment

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

I think this PR looks good. I want have a conversation about having a Load method that doesn't require you to say what the format is, but we can defer that to conversation to after this PR has been merged..

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
26.0% Coverage on New Code (required ≥ 80%)
15.5% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@MaggieKimani1 MaggieKimani1 merged commit 624814d into release/2.0.0 Mar 26, 2024
@MaggieKimani1 MaggieKimani1 deleted the mk/use-loading-pattern branch March 26, 2024 12:58
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.

5 participants