@kubb/plugin-oas
Version:
OpenAPI Specification (OAS) plugin for Kubb, providing core functionality for parsing and processing OpenAPI/Swagger schemas for code generation.
58 lines (55 loc) • 1.8 kB
JavaScript
import path from "node:path";
import { isFunction } from "remeda";
//#region src/utils/getBanner.ts
/**
* Generate a default banner for files created by Kubb
* @returns A string with the default banner
*/
function getDefaultBanner({ title, description, version, config }) {
try {
let source = "";
if ("path" in config.input) source = path.basename(config.input.path);
else if ("data" in config.input) source = "text content";
let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
if (config.output.defaultBanner === "simple") {
banner += "*/\n";
return banner;
}
if (source) banner += `* Source: ${source}\n`;
if (title) banner += `* Title: ${title}\n`;
if (description) {
const formattedDescription = description.replace(/\n/gm, "\n* ");
banner += `* Description: ${formattedDescription}\n`;
}
if (version) banner += `* OpenAPI spec version: ${version}\n`;
banner += "*/\n";
return banner;
} catch (_error) {
return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
}
}
function getBanner({ output, oas, config }) {
let banner = "";
if (config?.output?.defaultBanner !== false && config) {
const { title, description, version } = oas.api?.info || {};
banner = getDefaultBanner({
title,
description,
version,
config
});
}
if (!output.banner) return banner;
if (isFunction(output.banner)) return `${output.banner(oas)}\n${banner}`;
return `${output.banner}\n${banner}`;
}
//#endregion
//#region src/utils/getFooter.ts
function getFooter({ output, oas }) {
if (!output.footer) return;
if (isFunction(output.footer)) return output.footer(oas);
return output.footer;
}
//#endregion
export { getBanner as n, getFooter as t };
//# sourceMappingURL=getFooter-DVB-hawK.js.map