@scalar/api-client
Version:
the open source API testing client
51 lines (50 loc) • 1.84 kB
JavaScript
import { defineComponent as c, computed as a, createElementBlock as s, createBlock as m, createCommentVNode as f, openBlock as o, toDisplayString as d, unref as p } from "vue";
import { ScalarCodeBlock as v } from "@scalar/components";
import { isDefined as y } from "@scalar/oas-utils/helpers";
import { encode as g } from "js-base64";
import { getHarRequest as x } from "./helpers/get-har-request.js";
import { getSnippet as k } from "./helpers/get-snippet.js";
const S = {
key: 0,
class: "text-c-3 flex min-h-16 items-center justify-center px-4 text-sm"
}, q = /* @__PURE__ */ c({
__name: "CodeSnippet",
props: {
target: {},
client: {},
operation: {},
server: {},
example: {},
securitySchemes: { default: () => [] },
environment: {}
},
setup(t) {
const l = a(
() => t.securitySchemes.flatMap((e) => e.type === "apiKey" ? e.value : e?.type === "http" ? [
e.token,
e.password,
g(`${e.username}:${e.password}`)
] : e.type === "oauth2" ? Object.values(e.flows).map((n) => n?.token).filter(y) : [])
), r = a(() => {
const e = x({
operation: t.operation,
example: t.example,
server: t.server,
securitySchemes: t.securitySchemes,
environment: t.environment
}), [n, u] = k(t.target, t.client, e);
return { error: n, payload: u };
}), i = a(() => t.target === "shell" && t.client === "curl" ? "curl" : t.target ?? "plaintext");
return (e, n) => r.value.error ? (o(), s("div", S, d(r.value.error.message), 1)) : r.value.payload ? (o(), m(p(v), {
key: 1,
class: "w-full",
content: r.value.payload,
hideCredentials: l.value,
lang: i.value,
lineNumbers: ""
}, null, 8, ["content", "hideCredentials", "lang"])) : f("", !0);
}
});
export {
q as default
};