feat: add tag/endpoint selection mechanism
This commit is contained in:
@@ -9,6 +9,8 @@ import type {
|
||||
OpenApiSchema,
|
||||
OpenApiOperation,
|
||||
TagOperation,
|
||||
TagSummary,
|
||||
SelectionFilter,
|
||||
GeneratedCount
|
||||
} from '../types';
|
||||
|
||||
@@ -34,12 +36,35 @@ export function extractTagsFromAnalysis(analysis: SwaggerAnalysis): string[] {
|
||||
return tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts all tags with their operations summary for the interactive selection screen.
|
||||
*/
|
||||
export function extractTagsWithOperations(analysis: SwaggerAnalysis): TagSummary[] {
|
||||
const map = new Map<string, TagSummary>();
|
||||
Object.entries(analysis.paths).forEach(([pathKey, pathObj]) => {
|
||||
Object.entries(pathObj as Record<string, unknown>).forEach(([method, opRaw]) => {
|
||||
const op = opRaw as OpenApiOperation;
|
||||
if (!op.tags?.length) return;
|
||||
const tag = op.tags[0];
|
||||
if (!map.has(tag)) map.set(tag, { tag, operations: [] });
|
||||
map.get(tag)!.operations.push({
|
||||
nickname: op.operationId || `${method}${pathKey.replace(/\//g, '_')}`,
|
||||
method: method.toUpperCase(),
|
||||
path: pathKey,
|
||||
summary: op.summary || ''
|
||||
});
|
||||
});
|
||||
});
|
||||
return [...map.values()];
|
||||
}
|
||||
|
||||
/** Genera todos los artefactos de Clean Architecture (modelos, mappers, repos, use cases, providers) usando Mustache. */
|
||||
export function generateCleanArchitecture(
|
||||
analysis: SwaggerAnalysis,
|
||||
outputDir: string,
|
||||
templatesDir: string,
|
||||
tagApiKeyMap: Record<string, string> = {}
|
||||
tagApiKeyMap: Record<string, string> = {},
|
||||
selectionFilter: SelectionFilter = {}
|
||||
): GeneratedCount {
|
||||
logStep('Generando artefactos de Clean Architecture usando Mustache...');
|
||||
const generatedCount: GeneratedCount = {
|
||||
@@ -221,6 +246,17 @@ export function generateCleanArchitecture(
|
||||
});
|
||||
});
|
||||
|
||||
if (Object.keys(selectionFilter).length > 0) {
|
||||
Object.keys(tagsMap).forEach((tag) => {
|
||||
if (!selectionFilter[tag]) {
|
||||
delete tagsMap[tag];
|
||||
} else {
|
||||
tagsMap[tag] = tagsMap[tag].filter((op) => selectionFilter[tag].includes(op.nickname));
|
||||
if (tagsMap[tag].length === 0) delete tagsMap[tag];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Generar por cada Tag
|
||||
Object.keys(tagsMap).forEach((tag) => {
|
||||
const returnImports: { classname: string; classFilename: string; classVarName: string }[] = [];
|
||||
|
||||
Reference in New Issue
Block a user