feat: Implement Clean Architecture code generation with Mustache templates
- Added `clean-arch.generator.ts` for generating models, mappers, repositories, use cases, and providers based on OpenAPI specs. - Introduced `dto.generator.ts` to invoke `openapi-generator-cli` for generating DTOs and organizing them. - Created `report.generator.ts` to generate a JSON report of the generation process. - Implemented `analyzer.ts` for parsing OpenAPI/Swagger files and extracting relevant data. - Defined new types in `cli.types.ts`, `generation.types.ts`, `openapi.types.ts`, and `swagger.types.ts` for better type safety. - Added utility functions in `filesystem.ts` for creating directory structures and cleaning up temporary files. - Developed logging utilities in `logger.ts` for better console output. - Included OpenAPI generator checks and installation in `openapi-generator.ts`. - Added type mapping utility in `type-mapper.ts` for converting OpenAPI types to TypeScript types. - Updated `package.json` scripts to lint all TypeScript files. - Modified `tsconfig.json` to include all TypeScript files in the project.
This commit is contained in:
11
src/types/cli.types.ts
Normal file
11
src/types/cli.types.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Opciones recibidas desde la línea de comandos (Commander).
|
||||
* Desacoplada del framework CLI para permitir su uso desde un backend u otro entrypoint.
|
||||
*/
|
||||
export interface CliOptions {
|
||||
input: string;
|
||||
output: string;
|
||||
templates: string;
|
||||
skipInstall?: boolean;
|
||||
dryRun?: boolean;
|
||||
}
|
||||
27
src/types/generation.types.ts
Normal file
27
src/types/generation.types.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Contadores acumulativos de artefactos generados durante el proceso.
|
||||
*/
|
||||
export interface GeneratedCount {
|
||||
models: number;
|
||||
repositories: number;
|
||||
mappers: number;
|
||||
useCases: number;
|
||||
providers: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reporte final de generación que se persiste como `generation-report.json`.
|
||||
*/
|
||||
export interface GenerationReport {
|
||||
timestamp: string;
|
||||
tags: number;
|
||||
endpoints: number;
|
||||
outputDirectory: string;
|
||||
structure: {
|
||||
dtos: number;
|
||||
repositories: number;
|
||||
mappers: number;
|
||||
useCases: number;
|
||||
providers: number;
|
||||
};
|
||||
}
|
||||
8
src/types/index.ts
Normal file
8
src/types/index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* @module types
|
||||
* @description Barrel que re-exporta todos los tipos e interfaces compartidos del proyecto.
|
||||
*/
|
||||
export * from './cli.types';
|
||||
export * from './swagger.types';
|
||||
export * from './openapi.types';
|
||||
export * from './generation.types';
|
||||
83
src/types/openapi.types.ts
Normal file
83
src/types/openapi.types.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Representación simplificada de un schema de componente OpenAPI.
|
||||
* Se utiliza para generar modelos (entidades) y mappers.
|
||||
*/
|
||||
export interface OpenApiSchema {
|
||||
properties?: Record<
|
||||
string,
|
||||
{
|
||||
type?: string;
|
||||
description?: string;
|
||||
$ref?: string;
|
||||
items?: { $ref?: string };
|
||||
}
|
||||
>;
|
||||
required?: string[];
|
||||
description?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Representación de una operación OpenAPI (GET, POST, etc.) dentro de un path.
|
||||
* Contiene la información necesaria para generar repositorios y casos de uso.
|
||||
*/
|
||||
export interface OpenApiOperation {
|
||||
tags?: string[];
|
||||
operationId?: string;
|
||||
summary?: string;
|
||||
description?: string;
|
||||
parameters?: Array<{
|
||||
name: string;
|
||||
in: string;
|
||||
required: boolean;
|
||||
description?: string;
|
||||
schema?: { type?: string };
|
||||
}>;
|
||||
requestBody?: {
|
||||
description?: string;
|
||||
content?: Record<
|
||||
string,
|
||||
{
|
||||
schema?: {
|
||||
$ref?: string;
|
||||
type?: string;
|
||||
};
|
||||
}
|
||||
>;
|
||||
};
|
||||
responses?: Record<
|
||||
string,
|
||||
{
|
||||
content?: Record<
|
||||
string,
|
||||
{
|
||||
schema?: {
|
||||
$ref?: string;
|
||||
type?: string;
|
||||
items?: { $ref?: string };
|
||||
};
|
||||
}
|
||||
>;
|
||||
}
|
||||
>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Operación normalizada y lista para ser consumida por los templates Mustache.
|
||||
* Cada instancia representa un endpoint agrupado bajo un tag del API.
|
||||
*/
|
||||
export interface TagOperation {
|
||||
nickname: string;
|
||||
summary: string;
|
||||
notes: string;
|
||||
httpMethod: string;
|
||||
path: string;
|
||||
allParams: unknown[];
|
||||
hasQueryParams: boolean;
|
||||
queryParams: unknown[];
|
||||
hasBodyParam: boolean;
|
||||
bodyParam: string;
|
||||
returnType: string | boolean;
|
||||
returnBaseType: string | boolean;
|
||||
isListContainer: boolean;
|
||||
vendorExtensions: Record<string, unknown>;
|
||||
}
|
||||
9
src/types/swagger.types.ts
Normal file
9
src/types/swagger.types.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Resultado del análisis de un archivo OpenAPI/Swagger.
|
||||
* Contiene las estructuras crudas extraídas del spec para su posterior procesamiento.
|
||||
*/
|
||||
export interface SwaggerAnalysis {
|
||||
tags: unknown[];
|
||||
paths: Record<string, unknown>;
|
||||
swagger: unknown;
|
||||
}
|
||||
Reference in New Issue
Block a user