Allow excluding certain paths from dereferencing #249
Merged
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.
This is the first step towards fixing APIDevTools/swagger-parser#160 and thereby github/rest-api-description#188.
In OpenAPI, examples must be interpreted literally. For example, a response could include this
examples
field to illustrate a possible HTTP JSON response body:(This is a smaller version of a real example from GitHub's OpenAPI spec)
In this case, this is showing an example where a response really will contain a $ref field - it's not a ref to an external resource in the spec, and it shouldn't ever be dereferenced.
The OpenAPI spec on example objects here describes this as an "Embedded literal example" and this discussion goes into more detail.
The only way to handle cases like this is to allow callers of
dereference
to stop dereferencing at certain points within a schema's structure. This PR adds aexcludedPathsMatcher
dereference option, which allows the caller to provide a callback that can do this.The example test shows a quick & dirty approach to how the OpenAPI problem could be solved with this new option. It's not rigorous (really it should be checking against a large list of possible paths from the root) but it shows you the general idea and produces the correct result given the example included here.