json-refs icon indicating copy to clipboard operation
json-refs copied to clipboard

Fix for bug where refs property does not include invalid ref, if invalid reference is part of a nested file, even if includeInvalid option is set to true

Open sticklerdev opened this issue 5 years ago • 7 comments

Changes:

  • The bail out action for invalid references (when building metadata) was happening one step too soon - before it was recorded in the deps property. Moved the check for isValid after the dependency is recored.
  • Updated test-nested.yaml to include an invalid reference in the file.
  • Updated test-json-refs.js file's "expected" values.

sticklerdev avatar Sep 07 '18 19:09 sticklerdev

Can you tell me why this is important? I don't disagree but the whole purpose of the deps property was for building a graph of dependencies so that I could identify circular dependencies. Since invalid references can't be circular, it didn't seem to fit. But...I can see where it might be useful. So what's the use case?

whitlockjc avatar Sep 07 '18 19:09 whitlockjc

This is not about circularity.

Say I have an invalid reference in file A (which is my root for resolution). If I specify includeInvalid=true, then this invalid reference in file A is reported to me in the refs property, as expected and I can filter on it. But now, if the file A references file B (which has no reference back to file A - so no circularity in play here but does have an invalid reference), then the invalid reference in file B isn't reported.

On the other hand, missing references are reported correctly whether they are in the root file A or in a nested file B.

This pull request is an attempt to fix this behavior. If these nested invalids aren't reported then I can't filter them either.

Thanks.

sticklerdev avatar Sep 07 '18 19:09 sticklerdev

I know it's not about circularity, I'm explaining where the deps property came from in the first. I'm trying to understand what other cases there are. Thanks for explaining.

whitlockjc avatar Sep 07 '18 19:09 whitlockjc

The one particular use case I have is to validate the document against JSON schema but only after all references have been successfully resolved. If the resolution fails (either because of invalids or missings), then there errors are reported back to the user, instead of moving forward with the validation step. Since invalids weren't being reported, I was coming up with a false positive and moving to the validation step instead of short-circuiting.

sticklerdev avatar Sep 07 '18 19:09 sticklerdev

Can you run npm test locally? It seems like tests are failing.

whitlockjc avatar Sep 10 '18 20:09 whitlockjc

Do you know which tests? Some tests have always failed for me (I am on windows) even before the changes?

sticklerdev avatar Sep 11 '18 16:09 sticklerdev

The TravisCI build has them, linked above. Your tests shouldn't be failing, maybe there is a Windows build issue I'm not aware of. I'll try to spin up a Windows VM to test.

whitlockjc avatar Sep 12 '18 16:09 whitlockjc