Skip to content

[Feature Req] Additional property on file object #256

@JaiPe

Description

@JaiPe

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions