Throw dereferencing errors #22
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.
Motivation
I'm working on converting schemas from backstage.io into OpenAPI for backstage/backstage#2566. The schema in master seems to use incorrect references so I was surprised to find that json-schema-to-openapi-schema did not fail. It was quite confusing because the
$ref
didn't get resolved but the function did not fail.Once I started looking at the code, I realized that
resolver.resolve
succeeds even if dereferencing fails. I believe@stoplight/json-ref-resolver
should actually throw an error in this case but that would be a substantial breaking change to that library. Instead, I'm just fixing error reporting in this library.Approach
Throw an error when dereferencing has errors in results. I added a test for this.