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

[Feature Req] Additional property on file object #256

Closed
JaiPe opened this issue Feb 7, 2022 · 1 comment
Closed

[Feature Req] Additional property on file object #256

JaiPe opened this issue Feb 7, 2022 · 1 comment

Comments

@JaiPe
Copy link

JaiPe commented Feb 7, 2022

Hi
Great library, thanks for your hard work on this.

I was wondering if we could expose something akin to this change:

diff --git a/node_modules/@apidevtools/json-schema-ref-parser/lib/parse.js b/node_modules/@apidevtools/json-schema-ref-parser/lib/parse.js
index b9160df..48d56bd 100644
--- a/node_modules/@apidevtools/json-schema-ref-parser/lib/parse.js
+++ b/node_modules/@apidevtools/json-schema-ref-parser/lib/parse.js
@@ -18,8 +18,13 @@ module.exports = parse;
  * The promise resolves with the parsed file contents, NOT the raw (Buffer) contents.
  */
 async function parse (path, $refs, options) {
-  // Remove the URL fragment, if any
-  path = url.stripHash(path);
+  let hashIndex = path.indexOf("#");
+  let hash = "";
+  if (hashIndex >= 0) {
+    hash = path.substr(hashIndex);
+    // Remove the URL fragment, if any
+    path = path.substr(0, hashIndex);
+  }
 
   // Add a new $Ref for this file, even though we don't have the value yet.
   // This ensures that we don't simultaneously read & parse the same file multiple times
@@ -28,6 +33,7 @@ async function parse (path, $refs, options) {
   // This "file object" will be passed to all resolvers and parsers.
   let file = {
     url: path,
+    hash,
     extension: url.getExtension(path),
   };
 

I am currently building a wildcard ref resolver, but am in need of the original hash item inside the resolver function to achieve this. I can't see a way to obtain it with the current API - but I imagine it could be useful for other situations within a file resolver too - so would be useful to add.

@jonluca
Copy link
Collaborator

jonluca commented Mar 6, 2024

Great suggestion, included in the latest version

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

No branches or pull requests

2 participants