Skip to content

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

Closed
@gdaszuta

Description

@gdaszuta

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 {

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