MCPcopy Index your code
hub / github.com/SchemaStore/schemastore / assertFileValidatesAgainstSchema

Function assertFileValidatesAgainstSchema

cli.js:1726–1745  ·  view source on GitHub ↗
(
  /** @type {string} */ filepath,
  /** @type {string} */ schemaFilepath,
)

Source from the content-addressed store, hash-verified

1724}
1725
1726async function assertFileValidatesAgainstSchema(
1727 /** @type {string} */ filepath,
1728 /** @type {string} */ schemaFilepath,
1729) {
1730 const [data, schemaJson] = await Promise.all([
1731 fs.readFile(filepath, 'utf-8').then((data) => jsoncParser.parse(data)),
1732 readJsonFile(schemaFilepath),
1733 ])
1734
1735 const ajv = new AjvDraft06And07({
1736 strict: true,
1737 })
1738 addFormats(ajv)
1739
1740 if (ajv.validate(schemaJson, data)) {
1741 console.info(`✔️ ${path.basename(filepath)} validates against its schema`)
1742 } else {
1743 printSchemaValidationErrorAndExit(filepath, schemaFilepath, ajv.errors)
1744 }
1745}
1746
1747async function assertSchemaHasValidSchemaField(
1748 /** @type {SchemaFile} */ schema,

Callers 1

taskCheckFunction · 0.85

Calls 2

readJsonFileFunction · 0.70

Tested by

no test coverage detected