UNPKG

@scalar/api-client

Version:

the open source API testing client

53 lines (52 loc) 1.64 kB
import { isDefined as l } from "@scalar/oas-utils/helpers"; import { ADD_AUTH_OPTIONS as p } from "../consts/new-auth-options.js"; const c = (e) => ({ id: e.uid, label: e.type === "openIdConnect" ? `${e.nameKey} (coming soon)` : e.nameKey }), y = (e, n) => c( e.reduce( (i, u, a) => { const s = n[u]; return s && (i.nameKey += `${a > 0 ? " & " : ""}${s.nameKey}`, i.uid = `${i.uid}${a > 0 ? "," : ""}${s.uid}`), i; }, { type: "complex", nameKey: "", uid: "" } ) ), O = (e, n) => JSON.stringify(e?.security) === "[{}]" && n?.security?.length ? !!n?.security.find((u) => JSON.stringify(u) === "{}") ? n.security : [...n.security, {}] : e?.security ?? n?.security ?? [], b = (e, n, i, u = !1) => { { const a = n.reduce( (r, t) => { const o = i[t]; return o && (r[o.nameKey] = o), r; }, {} ), s = e.flatMap((r) => { const t = Object.keys(r); if (t.length > 1) { const o = t.map((d) => a[d]?.uid).filter(l); return y(o, i); } if (t[0]) { const o = a[t[0]]; if (o) return c(o); } return []; }), f = n.filter((r) => !s.some((t) => t.id === r)).map((r) => { const t = i[r]; return t ? c(t) : null; }).filter(l), m = [ { label: "Required authentication", options: s }, { label: "Available authentication", options: f } ]; return u ? s.length ? m : f : (m.push({ label: "Add new authentication", options: p }), m); } }; export { y as formatComplexScheme, c as formatScheme, b as getSchemeOptions, O as getSecurityRequirements };