UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

161 lines (160 loc) 6.75 kB
import { defineComponent as H, computed as k, createBlock as s, createCommentVNode as t, openBlock as i, unref as l, withCtx as r, createElementVNode as g, normalizeClass as m, createElementBlock as c, createVNode as n, withDirectives as S, createTextVNode as d, toDisplayString as u, vShow as C, normalizeStyle as O, Fragment as h } from "vue"; import { Disclosure as P, DisclosureButton as N, DisclosurePanel as w } from "@headlessui/vue"; import { ScalarMarkdown as M, ScalarIcon as p } from "@scalar/components"; import B from "../../ScreenReader.vue.js"; import { isTypeObject as D } from "./helpers/is-type-object.js"; import z from "./SchemaHeading.vue.js"; import A from "./SchemaObjectProperties.vue.js"; import V from "./SchemaProperty.vue.js"; const j = { key: 0, class: "schema-card-description" }, T = { key: 0, class: "schema-properties" }, K = /* @__PURE__ */ H({ __name: "Schema", props: { schema: {}, level: { default: 0 }, name: {}, compact: { type: Boolean }, noncollapsible: { type: Boolean, default: !1 }, hideHeading: { type: Boolean }, additionalProperties: { type: Boolean }, hideModelNames: { type: Boolean, default: !1 }, discriminator: {}, breadcrumb: {}, options: {} }, setup(a) { const f = k(() => !a.noncollapsible && a.level > 0), y = k(() => a.schema?.allOf && a.schema.allOf.length > 0 && a.name === "Request Body" ? a.schema.description || a.schema.allOf[0].description : !a.schema?.description || typeof a.schema.description != "string" || a.schema.oneOf || a.schema.anyOf || a.schema.enum || !("properties" in a.schema) && !("patternProperties" in a.schema) && !("additionalProperties" in a.schema) ? null : a.schema.description), v = (e) => a.noncollapsible && e.stopPropagation(); return (e, b) => typeof e.schema == "object" && Object.keys(e.schema).length ? (i(), s(l(P), { key: 0, defaultOpen: e.noncollapsible }, { default: r(({ open: o }) => [ g("div", { class: m(["schema-card", [ `schema-card--level-${e.level}`, { "schema-card--compact": e.compact, "schema-card--open": o }, { "border-t": e.additionalProperties && o } ]]) }, [ y.value ? (i(), c("div", j, [ n(l(M), { value: y.value }, null, 8, ["value"]) ])) : t("", !0), g("div", { class: m(["schema-properties", { "schema-properties-open": o }]) }, [ e.additionalProperties ? S((i(), c("div", T, [ n(l(N), { as: "button", class: "schema-card-title schema-card-title--compact", onClickCapture: v }, { default: r(() => [ n(l(p), { class: "schema-card-title-icon", icon: "Add", size: "sm" }), b[0] || (b[0] = d(" Show additional properties ")), e.name ? (i(), s(B, { key: 0 }, { default: r(() => [ d("for " + u(e.name), 1) ]), _: 1 })) : t("", !0) ]), _: 1, __: [0] }) ], 512)), [ [C, !o] ]) : f.value ? S((i(), s(l(N), { key: 1, as: e.noncollapsible ? "div" : "button", class: m(["schema-card-title", { "schema-card-title--compact": e.compact }]), style: O({ top: `calc(var(--refs-viewport-offset) + calc(var(--schema-title-height) * ${e.level}))` }), onClickCapture: v }, { default: r(() => [ e.compact ? (i(), c(h, { key: 0 }, [ n(l(p), { class: m(["schema-card-title-icon", { "schema-card-title-icon--open": o }]), icon: "Add", size: "sm" }, null, 8, ["class"]), o ? (i(), c(h, { key: 0 }, [ d(" Hide " + u(e.schema?.title ?? "Child Attributes"), 1) ], 64)) : (i(), c(h, { key: 1 }, [ d(" Show " + u(e.schema?.title ?? "Child Attributes"), 1) ], 64)), e.name ? (i(), s(B, { key: 2 }, { default: r(() => [ d("for " + u(e.name), 1) ]), _: 1 })) : t("", !0) ], 64)) : (i(), c(h, { key: 1 }, [ n(l(p), { class: m(["schema-card-title-icon", { "schema-card-title-icon--open": o }]), icon: "Add", size: "sm" }, null, 8, ["class"]), n(z, { name: e.schema?.title ?? e.name, value: e.schema }, null, 8, ["name", "value"]) ], 64)) ]), _: 2 }, 1032, ["as", "class", "style"])), [ [C, !e.hideHeading && !(e.noncollapsible && e.compact)] ]) : t("", !0), !e.additionalProperties || o ? (i(), s(l(w), { key: 2, as: "ul", static: !f.value }, { default: r(() => [ l(D)(e.schema) ? (i(), s(A, { key: 0, breadcrumb: e.breadcrumb, compact: e.compact, discriminator: e.discriminator, hideHeading: e.hideHeading, hideModelNames: e.hideModelNames, level: e.level + 1, options: e.options, schema: e.schema }, null, 8, ["breadcrumb", "compact", "discriminator", "hideHeading", "hideModelNames", "level", "options", "schema"])) : (i(), c(h, { key: 1 }, [ e.schema ? (i(), s(V, { key: 0, breadcrumb: e.breadcrumb, compact: e.compact, hideHeading: e.hideHeading, hideModelNames: e.hideModelNames, level: e.level, options: e.options, schema: e.schema }, null, 8, ["breadcrumb", "compact", "hideHeading", "hideModelNames", "level", "options", "schema"])) : t("", !0) ], 64)) ]), _: 1 }, 8, ["static"])) : t("", !0) ], 2) ], 2) ]), _: 1 }, 8, ["defaultOpen"])) : t("", !0); } }); export { K as default };