UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

92 lines (91 loc) 3.59 kB
import { defineComponent as g, computed as n, ref as y, createElementBlock as s, openBlock as i, createBlock as C, unref as m, Fragment as S, createVNode as c, createElementVNode as r, withCtx as H, createCommentVNode as k, toDisplayString as u, normalizeClass as V } from "vue"; import { ScalarListbox as w } from "@scalar/components"; import { isDefined as B } from "@scalar/helpers/array/is-defined"; import { ScalarIconCaretDown as N } from "@scalar/icons"; import { getResolvedRef as O } from "@scalar/workspace-store/helpers/get-resolved-ref"; import { getSchemaType as z } from "./helpers/get-schema-type.js"; import { mergeAllOfSchemas as D } from "./helpers/merge-all-of-schemas.js"; import b from "./Schema.vue.js"; const U = { class: "property-rule" }, A = { class: "composition-selector bg-b-1.5 hover:bg-b-2 flex w-full cursor-pointer items-center gap-1 rounded-t-lg border border-b-0 px-2 py-1.25 pr-3 text-left", type: "button" }, E = { class: "text-c-2" }, L = { key: 0, class: "text-red" }, R = { class: "composition-panel" }, J = /* @__PURE__ */ g({ __name: "SchemaComposition", props: { composition: {}, discriminator: {}, name: {}, schema: {}, level: {}, compact: { type: Boolean, default: !1 }, hideHeading: { type: Boolean, default: !1 }, breadcrumb: {}, options: {} }, setup(h) { const a = h, p = n( () => [a.schema[a.composition]].flat().map((e) => ({ value: O(e), original: e })).filter((e) => B(e.value)) ), d = n( () => p.value.map((e, o) => ({ id: String(o), label: z(e.original) || "Schema" })) ), t = y(d.value[0]), f = (e) => e.replace(/([A-Z])/g, " $1").replace(/^./, (o) => o.toUpperCase()).toLowerCase().replace(/^(\w)/, (o) => o.toUpperCase()), l = n( () => p.value[Number(t.value.id)].value ); return (e, o) => (i(), s("div", U, [ a.composition === "allOf" ? (i(), C(b, { key: 0, breadcrumb: e.breadcrumb, compact: e.compact, discriminator: e.discriminator, hideHeading: e.hideHeading, level: e.level, name: e.name, noncollapsible: !0, options: e.options, schema: m(D)(e.schema) }, null, 8, ["breadcrumb", "compact", "discriminator", "hideHeading", "level", "name", "options", "schema"])) : (i(), s(S, { key: 1 }, [ c(m(w), { modelValue: t.value, "onUpdate:modelValue": o[0] || (o[0] = (v) => t.value = v), options: d.value, resize: "" }, { default: H(() => [ r("button", A, [ r("span", E, u(f(a.composition)), 1), r("span", { class: V(["composition-selector-label text-c-1", { "line-through": l.value?.deprecated }]) }, u(t.value?.label || "Schema"), 3), l.value?.deprecated ? (i(), s("div", L, " deprecated ")) : k("", !0), c(m(N)) ]) ]), _: 1 }, 8, ["modelValue", "options"]), r("div", R, [ c(b, { breadcrumb: e.breadcrumb, compact: e.compact, discriminator: e.discriminator, hideHeading: e.hideHeading, level: e.level + 1, name: e.name, noncollapsible: !0, options: e.options, schema: l.value }, null, 8, ["breadcrumb", "compact", "discriminator", "hideHeading", "level", "name", "options", "schema"]) ]) ], 64)) ])); } }); export { J as default };