@scalar/api-reference
Version:
Generate beautiful API references from OpenAPI documents
34 lines (33 loc) • 1.1 kB
JavaScript
import { getResolvedRef as y } from "@scalar/workspace-store/helpers/get-resolved-ref";
import { isArraySchema as a } from "@scalar/workspace-store/schemas/v3.1/strict/type-guards";
import { getRefName as p } from "./get-ref-name.js";
const s = (t) => {
if (!t)
return null;
if ("$ref" in t) {
const e = p(t);
if (e)
return e;
}
const r = y(t);
return r.title ? r.title : r.name ? r.name : null;
}, o = (t, r) => `${t} ${r}${t === "array" ? "[]" : ""}`, N = (t, r = !1) => {
if (!("type" in t) || r)
return null;
const e = t.type, i = s(t);
if (i && t.title)
return e === "array" ? `array ${i}[]` : i;
if (a(t) && t.items) {
const n = y(t.items), f = n.title;
if (f)
return o(e, f);
const m = s(t.items);
return m && "type" in n && m !== n.type ? o(e, m) : "type" in n ? o(e, Array.isArray(n.type) ? n.type.join(" | ") : n.type) : o(e, "object");
}
return i && i !== e ? i.startsWith("Array of ") ? `array ${i.slice(9)}[]` : i : null;
};
export {
o as formatTypeWithModel,
N as getModelName,
s as getModelNameFromSchema
};