Skip to content

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

Closed

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 {

Activity

  1. philsturgeon commented on Nov 7, 2022

    @philsturgeon
    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

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