@mintlify/validation
Version:
Validates mint.json files
59 lines (58 loc) • 2.12 kB
JavaScript
import hash from 'object-hash';
import { v4 as uuidv4 } from 'uuid';
import { httpMethods } from '../types/endpoint.js';
import { mapOperation } from './mapOperation.js';
import { mapParameter } from './mapParameter.js';
export const mapPath = ({ pathItem, refUuidMap, uuidObjectHashMap, hashedNodeMap, uuid, path, isWebhook, }) => {
var _a;
const objectHash = hash(pathItem);
uuidObjectHashMap[uuid] = objectHash;
if ('$ref' in pathItem && pathItem.$ref) {
const refId = pathItem.$ref;
const refUuid = refUuidMap[refId] || uuidv4();
pathItem.$ref = refUuid;
}
// process path - Parameters
if ('parameters' in pathItem) {
const parameterUuids = [];
(_a = pathItem.parameters) === null || _a === void 0 ? void 0 : _a.forEach((parameter) => {
const parameterUuid = uuidv4();
mapParameter({
parameter,
refUuidMap,
uuidObjectHashMap,
hashedNodeMap,
uuid: parameterUuid,
});
parameterUuids.push(parameterUuid);
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
pathItem.parameters = parameterUuids;
}
// process operations per http method
if (!('$ref' in pathItem)) {
httpMethods.forEach((method) => {
if (!(method in pathItem))
return;
const operation = pathItem[method];
if (!operation)
return;
const operationUuid = uuidv4();
mapOperation({
operation,
refUuidMap,
uuidObjectHashMap,
hashedNodeMap,
uuid: operationUuid,
method,
isWebhook,
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
pathItem[method] = operationUuid;
refUuidMap[`${path}/${isWebhook ? 'webhook' : method}`] = uuid;
});
}
pathItem.path = path;
// store path object
hashedNodeMap[objectHash] = pathItem;
};