UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

112 lines (111 loc) 2.41 kB
import { getResolvedRef as s } from "@scalar/workspace-store/helpers/get-resolved-ref"; import { extractRequestBody as h, createParameterMap as a } from "../../../libs/openapi.js"; function f(o, i) { const t = []; function e(p) { p.forEach((d) => { c(d, t, i), "children" in d && d.children && e(d.children); }); } return e(o), t; } function c(o, i, t) { if (o.type === "operation") { const e = s(t?.paths?.[o.path]?.[o.method]) ?? {}, p = h(e) || a(e), d = typeof p != "boolean" ? p : null; i.push({ type: "operation", title: o.title, href: `#${o.id}`, id: e.operationId, description: e.description || "", method: o.method, path: o.path, body: d || "", entry: o }); return; } if (o.type === "webhook") { const e = s(t?.webhooks?.[o.name]?.[o.method]) ?? {}; i.push({ type: "webhook", title: o.title, href: `#${o.id}`, description: "Webhook", method: o.method, body: e.description || "", entry: o }); return; } if (o.type === "model") { const p = s(t?.components?.schemas?.[o.name])?.description ?? ""; i.push({ type: "model", title: o.title, href: `#${o.id}`, description: "Model", body: p, entry: o }); return; } if (o.title === "Models") { i.push({ type: "heading", title: "Models", href: `#${o.id}`, description: "Heading", body: "", entry: o }); return; } if (o.type === "tag" && o.isWebhooks === !0) { i.push({ type: "heading", title: "Webhooks", href: `#${o.id}`, description: "Heading", body: "", entry: o }); return; } if (o.type === "tag" && o.isGroup === !1) { i.push({ title: o.title, href: `#${o.id}`, description: o.description || "", type: "tag", body: "", entry: o }); return; } if (o.type === "tag" && o.isGroup === !0) { i.push({ title: o.title, href: `#${o.id}`, description: "Tag Group", type: "tag", body: "", entry: o }); return; } if (o.title) { i.push({ type: "heading", title: o.title ?? "", description: "Description", href: `#${o.id}`, body: "", entry: o }); return; } } export { f as createSearchIndex };