feat: enhance DTO mock generation with dynamic import paths and mock value checks

This commit is contained in:
2026-03-27 15:40:33 +01:00
parent e0446d4939
commit 16ef1ce3e3
3 changed files with 20 additions and 7 deletions

View File

@@ -247,6 +247,7 @@ export function generateCleanArchitecture(
const varsMap = Object.keys(rawProperties).map((k) => {
let tsType = mapSwaggerTypeToTs(rawProperties[k].type);
const isInlineObject = rawProperties[k].type === 'object' && !rawProperties[k].$ref;
if (rawProperties[k].$ref) {
tsType = rawProperties[k].$ref.split('/').pop() || 'unknown';
} else if (rawProperties[k].type === 'array' && rawProperties[k].items?.$ref) {
@@ -257,7 +258,8 @@ export function generateCleanArchitecture(
originalName: k,
dataType: tsType,
description: rawProperties[k].description || '',
required: requiredProps.includes(k)
required: requiredProps.includes(k),
hasMockValue: !isInlineObject
};
});
@@ -347,11 +349,18 @@ export function generateCleanArchitecture(
name: safePropertyName(k),
mockValue: resolveMockValue(k, rawProperties[k], 'dto', schemaName)
}));
const dtoMockImports = [...referencedTypes].filter(Boolean).map((name) => ({
classname: name,
classFilename: toCamelCase(name),
tagFilename: schemaTagMap[name] || 'shared'
}));
const dtoMockImports = [...referencedTypes].filter(Boolean).map((name) => {
const targetTag = schemaTagMap[name] || 'shared';
const targetFile = `${toCamelCase(name)}.dto.mock`;
const importPath =
targetTag === tagFilename ? `./${targetFile}` : `../${targetTag}/${targetFile}`;
return {
classname: name,
classFilename: toCamelCase(name),
tagFilename: targetTag,
importPath
};
});
const dtoMockViewData = {
tagFilename,