UNPKG

@scalar/api-client

Version:

the open source API testing client

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