@mintlify/common
Version:
Commonly shared code within Mintlify
33 lines (32 loc) • 1.6 kB
JavaScript
import { camelToSentenceCase } from '../camelToSentenceCase.js';
import { parseAsyncApiString } from './parseAsyncApiString.js';
export const getAsyncApiChannelMetadata = (asyncApiMetaField, asyncApiFiles) => {
const potentiallyParsedAsyncApiString = parseAsyncApiString(asyncApiMetaField);
if (potentiallyParsedAsyncApiString == undefined) {
return undefined;
}
const { channelId, filename } = potentiallyParsedAsyncApiString;
let asyncApiFile = undefined;
for (const file of asyncApiFiles) {
const asyncApiSpec = file.spec;
const hasAsyncApiChannel = channelId && asyncApiSpec.allChannels().has(channelId);
const filenameMatches = !filename || filename === file.filename || filename === file.originalFileLocation;
if (hasAsyncApiChannel && filenameMatches) {
asyncApiFile = file;
}
}
if (asyncApiFile == null) {
return undefined;
}
const channelInterface = channelId
? asyncApiFile.spec.channels().get(channelId)
: undefined;
const channelTitle = (channelInterface === null || channelInterface === void 0 ? void 0 : channelInterface.title()) || camelToSentenceCase(channelId);
const channelDescription = (channelInterface === null || channelInterface === void 0 ? void 0 : channelInterface.description()) || (channelInterface === null || channelInterface === void 0 ? void 0 : channelInterface.summary()) || '';
return {
channelId,
filename: asyncApiFile.filename,
title: channelTitle,
description: channelDescription,
};
};