@scalar/api-client
Version:
the open source API testing client
53 lines (52 loc) • 1.2 kB
JavaScript
import { isObject as u } from "@scalar/helpers/object/is-object";
import { parseJson as c, parseYaml as d } from "@scalar/json-magic/bundle/plugins/browser";
import { getOpenApiFromPostman as m } from "./get-openapi-from-postman.js";
import { isPostmanCollection as f } from "./is-postman-collection.js";
const p = () => ({
type: "loader",
validate: f,
exec: (e) => {
try {
const r = m(e);
return r ? Promise.resolve({
ok: !0,
data: r,
raw: e
}) : Promise.resolve({
ok: !1
});
} catch {
return Promise.resolve({
ok: !1
});
}
}
}), h = async (e, r, o, l) => {
const { source: t, type: n } = r;
if (!t)
return !1;
if (n === "url")
return await e.addDocument({
name: o,
url: t,
meta: {
"x-scalar-watch-mode": l
}
});
if (n === "file")
return await e.addDocument({
name: o,
path: t
});
const s = [p(), c(), d()].find((i) => i.validate(t));
if (!s)
return !1;
const a = await s.exec(t);
return !(!a.ok || !u(a.data) || !await e.addDocument({
name: o,
document: a.data
}));
};
export {
h as loadDocumentFromSource
};