UNPKG

@scalar/api-client

Version:

the open source API testing client

37 lines (36 loc) 1.13 kB
import { getResolvedRefDeep as u } from "../../operation-code-sample/helpers/get-resolved-ref-deep.js"; const r = (t, n, s) => { if (!t && !n) return; const o = !!t && Object.keys(t).length > 0, e = s || Object.keys(t ?? {})[0] || "", i = u(t?.[e]); if (i !== void 0) return i; if ((!o || !s) && n !== void 0) return { value: u(n) }; }, l = (t, n, s) => { if ("content" in t) { const e = t.content?.[s ?? Object.keys(t.content)[0] ?? ""], i = r(e?.examples, e?.example, n); if (i !== void 0) return i; } if ("examples" in t || "example" in t) { const e = r(t.examples, t.example, n); if (e !== void 0) return e; } const o = u(t); if ("schema" in o && o.schema) { const e = o.schema; if ("default" in e && e.default !== void 0) return { value: e.default }; if ("enum" in e && e.enum?.[0] !== void 0) return { value: e.enum[0] }; if ("examples" in e && e.examples?.[0] !== void 0) return { value: e.examples[0] }; if ("example" in e && e.example !== void 0) return { value: e.example }; } }; export { l as getExample };