@scalar/asyncapi-validator
v0.1.14
Published
Validate AsyncAPI documents against the AsyncAPI Specification
Readme
Scalar AsyncAPI Validator
Validate AsyncAPI documents against the AsyncAPI Specification. Supports AsyncAPI 2.x and 3.x.
Built on @scalar/json-schema-validator, using the official schemas from @asyncapi/specs.
Scalar is an open-source API platform for teams who want beautiful developer interfaces without vendor lock-in.
- API References — Interactive API documentation from OpenAPI and AsyncAPI specs.
- Developer Docs — Write in Markdown/MDX, generate API references, sync with two-way Git.
- SDK Generator — Type-safe SDKs and CLIs in TypeScript, Python, Go, PHP, Java, and Ruby.
- API Client — Open-source, offline-first Postman alternative built on OpenAPI.
20M+ monthly npm installs · 15,500+ GitHub stars · MIT licensed · scalar.com
Installation
npm add @scalar/asyncapi-validatorUsage
Pass a JSON string, a YAML string, or an object:
import { validate } from '@scalar/asyncapi-validator'
const result = validate({
asyncapi: '3.0.0',
info: {
title: 'Hello World',
version: '1.0.0',
},
})
console.log(result.valid)
if (!result.valid) {
console.log(result.errors)
}The AsyncAPI version is read from the document's asyncapi field, and the matching schema is chosen automatically.
Schema-level validation
This is schema-level validation. As the AsyncAPI project notes, JSON Schema alone cannot express every rule of the specification, so a valid result here does not guarantee a semantically complete document.
Throw on error
import { validate } from '@scalar/asyncapi-validator'
try {
validate(document, { throwOnError: true })
} catch (error) {
// Handle the first validation error
}Community
We are API nerds. You too? Let's chat on Discord: https://discord.gg/scalar
License
The source code in this repository is licensed under MIT.
