MCPcopy Create free account
hub / github.com/SchemaStore/schemastore / assertSchemaHasCorrectMetadata

Function assertSchemaHasCorrectMetadata

cli.js:1810–1851  ·  view source on GitHub ↗
(
  /** @type {SchemaFile} */ schema,
)

Source from the content-addressed store, hash-verified

1808}
1809
1810async function assertSchemaHasCorrectMetadata(
1811 /** @type {SchemaFile} */ schema,
1812) {
1813 const schemasWithDollarlessId = [
1814 'http://json-schema.org/draft-03/schema#',
1815 'http://json-schema.org/draft-04/schema#',
1816 ]
1817
1818 if (schemasWithDollarlessId.includes(schema.json.$schema)) {
1819 if (schema.json.$id) {
1820 printErrorAndExit(new Error(), [
1821 `Expected to find correct metadata on schema file "./${schema.path}"`,
1822 `Bad property of '$id'; expected 'id' for this schema version`,
1823 ])
1824 }
1825
1826 if (schema.json.id !== `https://www.schemastore.org/${schema.name}`) {
1827 printErrorAndExit(new Error(), [
1828 `Expected to find correct metadata on schema file "./${schema.path}"`,
1829 `Incorrect property 'id' for schema "./${path.join(SchemaDir, schema.name)}"`,
1830 `Expected value of "https://www.schemastore.org/${schema.name}"`,
1831 `Found value of "${schema.json.id}"`,
1832 ])
1833 }
1834 } else {
1835 if (schema.json.id) {
1836 printErrorAndExit(new Error(), [
1837 `Expected to find correct metadata on schema file "./${schema.path}"`,
1838 `Bad property of 'id'; expected '$id' for this schema version`,
1839 ])
1840 }
1841
1842 if (schema.json.$id !== `https://www.schemastore.org/${schema.name}`) {
1843 printErrorAndExit(new Error(), [
1844 `Expected to find correct metadata on schema file "./${schema.path}"`,
1845 `Incorrect property '$id' for schema "./${path.join(SchemaDir, schema.name)}"`,
1846 `Expected value of "https://www.schemastore.org/${schema.name}"`,
1847 `Found value of "${schema.json.$id}"`,
1848 ])
1849 }
1850 }
1851}
1852
1853async function assertSchemaNoSmartQuotes(/** @type {SchemaFile} */ schema) {
1854 const buffer = schema.buffer

Callers

nothing calls this directly

Calls 1

printErrorAndExitFunction · 0.85

Tested by

no test coverage detected