refactor: normalize array type notation from Array<T> to T[] in generators and type mapper

This commit is contained in:
didavila
2026-03-24 16:27:10 +01:00
parent 73dcb6f701
commit e008144813
3 changed files with 15 additions and 10 deletions

View File

@@ -44,7 +44,7 @@ export function generateCleanArchitecture(
if (rawProperties[k].$ref) {
tsType = rawProperties[k].$ref.split('/').pop() || 'unknown';
} else if (rawProperties[k].type === 'array' && rawProperties[k].items?.$ref) {
tsType = `Array<${rawProperties[k].items.$ref.split('/').pop()}>`;
tsType = `${rawProperties[k].items.$ref.split('/').pop()}[]`;
}
return {
name: k,
@@ -163,7 +163,7 @@ export function generateCleanArchitecture(
returnBaseType = returnType;
} else if (responseSchema.type === 'array' && responseSchema.items?.$ref) {
returnBaseType = responseSchema.items.$ref.split('/').pop() || 'unknown';
returnType = `Array<${returnBaseType}>`;
returnType = `${returnBaseType}[]`;
isListContainer = true;
}
}
@@ -203,10 +203,10 @@ export function generateCleanArchitecture(
const imports: { classname: string; classFilename: string; classVarName: string }[] = [];
Object.keys(schemas).forEach((s) => {
const usedAsReturn = tagsMap[tag].some(
(op) => op.returnType === s || op.returnType === `Array<${s}>`
(op) => op.returnType === s || op.returnType === `${s}[]`
);
const usedAsParam = tagsMap[tag].some((op) =>
op.allParams.some((p) => p.dataType === s || p.dataType === `Array<${s}>`)
op.allParams.some((p) => p.dataType === s || p.dataType === `${s}[]`)
);
if (usedAsReturn || usedAsParam) {
imports.push({