Workaround for OpenAPI / Swagger v2 schema validation #62
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.
Hi Nate,
Currently jayschema does not validate document instances of OpenAPI / Swagger v2
schemas which is a valid JSON Schema Draft 4 specification. jayschema does correctly
validate the schema itself, but fails subsequently for instance validation against that schema as follows:
This is due to declarations of the following form in the Schema for Swagger v2:
Which themselves are working around lack of references in Json Schema Draft 4 for
'$ref' itself. Declaring
$ref
as type string ( for which there is also no declarationin the Json Schema Draft4 Schema ) seems reasonable.
This PR patches
lib/schemaRegistry._gatherRefs
to detect this pattern of use andskip adding it to the gathered references. By so doing, it allows the usage of '$ref' in schema
documents, and validation against in document instances.
Submitting a PR in the hopes that it is a useful workaround/fix for anyone writing or
using schema documents that define and use '$ref' in accordance with the intended
use in Json Schema itself.