Skip to content
Message validator for Kafka/RabbitMQ/Anything through AsyncAPI schema
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist moved to dist Jul 15, 2019
test fixed test lint / bump version Sep 1, 2019
.eslintignore fixed eslint Jul 15, 2019
.eslintrc.json updated implementatoin Jul 13, 2019
.gitignore updated git ignore Jul 15, 2019
.travis.yml added codecov Jul 7, 2019
LICENSE Initial commit Jun 1, 2019 updated errors Jul 24, 2019
codecov.yml added codecov config Jul 7, 2019
index.js re structure, use schema validator Jul 15, 2019
jest.config.js updated implementatoin Jul 13, 2019
package-lock.json fixed test lint / bump version Sep 1, 2019

Build Status codecov


message validator through asyncapi schema

npm i asyncapi-validator


  • Validate your AsyncApi Schema against AsyncApi Schema definition
  • Validate your messages against your AsyncApi Schema definition
  • Use 'bundle.min.js' to run validator in browser
  • Load your AsyncApi Schema from local file or any URL
  • Supports AsyncApi in JSON and YAML format
  • Supports all versions of AsyncAPI
  • more coming . . .


 * @param {String} path - local path or URL of AsyncAPI schema
 * @param {Object} options - options for validation
 * @returns {Promise}
fromSource(path, options)

 * @param {String} key
 * @param {Object} payload
validate(key, payload)


value type description
ignoreArray boolean If true, then if schema is defined as an array and payload is an object, then payload will be placed inside an array before validation.


const AsyncApiValidator = require('asyncapi-validator')
let va = await AsyncApiValidator.fromSource('./api.yaml')

// validate 'UserDeleted' key with payload
va.validate('UserDeleted', {
  userId: 'bd58d14f-fd3e-449c-b60c-a56548190d68',
  deletedBy: 'bd58d14f-fd3e-449c-b60c-a56548190d68',
  deletedAt: '2017-01-09T08:27:22.222Z',

// validate 'Key' key with payload
va.validate('Key', {1:1})


Error thown from asyncapi-validator will have these properties.

key type value description
name string AsyncAPIValidationError AsyncAPIValidationError
key string "key" of payload against which schema is validated
message string errorsText from AJV
errors array Array of errors from AJV

Error Example

  AsyncAPIValidationError: data.type should be equal to one of the allowed values at MessageValidator.validate (.....
  name: 'AsyncAPIValidationError',
  key: 'hello',
      { keyword: 'enum',
        dataPath: '.type',
        schemaPath: '#/properties/type/enum',
        params: [Object],
        message: 'should be equal to one of the allowed values'
You can’t perform that action at this time.