UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

37 lines (36 loc) 1.06 kB
import { getResolvedRef as y } from "@scalar/workspace-store/helpers/get-resolved-ref"; import { isTypeObject as m } from "./is-type-object.js"; const q = (r, o) => r.reduce((i, s) => { const n = o?.[s]; return n && (i[s] = n), i; }, {}), R = (r, o, { hideReadOnly: i = !1, hideWriteOnly: s = !1, orderSchemaPropertiesBy: n = "alpha", orderRequiredPropertiesFirst: c = !0 } = {}) => { if (!m(r) || !r.properties) return []; const d = Object.keys(r.properties), p = new Set(r.required || []); return d.sort((t, e) => { const u = t === o?.propertyName, f = e === o?.propertyName, l = p.has(t), a = p.has(e); if (u && !f) return -1; if (!u && f) return 1; if (c) { if (l && !a) return -1; if (!l && a) return 1; } return n === "alpha" ? t.localeCompare(e) : 0; }).filter((t) => { const e = r.properties && y(r.properties[t]); return !(i && e?.readOnly === !0 || s && e?.writeOnly === !0); }); }; export { q as reduceNamesToObject, R as sortPropertyNames };