feat: sort out $ref resolving once and for all #127
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When signing off https://github.com/stoplightio/platform-internal/issues/5218 I spotted there is at least one additional place I didn't cover... This freaked me out a little bit, and I decided to revamp our approach to $ref resolving.
I'm uncertain whether we'll merge it or not, but opening a PR to have a forum to discuss the pros and cons.
Alright, here is the idea.
Instead of resolving each $ref in place, we could simply 'trap' the whole document.
I created a small util that would do that for us stoplightio/json#72.
In other words, Graphite would do something as follows
transformXyz(inlineRefResolver(node.data.resolved))and all inline $refs would be automatically resolved as needed.There is one significant (or maybe not?) con - we'd also potentially attempt to resolve $refs in invalid zones. OAS doesn't let you use $refs everywhere, thus the current conservative approach is perhaps a bit more correct here, but also much more difficult to maintain.
The hope is that Spectral could notify about incorrect usage, or we could bake an ignorelist in the util itself.