UNPKG

@sap/cli-core

Version:

Command-Line Interface (CLI) Core Module

21 lines (20 loc) 636 B
import { Ajv } from "ajv"; import { get as getLogger } from "../logger/index.js"; export const validate = async (schema, data) => { const logger = getLogger("jsonschema"); try { const ajv = new Ajv({ logger }); // use await, see ajv.js.org/api.html#ajv-validate-schemaorref-object-string-data-any-boolean await ajv.validate(schema, data); return { result: "VALID", }; } catch (err) { logger.error("error while compiling schema or validating data", err.stack); return { result: "INVALID", errors: err.errors, }; } };