Skip to content

onDereference callback mentioned in documentation, yet missing from the latest release #287

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

Closed
gdaszuta opened this issue Nov 3, 2022 · 1 comment

Comments

@gdaszuta
Copy link

gdaszuta commented Nov 3, 2022

So yeah, everything is in the title: https://apitools.dev/json-schema-ref-parser/docs/options.html mentions options.reference.onDereference callback, yet it's missing from latest release:

$ grep '"version"' node_modules/@apidevtools/json-schema-ref-parser/package.json 
  "version": "9.0.9",
$ diff -u node_modules/@apidevtools/json-schema-ref-parser/lib/dereference.js ../../json-schema-ref-parser/lib/dereference.js
--- node_modules/@apidevtools/json-schema-ref-parser/lib/dereference.js	2022-11-03 09:52:16.125999000 +0100
+++ ../../json-schema-ref-parser/lib/dereference.js	2022-11-02 18:45:29.807704592 +0100
@@ -41,8 +41,10 @@
     circular: false
   };
 
+  let isExcludedPath = options.dereference.excludedPathMatcher;
+
   if (options.dereference.circular === "ignore" || !processedObjects.has(obj)) {
-    if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj)) {
+    if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj) && !isExcludedPath(pathFromRoot)) {
       parents.add(obj);
       processedObjects.add(obj);
 
@@ -55,6 +57,11 @@
         for (const key of Object.keys(obj)) {
           let keyPath = Pointer.join(path, key);
           let keyPathFromRoot = Pointer.join(pathFromRoot, key);
+
+          if (isExcludedPath(keyPathFromRoot)) {
+            continue;
+          }
+
           let value = obj[key];
           let circular = false;
 
@@ -64,6 +71,9 @@
             // Avoid pointless mutations; breaks frozen objects to no profit
             if (obj[key] !== dereferenced.value) {
               obj[key] = dereferenced.value;
+              if (options.dereference.onDereference) {
+                options.dereference.onDereference(value.$ref, obj[key]);
+              }
             }
           }
           else {
@philsturgeon
Copy link
Member

That method was introduced by #281 and the release has not yet happened as a few bit PRs are still failing tests. It'll be available when those PRs are solved so if you can pitch in a fix there that'll be awesome.

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