This repository has been archived by the owner on Aug 4, 2023. It is now read-only.
Allow custom JSON Schema validator in validator middleware (fixes #467) #471
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 changeset provides an option to allow a custom JSON schema validator to be passed to the validation middleware. See further discussion in #467.
In general this actually a small change.
validateAgainstSchema()
invalidators.js
already supported passing an external validator to it. So this change is mostly just adding another parameter to the optionsthat
swagger-validator
accepts, and then passing any validator down until it gets tovalidateAgainstSchema()
.There are other minor changes around error handling to be slightly more flexible in the error handling for validation errors, so that the custom validator doesn't have to be exactly identical in response to z-schema (the default validator). If the response is not identical you will still get errors; you just won't get the slightly improved error messages that swagger-tools generates from the z-schema error messages in some corner cases.
This change also includes updated unit tests to check that:
format
s andvendor extension
s (also known ascustom keyword
s) that are not able to be verified using the default validator.NOTE: this ONLY allows custom validation of
schema
objects in the body of a request or response.NOTE:
path
andquery
parameters, and the schema itself will still be validated by the inbuilt validators, irrespective of any validator passed in.Finally, the
Middleware.md
docs have been updated with the new capability.Test Plan: