@scalar/api-client
Version:
the open source API testing client
50 lines (49 loc) • 1.84 kB
JavaScript
import { defineComponent as c, computed as a, createElementBlock as s, createBlock as m, createCommentVNode as d, openBlock as i, toDisplayString as f, unref as p } from "vue";
import { ScalarCodeBlock as v } from "@scalar/components";
import { isDefined as y } from "@scalar/oas-utils/helpers";
import { getHarRequest as g } from "./helpers/get-har-request.js";
import { getSnippet as x } from "./helpers/get-snippet.js";
const k = {
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 == 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(y) : [])
), n = a(() => {
const e = g({
operation: t.operation,
example: t.example,
server: t.server,
securitySchemes: t.securitySchemes,
environment: t.environment
}), [r, u] = x(t.target, t.client, e);
return { error: r, payload: u };
}), o = a(() => t.target === "shell" && t.client === "curl" ? "curl" : t.target ?? "plaintext");
return (e, r) => n.value.error ? (i(), s("div", k, f(n.value.error.message), 1)) : n.value.payload ? (i(), m(p(v), {
key: 1,
class: "w-full",
content: n.value.payload,
hideCredentials: l.value,
lang: o.value,
lineNumbers: ""
}, null, 8, ["content", "hideCredentials", "lang"])) : d("", !0);
}
});
export {
q as default
};