@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 (52 loc) • 1.9 kB
JavaScript
export { parseFromConfig } from './chunk-G3FDK7YW.js';
export { getBanner, getFooter } from './chunk-6S7YFY6F.js';
export { getSchemaFactory, getSchemas } from './chunk-PORSNYI5.js';
import transformers, { isValidVarName, camelCase } from '@kubb/core/transformers';
import { URLPath } from '@kubb/core/utils';
import { isParameterObject } from '@kubb/oas';
export { isOptional } from '@kubb/oas';
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));
}
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;
}, {});
}
export { getComments, getPathParams };
//# sourceMappingURL=utils.js.map
//# sourceMappingURL=utils.js.map