UNPKG

@scalar/api-client

Version:

the open source API testing client

22 lines (21 loc) 905 B
import { getResolvedRef as d } from "@scalar/workspace-store/helpers/get-resolved-ref"; import { getResolvedRefDeep as o } from "../../operation-code-sample/helpers/get-resolved-ref-deep.js"; const m = (e, s, l) => { if ("content" in e) { const t = e.content?.[l ?? Object.keys(e.content)[0] ?? ""], f = t?.examples ?? {}, c = s ?? Object.keys(f)[0] ?? "", i = o(f[c]); return typeof i < "u" ? i : typeof s > "u" && t?.example ? { value: o(t.example) } : void 0; } if ("examples" in e || "example" in e) { const t = d(e.examples) ?? {}, f = s ?? Object.keys(t)[0] ?? "", c = o(t?.[f]); if (typeof c < "u") return c; if (typeof s > "u" && e.example) return { value: o(e.example) }; } const n = o(e); if ("schema" in n && n.schema && "default" in n.schema && typeof n.schema.default < "u") return { value: n.schema.default }; }; export { m as getExample };