@mintlify/prebuild
Version:
Helpful functions for Mintlify's prebuild step
31 lines (30 loc) • 1.04 kB
JavaScript
import { getAsyncApiDocumentFromUrl } from '@mintlify/common';
export const getAsyncApiFilesFromConfig = async (config) => {
const asyncApiConfig = config.api?.asyncapi;
const asyncApiFiles = [];
async function addAsyncApiFileFromUrl(url) {
try {
const document = await getAsyncApiDocumentFromUrl(url);
asyncApiFiles.push({
filename: url,
spec: document,
originalFileLocation: url,
});
}
catch (err) {
console.error(err);
throw err;
}
}
if (asyncApiConfig) {
if (typeof asyncApiConfig === 'string' && asyncApiConfig.startsWith('https://')) {
await addAsyncApiFileFromUrl(asyncApiConfig);
}
else if (typeof asyncApiConfig === 'object' &&
'source' in asyncApiConfig &&
asyncApiConfig.source.startsWith('https')) {
await addAsyncApiFileFromUrl(asyncApiConfig.source);
}
}
return asyncApiFiles;
};