UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

251 lines (250 loc) 13.1 kB
import { defineComponent, computed, useId, createBlock, openBlock, unref, withCtx, createVNode, createElementVNode, createCommentVNode, createTextVNode, toDisplayString, normalizeClass, createSlots } from "vue"; import { OperationCodeSample } from "@scalar/api-client/v2/blocks/operation-code-sample"; import { ScalarMarkdown, ScalarErrorBoundary } from "@scalar/components"; import { ScalarIconWebhooksLogo } from "@scalar/icons"; import { getOperationStability, getOperationStabilityColor, isOperationDeprecated } from "@scalar/oas-utils/helpers"; import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref"; import OperationPath from "../../../components/OperationPath.vue.js"; import _sfc_main$6 from "../components/callbacks/Callbacks.vue.js"; import _sfc_main$4 from "../components/OperationParameters.vue.js"; import _sfc_main$5 from "../components/OperationResponses.vue.js"; import _sfc_main$3 from "../../specification-extension/SpecificationExtension.vue2.js"; import { getXKeysFromObject } from "../../specification-extension/helpers.js"; import Section from "../../../components/Section/Section.vue.js"; import SectionContent from "../../../components/Section/SectionContent.vue.js"; import Badge from "../../../components/Badge/Badge.vue.js"; import _sfc_main$1 from "../../x-badges/XBadges.vue.js"; import SectionHeader from "../../../components/Section/SectionHeader.vue.js"; import _sfc_main$2 from "../../../components/Anchor/Anchor.vue.js"; import SectionHeaderTag from "../../../components/Section/SectionHeaderTag.vue.js"; import SectionColumns from "../../../components/Section/SectionColumns.vue.js"; import SectionColumn from "../../../components/Section/SectionColumn.vue.js"; import LinkList from "../../../components/LinkList/LinkList.vue.js"; import _sfc_main$7 from "../../external-docs/ExternalDocs.vue.js"; import TestRequestButton from "../../test-request-button/TestRequestButton.vue.js"; import ExampleResponses from "../../example-responses/ExampleResponses.vue.js"; const _hoisted_1 = { class: "flex flex-row justify-between gap-1" }; const _hoisted_2 = { class: "flex gap-1" }; const _hoisted_3 = { class: "flex gap-1" }; const _hoisted_4 = { class: "operation-details" }; const _hoisted_5 = { class: "examples" }; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "ModernLayout", props: { id: {}, method: {}, options: {}, path: {}, clientOptions: {}, isWebhook: { type: Boolean }, selectedClient: {}, eventBus: {}, operation: {}, selectedServer: {}, selectedSecuritySchemes: {} }, setup(__props) { const operationTitle = computed(() => __props.operation.summary || __props.path || ""); const labelId = useId(); const operationExtensions = computed(() => getXKeysFromObject(__props.operation)); return (_ctx, _cache) => { return openBlock(), createBlock(unref(Section), { id: __props.id, "aria-labelledby": unref(labelId), label: operationTitle.value, tabindex: "-1", onIntersecting: _cache[1] || (_cache[1] = () => __props.eventBus?.emit("intersecting:nav-item", { id: __props.id })) }, { default: withCtx(() => [ createVNode(unref(SectionContent), null, { default: withCtx(() => [ createElementVNode("div", _hoisted_1, [ createElementVNode("div", _hoisted_2, [ __props.options?.showOperationId && __props.operation.operationId ? (openBlock(), createBlock(unref(Badge), { key: 0 }, { default: withCtx(() => [ createTextVNode(toDisplayString(__props.operation.operationId), 1) ]), _: 1 })) : createCommentVNode("", true), unref(getOperationStability)(__props.operation) ? (openBlock(), createBlock(unref(Badge), { key: 1, class: normalizeClass(["capitalize", unref(getOperationStabilityColor)(__props.operation)]) }, { default: withCtx(() => [ createTextVNode(toDisplayString(unref(getOperationStability)(__props.operation)), 1) ]), _: 1 }, 8, ["class"])) : createCommentVNode("", true), __props.isWebhook ? (openBlock(), createBlock(unref(Badge), { key: 2, class: "font-code text-green flex w-fit items-center justify-center gap-1" }, { default: withCtx(() => [ createVNode(unref(ScalarIconWebhooksLogo), { weight: "bold" }), _cache[2] || (_cache[2] = createTextVNode("Webhook ", -1)) ]), _: 1 })) : createCommentVNode("", true), createVNode(unref(_sfc_main$1), { badges: __props.operation["x-badges"], position: "before" }, null, 8, ["badges"]) ]), createElementVNode("div", _hoisted_3, [ createVNode(unref(_sfc_main$1), { badges: __props.operation["x-badges"], position: "after" }, null, 8, ["badges"]) ]) ]), createElementVNode("div", { class: normalizeClass(unref(isOperationDeprecated)(__props.operation) ? "deprecated" : "") }, [ createVNode(unref(SectionHeader), null, { default: withCtx(() => [ createVNode(unref(_sfc_main$2), { onCopyAnchorUrl: _cache[0] || (_cache[0] = () => __props.eventBus?.emit("copy-url:nav-item", { id: __props.id })) }, { default: withCtx(() => [ createVNode(unref(SectionHeaderTag), { id: unref(labelId), level: 3 }, { default: withCtx(() => [ createTextVNode(toDisplayString(operationTitle.value), 1) ]), _: 1 }, 8, ["id"]) ]), _: 1 }) ]), _: 1 }) ], 2), createVNode(unref(SectionColumns), null, { default: withCtx(() => [ createVNode(unref(SectionColumn), null, { default: withCtx(() => [ createElementVNode("div", _hoisted_4, [ createVNode(_sfc_main$3, { value: operationExtensions.value }, null, 8, ["value"]), createVNode(unref(ScalarMarkdown), { anchorPrefix: __props.id, "aria-label": "Operation Description", role: "group", transformType: "heading", value: __props.operation.description, withAnchors: "", withImages: "" }, null, 8, ["anchorPrefix", "value"]), createVNode(_sfc_main$4, { breadcrumb: [__props.id], eventBus: __props.eventBus, options: __props.options, parameters: __props.operation.parameters, requestBody: unref(getResolvedRef)(__props.operation.requestBody) }, null, 8, ["breadcrumb", "eventBus", "options", "parameters", "requestBody"]), createVNode(_sfc_main$5, { breadcrumb: [__props.id], collapsableItems: !__props.options.expandAllResponses, eventBus: __props.eventBus, options: __props.options, responses: __props.operation.responses }, null, 8, ["breadcrumb", "collapsableItems", "eventBus", "options", "responses"]), createVNode(unref(ScalarErrorBoundary), null, { default: withCtx(() => [ __props.operation.callbacks ? (openBlock(), createBlock(_sfc_main$6, { key: 0, callbacks: __props.operation.callbacks, class: "mt-6", eventBus: __props.eventBus, options: __props.options, path: __props.path }, null, 8, ["callbacks", "eventBus", "options", "path"])) : createCommentVNode("", true) ]), _: 1 }) ]) ]), _: 1 }), createVNode(unref(SectionColumn), null, { default: withCtx(() => [ createElementVNode("div", _hoisted_5, [ __props.operation.externalDocs ? (openBlock(), createBlock(unref(LinkList), { key: 0 }, { default: withCtx(() => [ createVNode(unref(_sfc_main$7), { value: __props.operation.externalDocs }, null, 8, ["value"]) ]), _: 1 })) : createCommentVNode("", true), createVNode(unref(ScalarErrorBoundary), null, { default: withCtx(() => [ createVNode(unref(OperationCodeSample), { clientOptions: __props.clientOptions, eventBus: __props.eventBus, fallback: "", isWebhook: __props.isWebhook, method: __props.method, operation: __props.operation, path: __props.path, securitySchemes: __props.selectedSecuritySchemes, selectedClient: __props.selectedClient, selectedServer: __props.selectedServer }, createSlots({ header: withCtx(() => [ createVNode(OperationPath, { class: "font-code text-c-2 [&_em]:text-c-1 [&_em]:not-italic", deprecated: __props.operation?.deprecated, path: __props.path }, null, 8, ["deprecated", "path"]) ]), _: 2 }, [ !__props.isWebhook ? { name: "footer", fn: withCtx(() => [ !__props.options.hideTestRequestButton ? (openBlock(), createBlock(unref(TestRequestButton), { key: 0, id: __props.id, eventBus: __props.eventBus, method: __props.method, path: __props.path }, null, 8, ["id", "eventBus", "method", "path"])) : createCommentVNode("", true) ]), key: "0" } : void 0 ]), 1032, ["clientOptions", "eventBus", "isWebhook", "method", "operation", "path", "securitySchemes", "selectedClient", "selectedServer"]) ]), _: 1 }), createVNode(unref(ScalarErrorBoundary), null, { default: withCtx(() => [ __props.operation.responses ? (openBlock(), createBlock(unref(ExampleResponses), { key: 0, responses: __props.operation.responses, style: { "margin-top": "12px" } }, null, 8, ["responses"])) : createCommentVNode("", true) ]), _: 1 }) ]) ]), _: 1 }) ]), _: 1 }) ]), _: 1 }) ]), _: 1 }, 8, ["id", "aria-labelledby", "label"]); }; } }); export { _sfc_main as default };