nextjs-swagger-autogen
Version:
Auto-generate Swagger documentation for Next.js API routes
36 lines (35 loc) • 1.7 kB
JavaScript
;
"use client";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SwaggerClient = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const ErrorBoundary_1 = require("./ErrorBoundary");
const ReactSwagger_1 = require("./ReactSwagger");
const SwaggerClient = ({ spec, className, containerStyle = { minHeight: "100dvh", backgroundColor: "white" }, suppressConsoleWarnings = true, }) => {
(0, react_1.useEffect)(() => {
const logs = (type = "warn") => {
const originalConsoleWarn = console?.[type];
console[type] = (...args) => {
if (typeof args[0] === "string" &&
(args[0].includes("UNSAFE_componentWillReceiveProps") ||
args[0].includes("componentWillReceiveProps") ||
args[0].includes("OperationContainer"))) {
return;
}
originalConsoleWarn(...args);
};
return originalConsoleWarn;
};
if (suppressConsoleWarnings) {
const originalConsoleWarn = logs("warn");
const originalConsoleErr = logs("error");
return () => {
console.warn = originalConsoleWarn;
console.error = originalConsoleErr;
};
}
}, [suppressConsoleWarnings]);
return ((0, jsx_runtime_1.jsx)(ErrorBoundary_1.SwaggerErrorBoundary, { children: (0, jsx_runtime_1.jsx)("section", { className: className, style: containerStyle, children: (0, jsx_runtime_1.jsx)(ReactSwagger_1.ReactSwagger, { spec: spec }) }) }));
};
exports.SwaggerClient = SwaggerClient;