Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/reference proxy single copy #2031

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Open

Conversation

baywet
Copy link
Member

@baywet baywet commented Dec 27, 2024

partial #1998

@baywet baywet self-assigned this Dec 27, 2024
/// <param name="openApiSchema">The schema to add</param>
/// <param name="id">The id for the component</param>
/// <returns>Whether the schema was added to the components.</returns>
public bool AddComponentSchema(string id, OpenApiSchema openApiSchema)
Copy link
Member

Choose a reason for hiding this comment

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

Is this not relevant for all types of components? Should we just have a AddComponent method with overloads for the different types of components?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm iterating here, so far the only one that was problematic in the context of yoko was the schemas.
We also need to think about making collections read only maybe, and adding a method to remove entries, so everything is in sync.

Copy link
Contributor

@MaggieKimani1 MaggieKimani1 Jan 6, 2025

Choose a reason for hiding this comment

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

We already have an extension method for registering components into a document's workspace(components registry). Should we just reuse these?

public void RegisterComponents(OpenApiDocument document)
{
if (document?.Components == null) return;
string baseUri = document.BaseUri + OpenApiConstants.ComponentsSegment;
string location;
// Register Schema
foreach (var item in document.Components.Schemas)
{
location = item.Value.Id ?? baseUri + ReferenceType.Schema.GetDisplayName() + "/" + item.Key;
RegisterComponent(location, item.Value);
}
// Register Parameters
foreach (var item in document.Components.Parameters)
{
location = baseUri + ReferenceType.Parameter.GetDisplayName() + "/" + item.Key;
RegisterComponent(location, item.Value);
}
// Register Responses
foreach (var item in document.Components.Responses)
{
location = baseUri + ReferenceType.Response.GetDisplayName() + "/" + item.Key;
RegisterComponent(location, item.Value);
}
// Register RequestBodies
foreach (var item in document.Components.RequestBodies)
{
location = baseUri + ReferenceType.RequestBody.GetDisplayName() + "/" + item.Key;
RegisterComponent(location, item.Value);
}
// Register Links
foreach (var item in document.Components.Links)
{
location = baseUri + ReferenceType.Link.GetDisplayName() + "/" + item.Key;
RegisterComponent(location, item.Value);
}
// Register Callbacks
foreach (var item in document.Components.Callbacks)
{
location = baseUri + ReferenceType.Callback.GetDisplayName() + "/" + item.Key;
RegisterComponent(location, item.Value);
}
// Register PathItems
foreach (var item in document.Components.PathItems)
{
location = baseUri + ReferenceType.PathItem.GetDisplayName() + "/" + item.Key;
RegisterComponent(location, item.Value);
}
// Register Examples
foreach (var item in document.Components.Examples)
{
location = baseUri + ReferenceType.Example.GetDisplayName() + "/" + item.Key;
RegisterComponent(location, item.Value);
}
// Register Headers
foreach (var item in document.Components.Headers)
{
location = baseUri + ReferenceType.Header.GetDisplayName() + "/" + item.Key;
RegisterComponent(location, item.Value);
}
// Register SecuritySchemes
foreach (var item in document.Components.SecuritySchemes)
{
location = baseUri + ReferenceType.SecurityScheme.GetDisplayName() + "/" + item.Key;
RegisterComponent(location, item.Value);
}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

@darrelmiller I've just updated the methods to take into account all the component types.
@MaggieKimani1 no, this method registers everything at once. This is problematic because ordering might matter in some contexts (typically OData), and it results in a perf hit when wanting to register only a few components. Also, it's only accessible on the workspace, my goal was to make it accessible on the document for better discovery.

@baywet baywet marked this pull request as ready for review January 6, 2025 17:50
@baywet baywet enabled auto-merge January 6, 2025 17:50
Signed-off-by: Vincent Biret <[email protected]>
Copy link

sonarqubecloud bot commented Jan 6, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
45.2% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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.

3 participants