UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

240 lines (239 loc) 11.6 kB
import { defineComponent, computed, createBlock, openBlock, unref, createSlots, withCtx, createElementVNode, createCommentVNode, createElementBlock, createVNode, Fragment, toDisplayString, withModifiers, normalizeClass, createTextVNode } from "vue"; import { OperationCodeSample } from "@scalar/api-client/v2/blocks/operation-code-sample"; import { ScalarErrorBoundary, ScalarIconButton, ScalarMarkdown } from "@scalar/components"; import { ScalarIconPlay, ScalarIconCopy, ScalarIconWebhooksLogo } from "@scalar/icons"; import { isOperationDeprecated, getOperationStability, getOperationStabilityColor } from "@scalar/oas-utils/helpers"; import { useClipboard } from "@scalar/use-hooks/useClipboard"; import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref"; import OperationPath from "../../../components/OperationPath.vue.js"; import _sfc_main$4 from "../components/callbacks/Callbacks.vue.js"; import _sfc_main$2 from "../components/OperationParameters.vue.js"; import _sfc_main$3 from "../components/OperationResponses.vue.js"; import _sfc_main$1 from "../../specification-extension/SpecificationExtension.vue2.js"; import { getXKeysFromObject } from "../../specification-extension/helpers.js"; import SectionAccordion from "../../../components/Section/SectionAccordion.vue.js"; import ExampleResponses from "../../example-responses/ExampleResponses.vue.js"; import LinkList from "../../../components/LinkList/LinkList.vue.js"; import _sfc_main$5 from "../../external-docs/ExternalDocs.vue.js"; import _sfc_main$6 from "../../x-badges/XBadges.vue.js"; import TestRequestButton from "../../test-request-button/TestRequestButton.vue.js"; import _sfc_main$7 from "../../../components/HttpMethod/HttpMethod.vue.js"; import _sfc_main$8 from "../../../components/Anchor/Anchor.vue.js"; import Badge from "../../../components/Badge/Badge.vue.js"; const _hoisted_1 = { class: "operation-title" }; const _hoisted_2 = { class: "operation-details" }; const _hoisted_3 = { class: "endpoint-label" }; const _hoisted_4 = { class: "endpoint-label-path" }; const _hoisted_5 = { class: "endpoint-label-name" }; const _hoisted_6 = { key: 1, class: "font-code text-sm" }; const _hoisted_7 = { class: "endpoint-content" }; const _hoisted_8 = { class: "operation-details-card" }; const _hoisted_9 = { key: 0, class: "operation-details-card-item" }; const _hoisted_10 = { class: "operation-details-card-item" }; const _hoisted_11 = { class: "operation-details-card-item" }; const _hoisted_12 = { key: 1, class: "operation-details-card-item" }; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "ClassicLayout", props: { id: {}, method: {}, options: {}, path: {}, clientOptions: {}, isCollapsed: { type: Boolean }, isWebhook: { type: Boolean }, selectedClient: {}, eventBus: {}, operation: {}, selectedServer: {}, selectedSecuritySchemes: {} }, setup(__props) { const operationTitle = computed(() => __props.operation.summary || __props.path || ""); const operationExtensions = computed(() => getXKeysFromObject(__props.operation)); const { copyToClipboard } = useClipboard(); return (_ctx, _cache) => { return openBlock(), createBlock(unref(SectionAccordion), { id: __props.id, "aria-label": operationTitle.value, class: "reference-endpoint", modelValue: !__props.isCollapsed, transparent: "", "onUpdate:modelValue": _cache[2] || (_cache[2] = (value) => __props.eventBus?.emit("toggle:nav-item", { id: __props.id, open: value })) }, createSlots({ title: withCtx(() => [ createElementVNode("div", _hoisted_1, [ createElementVNode("div", _hoisted_2, [ createVNode(unref(_sfc_main$7), { class: "endpoint-type", method: __props.method, short: "" }, null, 8, ["method"]), createVNode(unref(_sfc_main$8), { class: "endpoint-anchor", onCopyAnchorUrl: _cache[0] || (_cache[0] = () => __props.eventBus?.emit("copy-url:nav-item", { id: __props.id })) }, { default: withCtx(() => [ createElementVNode("h3", _hoisted_3, [ createElementVNode("div", _hoisted_4, [ createVNode(OperationPath, { deprecated: unref(isOperationDeprecated)(__props.operation), path: __props.path }, null, 8, ["deprecated", "path"]) ]), createElementVNode("div", _hoisted_5, toDisplayString(operationTitle.value), 1), unref(getOperationStability)(__props.operation) ? (openBlock(), createBlock(unref(Badge), { key: 0, 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: 1, class: "font-code text-green flex w-fit items-center justify-center gap-1" }, { default: withCtx(() => [ createVNode(unref(ScalarIconWebhooksLogo), { weight: "bold" }), _cache[3] || (_cache[3] = createTextVNode("Webhook ", -1)) ]), _: 1 })) : createCommentVNode("", true), createVNode(unref(_sfc_main$6), { badges: __props.operation["x-badges"], position: "before" }, null, 8, ["badges"]) ]) ]), _: 1 }) ]) ]) ]), actions: withCtx(({ active }) => [ createVNode(unref(_sfc_main$6), { badges: __props.operation["x-badges"], position: "after" }, null, 8, ["badges"]), !__props.options.hideTestRequestButton ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [ active && !__props.isWebhook ? (openBlock(), createBlock(unref(TestRequestButton), { key: 0, id: __props.id, eventBus: __props.eventBus, method: __props.method, path: __props.path }, null, 8, ["id", "eventBus", "method", "path"])) : (openBlock(), createBlock(unref(ScalarIconPlay), { key: 1, class: "endpoint-try-hint size-4.5" })) ], 64)) : createCommentVNode("", true), __props.options.showOperationId && __props.operation.operationId ? (openBlock(), createElementBlock("span", _hoisted_6, toDisplayString(__props.operation.operationId), 1)) : createCommentVNode("", true), createVNode(unref(ScalarIconButton), { class: "endpoint-copy p-0.5", icon: unref(ScalarIconCopy), label: "Copy endpoint URL", size: "xs", variant: "ghost", onClick: _cache[1] || (_cache[1] = withModifiers(($event) => unref(copyToClipboard)(__props.path), ["stop"])) }, null, 8, ["icon"]) ]), default: withCtx(() => [ createElementVNode("div", _hoisted_7, [ createElementVNode("div", _hoisted_8, [ Object.keys(operationExtensions.value).length > 0 ? (openBlock(), createElementBlock("div", _hoisted_9, [ createVNode(_sfc_main$1, { value: operationExtensions.value }, null, 8, ["value"]) ])) : createCommentVNode("", true), createElementVNode("div", _hoisted_10, [ createVNode(_sfc_main$2, { eventBus: __props.eventBus, options: __props.options, parameters: __props.operation.parameters, requestBody: unref(getResolvedRef)(__props.operation.requestBody) }, null, 8, ["eventBus", "options", "parameters", "requestBody"]) ]), createElementVNode("div", _hoisted_11, [ createVNode(_sfc_main$3, { eventBus: __props.eventBus, options: __props.options, responses: __props.operation.responses }, null, 8, ["eventBus", "options", "responses"]) ]), __props.operation?.callbacks ? (openBlock(), createElementBlock("div", _hoisted_12, [ createVNode(_sfc_main$4, { callbacks: __props.operation.callbacks, eventBus: __props.eventBus, options: __props.options, path: __props.path }, null, 8, ["callbacks", "eventBus", "options", "path"]) ])) : createCommentVNode("", true) ]), __props.operation.responses ? (openBlock(), createBlock(unref(ExampleResponses), { key: 0, class: "operation-example-card", responses: __props.operation.responses }, null, 8, ["responses"])) : createCommentVNode("", true), createElementVNode("div", null, [ __props.operation.externalDocs ? (openBlock(), createBlock(unref(LinkList), { key: 0 }, { default: withCtx(() => [ createVNode(unref(_sfc_main$5), { value: __props.operation.externalDocs }, null, 8, ["value"]) ]), _: 1 })) : createCommentVNode("", true), createVNode(unref(ScalarErrorBoundary), null, { default: withCtx(() => [ createVNode(unref(OperationCodeSample), { class: "operation-example-card", 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 }, null, 8, ["clientOptions", "eventBus", "isWebhook", "method", "operation", "path", "securitySchemes", "selectedClient", "selectedServer"]) ]), _: 1 }) ]) ]) ]), _: 2 }, [ __props.operation.description ? { name: "description", fn: withCtx(() => [ createVNode(unref(ScalarMarkdown), { anchorPrefix: __props.id, "aria-label": "Operation Description", role: "group", transformType: "heading", value: __props.operation.description, withAnchors: "", withImages: "" }, null, 8, ["anchorPrefix", "value"]) ]), key: "0" } : void 0 ]), 1032, ["id", "aria-label", "modelValue"]); }; } }); export { _sfc_main as default };