UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

60 lines (59 loc) 2.42 kB
import { defineComponent, computed, createBlock, createElementBlock, openBlock, unref } from "vue"; import { getResolvedRefDeep, getExampleFromSchema } from "@scalar/api-client/v2/blocks/operation-code-sample"; import { ScalarCodeBlock, ScalarVirtualText } from "@scalar/components"; import { prettyPrintJson } from "@scalar/oas-utils/helpers"; import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref"; const _hoisted_1 = { key: 3, class: "empty-state" }; const VIRTUALIZATION_THRESHOLD = 2e4; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "ExampleResponse", props: { response: {}, example: {} }, setup(__props) { const getContent = () => { if (__props.example !== void 0) { return getResolvedRefDeep(__props.example)?.value ?? ""; } if (__props.response?.schema) { return getExampleFromSchema(getResolvedRef(__props.response.schema), { emptyString: "string", mode: "read" }); } return ""; }; const shouldVirtualize = computed( () => prettyPrintedContent.value.length > VIRTUALIZATION_THRESHOLD ); const prettyPrintedContent = computed( () => prettyPrintJson(getContent()) ); return (_ctx, _cache) => { return __props.example !== void 0 && !shouldVirtualize.value ? (openBlock(), createBlock(unref(ScalarCodeBlock), { key: 0, class: "bg-b-2 -outline-offset-2", lang: "json", prettyPrintedContent: prettyPrintedContent.value }, null, 8, ["prettyPrintedContent"])) : __props.response?.schema && !shouldVirtualize.value ? (openBlock(), createBlock(unref(ScalarCodeBlock), { key: 1, class: "bg-b-2 -outline-offset-2", lang: "json", prettyPrintedContent: prettyPrintedContent.value }, null, 8, ["prettyPrintedContent"])) : (__props.example !== void 0 || __props.response?.schema) && shouldVirtualize.value ? (openBlock(), createBlock(unref(ScalarVirtualText), { key: 2, containerClass: "custom-scroll scalar-code-block border rounded-b flex flex-1 max-h-screen", contentClass: "language-plaintext whitespace-pre font-code text-base", lineHeight: 20, text: prettyPrintedContent.value }, null, 8, ["text"])) : (openBlock(), createElementBlock("div", _hoisted_1, " No Body ")); }; } }); export { _sfc_main as default };