@scalar/api-reference
Version:
Generate beautiful API references from OpenAPI documents
53 lines (52 loc) • 2.25 kB
JavaScript
import { defineComponent, computed, createElementBlock, createCommentVNode, openBlock, Fragment, renderList, createBlock, unref, withCtx, resolveDynamicComponent, mergeProps } from "vue";
import { ScalarErrorBoundary } from "@scalar/components";
import { usePluginManager } from "../../plugins/hooks/usePluginManager.js";
const _hoisted_1 = {
key: 0,
class: "text-base"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "SpecificationExtension",
props: {
value: {}
},
setup(__props) {
const { getSpecificationExtensions } = usePluginManager();
function getCustomExtensionNames(value) {
return Object.keys(value ?? {}).filter(
(item) => item.startsWith("x-")
);
}
function getCustomOpenApiExtensionComponents(extensionNames) {
return extensionNames.flatMap((name) => getSpecificationExtensions(name)).filter((extension) => extension.component);
}
const customExtensionNames = computed(() => getCustomExtensionNames(__props.value));
const customExtensions = computed(
() => getCustomOpenApiExtensionComponents(customExtensionNames.value)
);
return (_ctx, _cache) => {
return typeof __props.value === "object" && customExtensions.value.length ? (openBlock(), createElementBlock("div", _hoisted_1, [
(openBlock(true), createElementBlock(Fragment, null, renderList(customExtensions.value, (extension) => {
return openBlock(), createBlock(unref(ScalarErrorBoundary), null, {
default: withCtx(() => [
extension.renderer ? (openBlock(), createBlock(resolveDynamicComponent(extension.renderer), mergeProps({
key: 0,
ref_for: true
}, {
[extension.name]: __props.value?.[extension.name],
component: extension.component
}), null, 16)) : (openBlock(), createBlock(resolveDynamicComponent(extension.component), mergeProps({
key: 1,
ref_for: true
}, { [extension.name]: __props.value?.[extension.name] }), null, 16))
]),
_: 2
}, 1024);
}), 256))
])) : createCommentVNode("", true);
};
}
});
export {
_sfc_main as default
};