feat: add base url mechanism

This commit is contained in:
2026-03-24 19:15:47 +01:00
parent a9bbf21317
commit 4aeb108c55
5 changed files with 193 additions and 6 deletions

View File

@@ -12,11 +12,34 @@ import type {
GeneratedCount
} from '../types';
/**
* Extracts the unique tags (in order of appearance) from a SwaggerAnalysis.
* Only endpoints that have at least one tag are considered; the first tag is used.
*/
export function extractTagsFromAnalysis(analysis: SwaggerAnalysis): string[] {
const seen = new Set<string>();
const tags: string[] = [];
Object.values(analysis.paths).forEach((pathObj) => {
Object.values(pathObj as Record<string, unknown>).forEach((opRaw) => {
const op = opRaw as OpenApiOperation;
if (op.tags && op.tags.length > 0) {
const tag = op.tags[0];
if (!seen.has(tag)) {
seen.add(tag);
tags.push(tag);
}
}
});
});
return tags;
}
/** Genera todos los artefactos de Clean Architecture (modelos, mappers, repos, use cases, providers) usando Mustache. */
export function generateCleanArchitecture(
analysis: SwaggerAnalysis,
outputDir: string,
templatesDir: string
templatesDir: string,
tagApiKeyMap: Record<string, string> = {}
): GeneratedCount {
logStep('Generando artefactos de Clean Architecture usando Mustache...');
const generatedCount: GeneratedCount = {
@@ -236,7 +259,9 @@ export function generateCleanArchitecture(
// Return-type-only imports — for repo impl (Dto + Entity + Mapper)
returnImports,
// Param-only imports — for repo impl (Entity only, no Dto/Mapper)
paramImports
paramImports,
// Environment API key for the repository base URL (e.g. "aprovalmApi")
environmentApiKey: tagApiKeyMap[tag] || 'apiUrl'
}
}
]