Registry / devops / yaml-schema-validator

yaml-schema-validator

JSON →
library1.2.3jsnpmunverified

A schema validation utility for YAML and JSON files against a predefined schema, written in JavaScript. Current version 1.2.3. Allows validation via file paths, plain objects, or schema objects. Supports custom validators and custom error messages. Limited release history; no breaking changes documented. Lightweight, no runtime dependencies, works in Node.js only.

npm install yaml-schema-validator
INSTALL
IMPORT
SIG · YAML-SCHEMA-VALIDA
Y
yaml-schema-validator
devopsjavascriptv1.2.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

validateSchema
const validateSchema = require('yaml-schema-validator')
import validateSchema from 'yaml-schema-validator'
Package is CommonJS only; ES import syntax may fail.
validateSchema
const { validateSchema } = require('yaml-schema-validator')
const validateSchema = require('yaml-schema-validator').default
No default export; must use named destructuring or direct assignment (the whole module is the function).
Schema
const { Schema } = require('yaml-schema-validator')
const Schema = require('yaml-schema-validator').Schema
Schema constructor for defining custom validators with .use and .message.

Demonstrates three validation methods: file vs schema file, object vs schema object, and object vs reference object.

const validateSchema = require('yaml-schema-validator'); // Validate a YAML file against a schema file const errors = validateSchema('target.yml', { schemaPath: 'schema.yml' }); if (errors.length > 0) { console.log('Validation errors:', errors); } else { console.log('Validation passed'); } // Validate a plain object against a JS schema object const person = { name: { first: 'Tom', last: 'Xoman' }, age: 45 }; const requiredSchema = { name: { first: { type: String, required: true }, last: { type: String, required: true } }, age: { type: Number } }; const schemaErrors = validateSchema(person, { schema: requiredSchema }); console.log(schemaErrors); // Validate using an ideal object's structure (schemaObj) const idealPerson = { name: { first: 'Tom', last: 'Xoman' }, age: 45 }; const compareErrors = validateSchema(person, { schemaObj: idealPerson }); console.log(compareErrors);
Debug
Known issues
gotchavalidateSchema returns an array of errors; does not throw on validation failure.
fix
Always check the returned array length to determine pass/fail.
affects: >=0.0.0
gotchaThe package is CommonJS-only. Using ES import syntax (import validateSchema from ...) will fail.
fix
Use require() or configure your bundler to handle CJS.
affects: >=0.0.0
gotchaschemaPath option requires a file path; passing a URL or buffer may cause unexpected errors.
fix
Provide a valid filesystem path or use the `schema` option with a JS object.
affects: >=0.0.0
gotchaThe library does not validate the schema file itself; invalid schema may cause silent failures.
fix
Ensure your schema file is valid JSON/YAML and conforms to the expected structure.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: validateSchema is not a function
Attempting to use ES import or destructuring incorrectly on a CommonJS module.
fix
Use `const validateSchema = require('yaml-schema-validator')`
Cannot find module 'yaml-schema-validator'
Package not installed or running in an environment without node_modules.
fix
Run `npm install yaml-schema-validator` and ensure you are in the correct directory.
ENOENT: no such file or directory, open 'schema.yml'
The file path provided to schemaPath or target does not exist.
fix
Provide absolute paths or ensure the relative path is correct from the working directory.
Upgrade
Version history
1.2.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
8
Amazon
1
Resources
yaml-schema-validator — npm install yaml-schema-validator · libregistry