UNPKG

@mintlify/validation

Version:

Validates mint.json files

25 lines (24 loc) 1.13 kB
import hash from 'object-hash'; import { v4 as uuidv4 } from 'uuid'; import { replaceSchemaRefs } from './replaceSchemaRefs.js'; export const mapSchemaComponents = ({ spec, refUuidMap, uuidObjectHashMap, hashedNodeMap, }) => { var _a; const schemaComponents = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.schemas; if (!schemaComponents) return; // Create a shared schemaToUuidMap for all schemas in this component set const schemaToUuidMap = new WeakMap(); Object.entries(schemaComponents).forEach(([schemaName, schema]) => { // match the refId to uuid const refId = `#/components/schemas/${schemaName}`; const uuid = refUuidMap[refId] || uuidv4(); // hash the raw object const objectHash = hash(schema); // map uuid and hash to uuidObjectHashMap uuidObjectHashMap[uuid] = objectHash; // replace refs in schema nodes with uuids replaceSchemaRefs({ schema, refUuidMap, uuidObjectHashMap, hashedNodeMap, schemaToUuidMap }); // add to hashedNodeMap hashedNodeMap[objectHash] = schema; }); };