UNPKG

@scalar/api-client

Version:

the open source API testing client

57 lines (56 loc) 1.61 kB
import { fetchDocument as y, createHash as R } from "@scalar/oas-utils/helpers"; import { importSpecToWorkspace as S } from "@scalar/oas-utils/transforms"; import { toRaw as g } from "vue"; import { normalizeError as w } from "../libs/errors.js"; const F = {}; function O({ requestMutators: s, collectionMutators: l, serverMutators: m, tagMutators: p, securitySchemeMutators: d, requestExampleMutators: f, workspaceMutators: u, workspaces: h }) { const n = async (t, a, e = {}) => { var i; const c = g(t), r = await S(c, e); if (r.error) { console.group("IMPORT ERRORS"), r.importWarnings.forEach((o) => console.warn(o)), console.groupEnd(); return; } return e.documentUrl && typeof c == "string" && (F[e.documentUrl] = { hash: R(c), schema: r.schema }), r.examples.forEach((o) => f.add(o)), r.requests.forEach((o) => s.add(o)), r.tags.forEach((o) => p.add(o)), r.servers.forEach((o) => m.add(o)), r.securitySchemes.forEach((o) => d.add(o)), l.add(r.collection), u.edit(a, "collections", [ ...((i = h[a]) == null ? void 0 : i.collections) ?? [], r.collection.uid ]), r; }; async function E(t, a, { proxyUrl: e, ...c } = {}) { try { const r = await y(t, e); return [ null, await n(r, a, { documentUrl: t, ...c }) ]; } catch (r) { return console.error("Failed to fetch spec from URL:", r), [w(r), null]; } } return { importSpecFile: n, importSpecFromUrl: E }; } export { O as importSpecFileFactory, F as specDictionary };