@scalar/api-reference
Version:
Generate beautiful API references from OpenAPI documents
194 lines (193 loc) • 9.25 kB
JavaScript
import { defineComponent, computed, createBlock, createCommentVNode, openBlock, unref, withCtx, createElementVNode, normalizeClass, createElementBlock, createVNode, withDirectives, createTextVNode, toDisplayString, vShow, normalizeStyle, Fragment } from "vue";
import { Disclosure, DisclosureButton, DisclosurePanel } from "@headlessui/vue";
import { ScalarMarkdown, ScalarIcon } from "@scalar/components";
import ScreenReader from "../../ScreenReader.vue.js";
import { isEmptySchemaObject } from "./helpers/is-empty-schema-object.js";
import { isTypeObject } from "./helpers/is-type-object.js";
import SchemaHeading from "./SchemaHeading.vue.js";
import _sfc_main$1 from "./SchemaObjectProperties.vue.js";
import SchemaProperty from "./SchemaProperty.vue.js";
const _hoisted_1 = {
key: 0,
class: "schema-card-description"
};
const _hoisted_2 = {
key: 1,
class: "pt-2"
};
const _hoisted_3 = {
key: 0,
class: "schema-properties"
};
const _sfc_main = /* @__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: {}
},
setup(__props) {
const shouldShowToggle = computed(() => {
return !__props.noncollapsible && __props.level > 0;
});
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.oneOf || __props.schema.anyOf) {
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, { 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, { 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, {
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(_sfc_main$1, {
key: 0,
breadcrumb: __props.breadcrumb,
compact: __props.compact,
discriminator: __props.discriminator,
eventBus: __props.eventBus,
hideHeading: __props.hideHeading,
hideModelNames: __props.hideModelNames,
level: __props.level + 1,
options: __props.options,
schema: __props.schema
}, null, 8, ["breadcrumb", "compact", "discriminator", "eventBus", "hideHeading", "hideModelNames", "level", "options", "schema"])) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
__props.schema ? (openBlock(), createBlock(SchemaProperty, {
key: 0,
breadcrumb: __props.breadcrumb,
compact: __props.compact,
eventBus: __props.eventBus,
hideHeading: __props.hideHeading,
hideModelNames: __props.hideModelNames,
level: __props.level,
options: __props.options,
schema: __props.schema
}, null, 8, ["breadcrumb", "compact", "eventBus", "hideHeading", "hideModelNames", "level", "options", "schema"])) : createCommentVNode("", true)
], 64))
]),
_: 1
}, 8, ["static"])) : createCommentVNode("", true)
], 2)
], 2)
]),
_: 1
}, 8, ["defaultOpen"])) : createCommentVNode("", true);
};
}
});
export {
_sfc_main as default
};