fumadocs-openapi
Version:
Generate MDX docs for your OpenAPI spec
49 lines (47 loc) • 1.25 kB
JavaScript
import { idToTitle } from "../id-to-title.js";
import Slugger from "github-slugger";
//#region src/utils/pages/to-static-data.ts
function toStaticData(page, dereferenced) {
const slugger = new Slugger();
const toc = [];
const structuredData = {
headings: [],
contents: []
};
function pathItem(item, defaultTitle) {
if (page.showTitle && item.operationId) {
const title = item.summary || (item.operationId ? idToTitle(item.operationId) : defaultTitle);
const id = slugger.slug(title);
toc.push({
depth: 2,
title,
url: `#${id}`
});
structuredData.headings.push({
content: title,
id
});
}
if (item.description) structuredData.contents.push({
content: item.description,
heading: structuredData.headings.at(-1)?.id
});
}
for (const item of page.operations ?? []) {
const operation = dereferenced.paths?.[item.path]?.[item.method];
if (!operation) continue;
pathItem(operation, item.path);
}
for (const item of page.webhooks ?? []) {
const webhook = dereferenced.webhooks?.[item.name]?.[item.method];
if (!webhook) continue;
pathItem(webhook, item.name);
}
return {
toc,
structuredData
};
}
//#endregion
export { toStaticData };
//# sourceMappingURL=to-static-data.js.map