@kubb/plugin-oas
Version:
OpenAPI Specification (OAS) plugin for Kubb, providing core functionality for parsing and processing OpenAPI/Swagger schemas for code generation.
134 lines (133 loc) • 5.12 kB
TypeScript
import { t as __name } from "./chunk--u3MIqq1.js";
import { g as OperationSchema } from "./createGenerator-W6EtzLmf.js";
import { t as Schema } from "./SchemaMapper-SneuY1wg.js";
import { Oas, OasTypes, OpenAPIV3, OpenAPIV3_1, Operation, SchemaObject, contentType, isOptional } from "@kubb/oas";
import { Config, FunctionParamsAST, Output } from "@kubb/core";
import { KubbFile } from "@kubb/fabric-core/types";
import { Params } from "@kubb/react-fabric/types";
//#region src/utils/getBanner.d.ts
type Props$1<TOas extends Oas> = {
oas: TOas;
output: Output<any>;
config?: Config;
};
declare function getBanner<TOas extends Oas>({
output,
oas,
config
}: Props$1<TOas>): string;
//#endregion
//#region src/utils/getComments.d.ts
declare function getComments(operation: Operation): string[];
//#endregion
//#region src/utils/getFooter.d.ts
type Props<TOas extends Oas> = {
oas: TOas;
output: Output<any>;
};
declare function getFooter<TOas extends Oas>({
output,
oas
}: Props<TOas>): string | undefined;
//#endregion
//#region src/utils/getImports.d.ts
/**
* Get imports from a schema tree by extracting all ref schemas that are importable
*/
declare function getImports(tree: Array<Schema>): Array<KubbFile.Import>;
//#endregion
//#region src/utils/getParams.d.ts
declare function getPathParams(operationSchema: OperationSchema | undefined, options?: {
typed?: boolean;
casing?: 'camelcase';
override?: (data: FunctionParamsAST) => FunctionParamsAST;
}): Params;
/**
* Get a mapping of camelCase parameter names to their original names
* Used for mapping function parameters to backend parameter names
*/
declare function getParamsMapping(operationSchema: OperationSchema | undefined, options?: {
casing?: 'camelcase';
}): Record<string, string> | undefined;
//#endregion
//#region src/utils/getSchemaFactory.d.ts
/**
* Make it possible to narrow down the schema based on a specific version(3 or 3.1)
*/
type SchemaResult<TWithRef extends boolean = false> = {
schemaObject: ((TWithRef extends true ? OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject : OpenAPIV3.SchemaObject) & {
nullable?: boolean;
'x-nullable'?: boolean;
}) | null;
version: '3.0';
} | {
schemaObject: ((TWithRef extends true ? OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject : OpenAPIV3_1.SchemaObject) & {
nullable?: boolean;
'x-nullable'?: boolean;
}) | null;
version: '3.1';
};
/**
* Creates a factory function that generates a versioned OpenAPI schema result.
*
* The returned function accepts an optional schema object and produces a {@link SchemaResult} containing the dereferenced schema and the OpenAPI version ('3.0' or '3.1').
*
* @returns A function that takes an optional schema and returns a versioned schema result.
*/
declare function getSchemaFactory<TWithRef extends boolean = false>(oas: Oas): (schema: SchemaObject | null) => SchemaResult<TWithRef>;
//#endregion
//#region src/utils/getSchemas.d.ts
type GetSchemasResult = {
schemas: Record<string, OasTypes.SchemaObject>;
/**
* Mapping from original component name to resolved name after collision handling
* e.g., { 'Order': 'OrderSchema', 'variant': 'variant2' }
*/
nameMapping: Map<string, string>;
};
type Mode = 'schemas' | 'responses' | 'requestBodies';
type GetSchemasProps = {
oas: Oas;
contentType?: contentType;
includes?: Mode[];
/**
* Whether to resolve name collisions with suffixes.
* If not provided, uses oas.options.collisionDetection
* @default false (from oas.options or fallback)
*/
collisionDetection?: boolean;
};
/**
* Collect schemas from OpenAPI components (schemas, responses, requestBodies)
* and return them in dependency order along with name mapping for collision resolution.
*
* This function is a wrapper around the oas.getSchemas() method for backward compatibility.
* New code should use oas.getSchemas() directly.
*
* @deprecated Use oas.getSchemas() instead
*/
declare function getSchemas({
oas,
contentType,
includes,
collisionDetection
}: GetSchemasProps): GetSchemasResult;
//#endregion
//#region src/utils/paramsCasing.d.ts
/**
* Apply casing transformation to schema properties
* Only transforms property names, not nested schemas
*/
declare function applyParamsCasing(schema: SchemaObject, casing: 'camelcase' | undefined): SchemaObject;
/**
* Check if this schema is a parameter schema (pathParams, queryParams, or headerParams)
* Only these should be transformed, not response/data/body
*/
declare function isParameterSchema(schemaName: string): boolean;
//#endregion
//#region src/utils/requestBody.d.ts
declare function isRequestBodyRequired(operationSchema: OperationSchema | undefined): boolean;
declare function withRequiredRequestBodySchema(operationSchema: OperationSchema | undefined): OperationSchema | undefined;
//#endregion
export { applyParamsCasing, getBanner, getComments, getFooter, getImports, getParamsMapping, getPathParams, getSchemaFactory, getSchemas, isOptional, isParameterSchema, isRequestBodyRequired, withRequiredRequestBodySchema };
//# sourceMappingURL=utils.d.ts.map