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

Filter 'relative' does not behave as expected #154

Open
saguinav opened this issue Mar 5, 2019 · 3 comments
Open

Filter 'relative' does not behave as expected #154

saguinav opened this issue Mar 5, 2019 · 3 comments

Comments

@saguinav
Copy link

saguinav commented Mar 5, 2019

According to the API documentation, the filter option allows us to specify what type of references we want to be resolved. In a previous version of this library (2.1.6), it was possible to do:

const options = {
        filter: 'relative',
        loaderOptions: {
          processContent: (res, cb) => {
            cb(null, yaml.safeLoad(res.text));
          },
        },
      };

resolveRefs(root, options)

Resulting in only relative references being resolved, meaning that any other references (like remote references) would remained unresolved.

However, in the latest version of this library this is no longer possible, given that all reference types that are considered "remote" (both relative and remote, see here) are forced to be fully resolved (see here).

It would be great if this filter option could be restored to allow developers decide which reference types should be resolved and which not.

Please let me know if this issue seems interesting to you. I would be happy to contribute with a fix. Cheers!

@saguinav saguinav changed the title Filter 'remote' does not behave as expected Filter 'relative' does not behave as expected Mar 5, 2019
@saguinav
Copy link
Author

saguinav commented Mar 5, 2019

Here is an example:

Input

{
  "a": "./b/c.yaml",
  "d": "https://my.domain.com/e/f.yaml
}

Expected Output

{
  "a": {
     "b": "c"
  },
  "d": "https://my.domain.com/e/f.yaml
}

Actual Output

{
  "a": {
     "b": "c"
  },
  "d": {
    "e": "f"
   }
}

Update March 11th

I just submitted a PR that includes a unit test that showcases this issue (see #155). While I was writing this unit test I realized that this example is actually not accurate and is not valid to reproduce the issue. The problem only applies to the remote references contained by any relative reference. Therefore, a more appropriate example would look like this:

Input

Root json file
{
  "a": {
    "$ref": "./b/c.json"
  }
  "d": {
    "$ref": "https://my.domain.com/e/f.json"
  }
}

File ./b/c.json
{
  "b": {
    "$ref": "https://my.domain.com/c.json"
  }
}

Expected Output

{
  "a": {
    "b": {
      "$ref": "https://my.domain.com/c.json"
    }
  }
  "d": {
    "$ref": "https://my.domain.com/e/f.json"
  }
}

Actual Output

{
  "a": {
    "b": {
      "c": "some dummy content"
    }
  }
  "d": {
    "$ref": "https://my.domain.com/e/f.json"
  }
}

I hope this example makes more sense @whitlockjc

@whitlockjc
Copy link
Owner

Thanks for the reproduction, I didn't realize we broke this. I will get on this.

@saguinav
Copy link
Author

saguinav commented Mar 6, 2019

@whitlockjc do you have an ETA for the fix? Thanks in advance.

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