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

Function assertSchemaHasValidIdField

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

Source from the content-addressed store, hash-verified

1773}
1774
1775async function assertSchemaHasValidIdField(/** @type {SchemaFile} */ schema) {
1776 let schemaId = ''
1777 /**
1778 * Old JSON Schema specification versions use the "id" key for unique
1779 * identifiers, rather than "$id". See for details:
1780 * https://json-schema.org/understanding-json-schema/basics.html#declaring-a-unique-identifier
1781 */
1782 const schemasWithDollarlessId = [
1783 'http://json-schema.org/draft-03/schema#',
1784 'http://json-schema.org/draft-04/schema#',
1785 ]
1786 if (schemasWithDollarlessId.includes(schema.json.$schema)) {
1787 if (schema.json.id === undefined) {
1788 printErrorAndExit(new Error(), [
1789 `Missing property 'id' for schema "./${path.join(SchemaDir, schema.name)}"`,
1790 ])
1791 }
1792 schemaId = schema.json.id
1793 } else {
1794 if (schema.json.$id === undefined) {
1795 printErrorAndExit(new Error(), [
1796 `Missing property '$id' for schema "./${path.join(SchemaDir, schema.name)}"`,
1797 ])
1798 }
1799 schemaId = schema.json.$id
1800 }
1801
1802 if (!schemaId.startsWith('https://') && !schemaId.startsWith('http://')) {
1803 printErrorAndExit(new Error(), [
1804 `Expected schema id/$id to begin with 'https://' or 'http://'`,
1805 `Found schema with value of "${schemaId}" in "./${path.join(SchemaDir, schema.name)}"`,
1806 ])
1807 }
1808}
1809
1810async function assertSchemaHasCorrectMetadata(
1811 /** @type {SchemaFile} */ schema,

Callers 1

onSchemaFileFunction · 0.85

Calls 1

printErrorAndExitFunction · 0.85

Tested by

no test coverage detected