UNPKG

@mintlify/validation

Version:

Validates mint.json files

16 lines (15 loc) 843 B
import hash from 'object-hash'; import { replaceSchemaRefs } from './replaceSchemaRefs.js'; export const mapSchema = ({ schema, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, schemaToUuidMap = new WeakMap(), }) => { const objectHash = hash(schema); uuidObjectHashMap[uuid] = objectHash; // if objectHash already exists, replace with hash ref if (objectHash in hashedNodeMap) { // if we found a duplicate hash we can assume the schema has already been processed to remove refs, so we can quit here and don't need to process it again or add a new entry // eslint-disable-next-line @typescript-eslint/no-explicit-any schema = objectHash; return; } replaceSchemaRefs({ schema, refUuidMap, uuidObjectHashMap, hashedNodeMap, schemaToUuidMap }); hashedNodeMap[objectHash] = schema; };