UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

193 lines (192 loc) 8.4 kB
import ScreenReader_default from "../../ScreenReader.vue.js"; import { isTypeObject } from "./helpers/is-type-object.js"; import { isEmptySchemaObject } from "./helpers/is-empty-schema-object.js"; import SchemaHeading_default from "./SchemaHeading.vue.js"; import SchemaProperty_default from "./SchemaProperty.vue.js"; import SchemaObjectProperties_default from "./SchemaObjectProperties.vue.js"; import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeClass, normalizeStyle, openBlock, toDisplayString, unref, vShow, withCtx, withDirectives } from "vue"; import { Disclosure, DisclosureButton, DisclosurePanel } from "@headlessui/vue"; import { ScalarIcon, ScalarMarkdown } from "@scalar/components"; //#region src/components/Content/Schema/Schema.vue?vue&type=script&setup=true&lang.ts var _hoisted_1 = { key: 0, class: "schema-card-description" }; var _hoisted_2 = { key: 1, class: "pt-2" }; var _hoisted_3 = { key: 0, class: "schema-properties" }; var Schema_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({ __name: "Schema", props: { schema: {}, level: { default: 0 }, name: {}, compact: { type: Boolean }, noncollapsible: { type: Boolean, default: false }, hideHeading: { type: Boolean }, additionalProperties: { type: Boolean }, hideModelNames: { type: Boolean, default: false }, discriminator: {}, breadcrumb: {}, eventBus: {}, options: {}, schemaContext: {}, compositionPath: {} }, setup(__props) { /** * Determines whether to show the collapse/expand toggle button. * We hide the toggle for non-collapsible schemas and root-level schemas. */ const shouldShowToggle = computed(() => { return !__props.noncollapsible && __props.level > 0; }); /** Gets the description to show for the schema */ const schemaDescription = computed(() => { if (__props.schema?.allOf && __props.schema.allOf.length > 0 && __props.name === "Request Body") return __props.schema.description || __props.schema.allOf[0]?.description || null; if (!__props.schema?.description || typeof __props.schema.description !== "string") return null; if (__props.schema.enum) return null; if (!("properties" in __props.schema) && !("patternProperties" in __props.schema) && !("additionalProperties" in __props.schema)) return null; return __props.schema.description; }); const handleClick = (e) => __props.noncollapsible && e.stopPropagation(); return (_ctx, _cache) => { return typeof __props.schema === "object" && Object.keys(__props.schema).length ? (openBlock(), createBlock(unref(Disclosure), { key: 0, defaultOpen: __props.noncollapsible }, { default: withCtx(({ open }) => [createElementVNode("div", { class: normalizeClass(["schema-card", [ `schema-card--level-${__props.level}`, { "schema-card--compact": __props.compact, "schema-card--open": open }, { "border-t": __props.additionalProperties && open } ]]) }, [ schemaDescription.value ? (openBlock(), createElementBlock("div", _hoisted_1, [createVNode(unref(ScalarMarkdown), { value: schemaDescription.value }, null, 8, ["value"])])) : createCommentVNode("", true), unref(isEmptySchemaObject)(__props.schema) ? (openBlock(), createElementBlock("div", _hoisted_2, " Empty object ")) : createCommentVNode("", true), createElementVNode("div", { class: normalizeClass(["schema-properties", { "schema-properties-open": open }]) }, [__props.additionalProperties ? withDirectives((openBlock(), createElementBlock("div", _hoisted_3, [createVNode(unref(DisclosureButton), { as: "button", class: "schema-card-title schema-card-title--compact", onClickCapture: handleClick }, { default: withCtx(() => [ createVNode(unref(ScalarIcon), { class: "schema-card-title-icon", icon: "Add", size: "sm" }), _cache[0] || (_cache[0] = createTextVNode(" Show additional properties ", -1)), __props.name ? (openBlock(), createBlock(ScreenReader_default, { key: 0 }, { default: withCtx(() => [createTextVNode("for " + toDisplayString(__props.name), 1)]), _: 1 })) : createCommentVNode("", true) ]), _: 1 })], 512)), [[vShow, !open]]) : shouldShowToggle.value ? withDirectives((openBlock(), createBlock(unref(DisclosureButton), { key: 1, as: __props.noncollapsible ? "div" : "button", class: normalizeClass(["schema-card-title", { "schema-card-title--compact": __props.compact }]), style: normalizeStyle({ top: `calc(var(--refs-viewport-offset) + calc(var(--schema-title-height) * ${__props.level}))` }), onClickCapture: handleClick }, { default: withCtx(() => [__props.compact ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [ createVNode(unref(ScalarIcon), { class: normalizeClass(["schema-card-title-icon", { "schema-card-title-icon--open": open }]), icon: "Add", size: "sm" }, null, 8, ["class"]), open ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [createTextVNode(" Hide " + toDisplayString(__props.schema?.title ?? "Child Attributes"), 1)], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createTextVNode(" Show " + toDisplayString(__props.schema?.title ?? "Child Attributes"), 1)], 64)), __props.name ? (openBlock(), createBlock(ScreenReader_default, { key: 2 }, { default: withCtx(() => [createTextVNode("for " + toDisplayString(__props.name), 1)]), _: 1 })) : createCommentVNode("", true) ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createVNode(unref(ScalarIcon), { class: normalizeClass(["schema-card-title-icon", { "schema-card-title-icon--open": open }]), icon: "Add", size: "sm" }, null, 8, ["class"]), createVNode(SchemaHeading_default, { name: __props.schema?.title ?? __props.name, value: __props.schema }, null, 8, ["name", "value"])], 64))]), _: 2 }, 1032, [ "as", "class", "style" ])), [[vShow, !__props.hideHeading && !(__props.noncollapsible && __props.compact)]]) : createCommentVNode("", true), !__props.additionalProperties || open ? (openBlock(), createBlock(unref(DisclosurePanel), { key: 2, as: "ul", static: !shouldShowToggle.value }, { default: withCtx(() => [unref(isTypeObject)(__props.schema) ? (openBlock(), createBlock(SchemaObjectProperties_default, { key: 0, breadcrumb: __props.breadcrumb, compact: __props.compact, compositionPath: __props.compositionPath, discriminator: __props.discriminator, eventBus: __props.eventBus, hideHeading: __props.hideHeading, hideModelNames: __props.hideModelNames, level: __props.level + 1, options: __props.options, schema: __props.schema, schemaContext: __props.schemaContext }, null, 8, [ "breadcrumb", "compact", "compositionPath", "discriminator", "eventBus", "hideHeading", "hideModelNames", "level", "options", "schema", "schemaContext" ])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [__props.schema ? (openBlock(), createBlock(SchemaProperty_default, { key: 0, breadcrumb: __props.breadcrumb, compact: __props.compact, compositionPath: __props.compositionPath, eventBus: __props.eventBus, hideHeading: __props.hideHeading, hideModelNames: __props.hideModelNames, level: __props.level, options: __props.options, schema: __props.schema, schemaContext: __props.schemaContext }, null, 8, [ "breadcrumb", "compact", "compositionPath", "eventBus", "hideHeading", "hideModelNames", "level", "options", "schema", "schemaContext" ])) : createCommentVNode("", true)], 64))]), _: 1 }, 8, ["static"])) : createCommentVNode("", true)], 2) ], 2)]), _: 1 }, 8, ["defaultOpen"])) : createCommentVNode("", true); }; } }); //#endregion export { Schema_vue_vue_type_script_setup_true_lang_default as default }; //# sourceMappingURL=Schema.vue.script.js.map