UNPKG

fastify-openapi-connector-generator

Version:

Complimentary CLI tool for fastify-openapi-connector package. It generates prefabricates for handlers from OpenAPI specification.

132 lines (131 loc) 3.48 kB
/// <reference types="node" resolution-mode="require"/> import path from 'node:path'; /** * OAS Paths object */ export interface PathsObject { [method: string]: any; } /** * OAS object */ export interface OpenAPISpec { components?: { securitySchemes?: Record<string, unknown>; }; paths?: PathsObject; webhooks?: PathsObject; } /** * Type of function that generates a file */ export type TemplateFunction = (imp: string, operationId: string, typesPath: string) => string; /** * Function to generate handler files * @param imp operationId * @param typesPath path to types file */ export declare const routeTemplateTyped: TemplateFunction; /** * Function to generate untyped handler files * @param imp operationId * @param typesPath not used */ export declare const routeTemplateUntyped: TemplateFunction; /** * Function to generate security files * @param name security name */ export declare const securityTemplate: (name: string) => string; /** * Function to generate handler files * @param args setup arguments * @returns operationIds */ export declare const parseAndGenerateOperationHandlers: (args: { paths: PathsObject; filesPath: string; typesPath: string; typed: boolean; }) => Promise<string[]>; /** * Function to generate security files * @param args setup arguments * @returns security hander names */ export declare const parseAndGenerateSecurity: (args: { security: Record<string, unknown>; filesPath: string; }) => Promise<string[]>; /** * Entry point function that generates the service and handler files * @param args Setup arguments */ export declare const generate: (args: { routesPath?: string; servicePath: string; spec: OpenAPISpec; typesPath: string; webhooksPath?: string; securityPath?: string; schemaFilePath: string; typed: boolean; overrideTypesFile: boolean; }) => Promise<void>; /** * Function to generate handler files * @param args setup arguments */ export declare const generateHandlerFiles: (args: { handlerNames: string[]; path: string; typesPath: string; templateFunction: TemplateFunction; }) => Promise<void>; /** * Function to generate handler imports * @param args setup arguments * @returns handler imports */ export declare const generateHandlerImports: (args: { handlerNames: string[]; path: string; servicePath: string; }) => string[]; /** * Helper interface for sorting handlers */ export interface OrganizedHandlers { path?: string; handlers?: string[]; exportName: string; typeName: string; } /** * Sort handlers function, sorting based on path * @param a * @param b * @returns -1/0/1 */ export declare const handlersSort: (a: OrganizedHandlers, b: OrganizedHandlers) => number; /** * Generets types file * @param typesFilePath Path where to generate * @param schemaPath Path to schema file * @param overrideTypesFile Indicates that types file should be overrided if exists * @returns */ export declare const generateTypesFile: (typesFilePath: string, schemaPath: string, overrideTypesFile: boolean) => void; /** * Function to generate service file * @param args setup arguments */ export declare const generateServiceFile: (args: { pathHandlerNames?: string[]; webhookHandlerNames?: string[]; securityHandlerNames?: string[]; routesPath?: string; webhooksPath?: string; securityPath?: string; servicePath: string; }) => void;