@kubb/plugin-oas
Version:
OpenAPI Specification (OAS) plugin for Kubb, providing core functionality for parsing and processing OpenAPI/Swagger schemas for code generation.
54 lines (51 loc) • 1.95 kB
JavaScript
import { n as getBanner, t as getFooter } from "./getFooter-DVB-hawK.js";
import { n as getSchemaFactory, t as getSchemas } from "./getSchemas-B0dk_Cbz.js";
import transformers, { camelCase, isValidVarName } from "@kubb/core/transformers";
import { isOptional, isParameterObject } from "@kubb/oas";
import { URLPath } from "@kubb/core/utils";
//#region src/utils/getComments.ts
function getComments(operation) {
return [
operation.getDescription() && `@description ${operation.getDescription()}`,
operation.getSummary() && `@summary ${operation.getSummary()}`,
operation.path && `{@link ${new URLPath(operation.path).URL}}`,
operation.isDeprecated() && "@deprecated"
].filter(Boolean).map((text) => transformers.trim(text)).filter(Boolean);
}
//#endregion
//#region src/utils/getParams.ts
/**
*
* @deprecated
* TODO move to operationManager hook
*/
function getASTParams(operationSchema, { typed = false, override } = {}) {
if (!operationSchema || !operationSchema.schema.properties || !operationSchema.name) return [];
return Object.entries(operationSchema.schema.properties).map(([name, schema]) => {
const isParam = isParameterObject(schema);
const data = {
name,
enabled: !!name,
required: isParam ? schema.required : true,
type: typed ? `${operationSchema.name}["${name}"]` : void 0
};
return override ? override(data) : data;
});
}
function getPathParams(operationSchema, options = {}) {
return getASTParams(operationSchema, options).reduce((acc, curr) => {
if (curr.name && curr.enabled) {
let name = isValidVarName(curr.name) ? curr.name : camelCase(curr.name);
if (options.casing === "camelcase") name = camelCase(name);
acc[name] = {
default: curr.default,
type: curr.type,
optional: !curr.required
};
}
return acc;
}, {});
}
//#endregion
export { getBanner, getComments, getFooter, getPathParams, getSchemaFactory, getSchemas, isOptional };
//# sourceMappingURL=utils.js.map