0.3.1 • Published 1 year ago

@smartrecruiters/openapi-schemas-validator v0.3.1

Weekly downloads
157
License
MIT
Repository
github
Last release
1 year ago

@smartrecruiters/openapi-schemas-validator

NPM Version NPM Downloads Node.js Version Licence Build

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:

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

MIT

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

ParamTypeDefaultDescription
specObjectAPI specification in OpenAPI Specification 3.0 format
optionsObject{}options
options.customFormatsObjectcustom format validators
options.banUnknownPropertiesbooleanfalsedisallow 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

ParamTypeDescription
entityObjectobject to validate
schemaObject | stringobject schema