UNPKG

@scalar/api-client

Version:

the open source API testing client

41 lines (40 loc) 1.13 kB
import { operationToHar as y } from "./operation-to-har/operation-to-har.js"; import { getSnippet as S } from "../../../../views/Components/CodeSnippet/helpers/get-snippet.js"; import { generateCustomId as h } from "./generate-client-options.js"; const q = ({ clientId: e, customCodeSamples: o, includeDefaultHeaders: n = !1, operation: p, method: s, path: a, example: i, contentType: g, server: m, securitySchemes: u, globalCookies: c }) => { try { if (!e) return ""; if (e.startsWith("custom")) return o.find((l) => h(l) === e)?.source ?? "Custom example not found"; const r = y({ operation: p, contentType: g, method: s, path: a, server: m, securitySchemes: u, example: i, globalCookies: c, includeDefaultHeaders: n }), [f, d] = e.split("/"), [t, C] = S(f, d, r); return t ? (console.error("[generateCodeSnippet]", t), t.message ?? "Error generating code snippet") : C; } catch (r) { return console.error("[generateCodeSnippet]", r), "Error generating code snippet"; } }; export { q as generateCodeSnippet };