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

Added support for handling Remote URL refs in the bundle method #747

Merged

Conversation

prashantRaghu
Copy link
Collaborator

lib/bundle.js Outdated

let isPartial = partialComponents.length > 1;
if (isPartial && !isReferenceRemoteURL) {
referencePath = partialComponents.slice(0, partialComponents.length - 1).join('#');
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a comment in the code on why this is needed with an example if possible? I'm not getting the need of joining it with # compared to the previous logic, as we're changing this code that's applicable for non-remote refs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@VShingala had done this refactor to test out some deep ref scenarios, but this check is just a more generic check in case we encounter reference paths that contain multiple hash fragments, but turns out we don't need this for any scenario so reverting this back to the original check

lib/bundle.js Show resolved Hide resolved
lib/bundle.js Outdated
return JSON.stringify(parsedFile.oasObject);
}

let contentFromRemote = await remoteRefResolver(property.$ref),
Copy link
Member

Choose a reason for hiding this comment

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

We should have some handling in cases where this may fail and throw error.

we can either ignore and keep the field as is or mention it missing in bundled content somehow. But not handling it at all can cause issues.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Handled err scenario

lib/bundle.js Outdated
if (isMissingNode) {
refData.nodeContent = refData.node;
refData.local = false;
}
else if (!refData) {
return;
}
else if (isExtRef(property, '$ref') && !isExtURLRef(property, '$ref')) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep the existing condition logic for else statement as is and use (!isExtRef(property, '$ref') && isExtURLRef(property, '$ref') as condition and add new logic here.

Reason behind it is as logic for HTTP is very specific and to handle future scenarios better as existing logic is more generic.

expect(res.result).to.be.true;
expect(res.output.specification.version).to.equal('3.0');
expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected);
});
Copy link
Member

Choose a reason for hiding this comment

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

Let's add few more tests to make sure the below scenarios also works.

  • Circular refs (A -> B -> C -> A). We should have this handled and circular ref should not be resolved to avoid obvious further issues.
  • If remoteRefResolver throws error, depending upon our handling expect the result instead entire function throwing error.
  • Should return bundled file as yaml with yaml remote refs
  • Should return bundled file as yaml with json content remote refs - remote_url_refs

@VShingala
Copy link
Member

@prashantRaghu Let's also add a changelog for this feature. We can add it under Added section within Unreleased section. This makes sure with release, changelog automatically gets added.

Here's sample PR and change done in changelog for reference: #732

@prashantRaghu
Copy link
Collaborator Author

@VShingala Added changelog, please verify if its done correctly

* For nodes that are fetched for remote URLs we ensure they
* aren't visited more than once
*/
(!node.href || (!hrefsVisited.has(node.href)))
Copy link
Member

Choose a reason for hiding this comment

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

In which cases !node.href can be true? i.e. if node.href is empty, in subsequent logic line no. 54 here, we're adding it to hrefsVisited. Not sure if this is intended.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

!node.href would be true for all non remote reference nodes, I'll add an extra check at line 54

CHANGELOG.md Outdated
@@ -2,6 +2,10 @@

## [Unreleased]

### Added

- Added support for resolving of remote URL refs in bundle method
Copy link
Member

Choose a reason for hiding this comment

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

Added support for remote $ref resolution in bundle() API.

@prashantRaghu prashantRaghu merged commit 29aa86c into develop Aug 18, 2023
6 checks passed
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.

None yet

2 participants