@mintlify/validation
Version:
Validates mint.json files
37 lines (36 loc) • 1.65 kB
JavaScript
import hash from 'object-hash';
import { v4 as uuidv4 } from 'uuid';
import { mapExample } from './mapExample.js';
import { mapSchema } from './mapSchema.js';
export const mapMedia = ({ content, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, }) => {
const objectHash = hash(content);
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
content = objectHash;
return;
}
// if schema in media, create SchemaOrRef node
if ('schema' in content && content.schema && typeof content.schema === 'object') {
const uuid = uuidv4();
mapSchema({ schema: content.schema, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
content.schema = uuid;
}
// if examples in media, create ExampleOrRef node
if ('examples' in content && content.examples && typeof content.examples === 'object') {
Object.entries(content.examples).forEach(([exampleName, example]) => {
const uuid = uuidv4();
mapExample({ example, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid });
if (content.examples) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
content.examples[exampleName] = uuid;
}
});
}
// if encoding in media, create Encoding node
// TODO: add support for encoding
// add to hashedNodeMap
hashedNodeMap[objectHash] = content;
};