@mintlify/validation
Version:
Validates mint.json files
21 lines (20 loc) • 751 B
JavaScript
import hash from 'object-hash';
import { v4 as uuidv4 } from 'uuid';
export const mapExample = ({ example, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }) => {
const objectHash = hash(example);
uuidObjectHashMap[uuid] = objectHash;
// if we've seen this exact object before, skip processing
if (objectHash in hashedNodeMap) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
example = objectHash;
return;
}
// if ref, replace with uuid
if ('$ref' in example && example.$ref) {
const refId = example.$ref;
const refUuid = refUuidMap[refId] || uuidv4();
example.$ref = refUuid;
}
// add to hashedNodeMap
hashedNodeMap[objectHash] = example;
};