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