UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

43 lines (42 loc) 1.31 kB
import { getResolvedRef as h } from "@scalar/workspace-store/helpers/get-resolved-ref"; import { compositions as d } from "./schema-composition.js"; function N(t) { if (!t || typeof t != "object") return t; const r = d.find((e) => e in t && e !== "not"); if (!r) return { ...t }; const i = t[r]; if (!Array.isArray(i)) return { ...t }; const { [r]: b, nullable: u, ...n } = t, m = Object.keys(n).length > 0, { filteredSchemas: o, hasNullSchema: a } = i.reduce( (e, l) => { const s = h(l); return "type" in s && s.type === "null" ? e.hasNullSchema = !0 : e.filteredSchemas.push(s), e; }, { filteredSchemas: [], hasNullSchema: !1 } ), c = a || u === !0; if (o.length === 1) { const e = { ...n, ...o[0] }; return c && (e.nullable = !0), e; } if ((r === "oneOf" || r === "anyOf") && (m || o.some((e) => e.allOf))) { const e = o.map((s) => { const f = h(s); if (f.allOf?.length === 1) { const { allOf: p, ...g } = f; return { ...n, ...g, ...h(p[0]) }; } return { ...n, ...f }; }), l = { [r]: e }; return c && (l.nullable = !0), l; } if (o.length !== i.length) { const e = { ...t, [r]: o }; return c && (e.nullable = !0), e; } return { ...t }; } export { N as optimizeValueForDisplay };