UNPKG

@scalar/api-client

Version:

the open source API testing client

53 lines (52 loc) 1.52 kB
import { isDefined as u } from "@scalar/oas-utils/helpers"; import { getResolvedRef as c } from "@scalar/workspace-store/helpers/get-resolved-ref"; import { authOptions as d } from "./auth-options.js"; const l = ({ name: o, type: n, value: i }) => ({ id: o, label: n === "openIdConnect" ? `${o} (coming soon)` : o, value: i }), m = (o) => l( Object.keys(o).reduce( (n, i, r) => (n.name += `${r > 0 ? " & " : ""}${i}`, n), { type: "complex", name: "", value: o } ) ), v = (o, n, i = !1) => { { const r = o.map((e) => { const t = Object.keys(e); if (t.length > 1) return m(e); if (t[0]) { const p = c(n[t[0]]); return p ? l({ name: t[0], type: p.type, value: e }) : void 0; } }).filter(u), s = Object.keys(n).filter((e) => !r.some((t) => t.id === e)).map((e) => { const t = c(n[e]); if (t) return l({ name: e, type: t.type, value: { [e]: [] } }); }).filter(u), a = [ { label: "Required authentication", options: r }, { label: "Available authentication", options: s } ]; return i ? r.length ? a : s : (a.push({ label: "Add new authentication", options: Object.entries(d).map(([e, t]) => ({ id: `@unique/${e}`, label: t.label, value: { [e]: [] }, payload: t.payload, // Disable deleting built-in options isDeletable: !1 })) }), a); } }; export { m as formatComplexScheme, l as formatScheme, v as getSecuritySchemeOptions };