UNPKG

@mintlify/validation

Version:

Validates mint.json files

44 lines (43 loc) 1.88 kB
import hash from 'object-hash'; import { v4 as uuidv4 } from 'uuid'; import { mapHeader } from './mapHeader.js'; import { mapMedia } from './mapMedia.js'; export const mapResponse = ({ response, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }) => { // hash the raw object const objectHash = hash(response); // map uuid and hash to uuidObjectHashMap uuidObjectHashMap[uuid] = objectHash; // if ref, replace with uuid if ('$ref' in response && response.$ref) { const refId = response.$ref; const uuid = refUuidMap[refId] || uuidv4(); response.$ref = uuid; } // if not ref // if headers, convert headers to HeaderOrRef nodes if ('headers' in response && response.headers && typeof response.headers === 'object') { Object.entries(response.headers).forEach(([headerName, header]) => { const uuid = uuidv4(); mapHeader({ header, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid }); if (response.headers) { // eslint-disable-next-line @typescript-eslint/no-explicit-any response.headers[headerName] = uuid; } }); } // if content, convert content to Media nodes if ('content' in response && response.content && typeof response.content === 'object') { Object.entries(response.content).forEach(([contentType, content]) => { const uuid = uuidv4(); mapMedia({ content, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid }); if (response.content) { // eslint-disable-next-line @typescript-eslint/no-explicit-any response.content[contentType] = uuid; } }); } // if links, convert links to Link nodes // TODO: add support for links // add to hashedNodeMap hashedNodeMap[objectHash] = response; };