UNPKG

fumadocs-openapi

Version:

Generate MDX docs for your OpenAPI spec

44 lines (42 loc) 1.23 kB
import { createProxy } from "./proxy.js"; import { processDocument } from "../utils/process-document.js"; //#region src/server/create.tsx function createOpenAPI(options = {}) { const { input = [], disableCache = false } = options; let schemas; async function getSchemas() { const out = {}; if (Array.isArray(input)) await Promise.all(input.map(async (item) => { out[item] = await processDocument(item); })); else await Promise.all(Object.entries(await input()).map(async ([k, v]) => { out[k] = await processDocument(v); })); return out; } return { options, createProxy, async getSchema(document) { const schemas$1 = await getSchemas(); if (document in schemas$1) return schemas$1[document]; console.warn(`[Fumadocs OpenAPI] the document "${document}" is not listed in the input array, this may not be expected.`); return processDocument(document); }, async getSchemas() { if (disableCache) return getSchemas(); return schemas ??= getSchemas(); } }; } function createCodeSample(options) { const { lang = "unknown", id = lang, ...rest } = options; return { id, lang, ...rest }; } //#endregion export { createCodeSample, createOpenAPI }; //# sourceMappingURL=create.js.map