@smartrecruiters/openapi-schemas-validator
v0.3.1
Published
Validator for schemas defined in OpenAPI Specification 3.0
Downloads
307
Readme
@smartrecruiters/openapi-schemas-validator
Create schema validators for api documentation in OpenAPI Specification 3.x format.
tv4
This module uses tv4 validator, additionally configured with tv4-formats.
This module uses tv4 validateMultiple
function,
with checkRecursive
param always passed as true
.
You can configure tv4 validator with following options:
- customFormats - will be passed to
tv4.addFormat
function - banUnknownProperties - will be passed to validating function (The banUnknownProperties flag)
There is exported an ErrorCodes
object containing mappings between error code numbers and error names that are generated by tv4 validator.
OpenAPI Specification 3.0 specific features
Currently @smartrecruiters/openapi-schemas-validator supports nullable
field.
Please refer to https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#fixed-fields-20.
License
API
Modules
Classes
@smartrecruiters/openapi-schemas-validator
SchemaValidator
Kind: global class
new SchemaValidator(spec, [options])
Create schema validator for schemas defined in spec at #/components/schemas
| Param | Type | Default | Description | | --- | --- | --- | --- | | spec | Object | | API specification in OpenAPI Specification 3.0 format | | [options] | Object | {} | options | | [options.customFormats] | Object | | custom format validators | | [options.banUnknownProperties] | boolean | false | disallow extra properties in validated objects |
schemaValidator.validate(entity, schema) ⇒ Array.<Object>
Validate object against schema. Schema can be passed explicitly or reference a schema from spec.
Kind: instance method of SchemaValidator
Returns: Array.<Object> - An array with errors when object is invalid, undefined
otherwise
| Param | Type | Description | | --- | --- | --- | | entity | Object | object to validate | | schema | Object | string | object schema |