@simplix-boot/cli 2.0.3 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.ko.md CHANGED
@@ -44,7 +44,7 @@ simplix-boot --version
44
44
  `Author`라는 JPA 엔티티와 그 저장소가 이미 있는 프로젝트의 루트에서 실행하세요.
45
45
 
46
46
  ```bash
47
- # 1. Create the .simplix folder, then write .simplix/generator-simplix.json
47
+ # 1. Create the .simplix folder, then write .simplix/simplix-boot.json
48
48
  simplix-boot init
49
49
 
50
50
  # 2. Write .simplix/entity/Author.yml from the entity
package/README.md CHANGED
@@ -44,7 +44,7 @@ To run it without installing, use `npx @simplix-boot/cli <command>` with the sam
44
44
  Run these in the root of a project that already has a JPA entity named `Author` and its repository.
45
45
 
46
46
  ```bash
47
- # 1. Create the .simplix folder, then write .simplix/generator-simplix.json
47
+ # 1. Create the .simplix folder, then write .simplix/simplix-boot.json
48
48
  simplix-boot init
49
49
 
50
50
  # 2. Write .simplix/entity/Author.yml from the entity
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplix-boot/cli",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "Command line tool that generates SimpliX Spring Boot code (services, controllers, DTOs, tests) from JPA entities",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { parseArguments } from './lib/args.js';
2
2
  import { createOutput, style, symbols } from './lib/console.js';
3
3
  import { CliError } from './lib/errors.js';
4
- import { requireProjectRoot } from './lib/project.js';
4
+ import { earlierConfigNotice, requireProjectRoot } from './lib/project.js';
5
5
  import { getGeneratorVersion } from './lib/version-utils.js';
6
6
  import * as config from './commands/config.js';
7
7
  import * as generate from './commands/generate.js';
@@ -93,6 +93,8 @@ export function main(argv, { cwd = process.cwd() } = {}) {
93
93
  const { positionals, options } = parseArguments(rest, command.argumentSpec);
94
94
  const output = createOutput();
95
95
  const root = command.needsProject === false ? undefined : requireProjectRoot(cwd);
96
+ const notice = root === undefined ? undefined : earlierConfigNotice(root);
97
+ if (notice !== undefined) output.notice(notice);
96
98
 
97
99
  return command.run({ cwd, root, positionals, options, output }) ?? 0;
98
100
  } catch (error) {
@@ -5,6 +5,7 @@ import lodash from 'lodash';
5
5
  import { extractTableComment } from '../lib/comment-extractor.js';
6
6
  import { symbols } from '../lib/console.js';
7
7
  import { resolveControllerName } from '../lib/controller-name.js';
8
+ import { analyzeParentClass } from '../lib/config/parents.js';
8
9
  import { analyzeEntity } from '../lib/entity-analyzer.js';
9
10
  import { createEntityTypeResolver } from '../lib/entity-type-resolver.js';
10
11
  import { resolveEntityType } from '../lib/entity-type.js';
@@ -170,6 +171,17 @@ export function generate({ root, entityName: ymlName, force = false, test = true
170
171
  const entityComment = extractTableComment(entityContent);
171
172
  const analysis = analyzeEntity(entityContent, { isEntityType: createEntityTypeResolver(srcPath) });
172
173
 
174
+ // What the entity takes from parent classes whose source is under the scan path. These stay
175
+ // apart from the entity's own fields, which the DTOs and the search fields are built from.
176
+ const { parentFields } = analyzeParentClass(
177
+ { root, config, log: () => {} },
178
+ analysis.parentClass,
179
+ settings.baseEntityPath,
180
+ srcPath,
181
+ new Set()
182
+ );
183
+ const inheritedFields = parentFields.filter(inherited => !analysis.fields.some(own => own.name === inherited.name));
184
+
173
185
  const treeEntityInterface = (analysis.implementedInterfaces || []).find(i => i.name === 'TreeEntity');
174
186
  const hasTreeEntity = Boolean(treeEntityInterface);
175
187
  if (hasTreeEntity) {
@@ -219,6 +231,7 @@ export function generate({ root, entityName: ymlName, force = false, test = true
219
231
  entityComment,
220
232
  analysis,
221
233
  fields,
234
+ inheritedFields,
222
235
  controllerName: resolveControllerName(ymlName, entityConfig),
223
236
  dtoExcludeFields: settings.dtoExcludeFields,
224
237
  searchFields,
@@ -1,7 +1,16 @@
1
1
  import fs from 'node:fs';
2
2
  import { style, symbols } from '../lib/console.js';
3
3
  import { CliError } from '../lib/errors.js';
4
- import { CONFIG_FILE_NAME, configPathOf, findProjectRoot, readProjectConfig } from '../lib/project.js';
4
+ import {
5
+ CONFIG_FILE_NAME,
6
+ EARLIER_CONFIG_FILE_NAME,
7
+ SIMPLIX_DIR,
8
+ configPathOf,
9
+ earlierConfigNotice,
10
+ findConfigFile,
11
+ findProjectRoot,
12
+ readProjectConfig,
13
+ } from '../lib/project.js';
5
14
  import {
6
15
  collectVersionStatus,
7
16
  fetchLatestPublishedVersion,
@@ -107,21 +116,32 @@ export function run({ cwd, options, output }) {
107
116
  }
108
117
 
109
118
  const root = findProjectRoot(cwd);
110
- const configPath = root !== undefined && fs.existsSync(configPathOf(root)) ? configPathOf(root) : null;
119
+ const file = root === undefined ? undefined : findConfigFile(root);
120
+ const configPath = file?.path ?? null;
111
121
 
112
122
  if (options.write) {
113
- if (!configPath) {
123
+ if (!file) {
114
124
  throw new CliError(
115
125
  `${CONFIG_FILE_NAME} not found. Run "simplix-boot init" first and create the configuration file.`
116
126
  );
117
127
  }
118
128
 
129
+ // The file is written under its current name: one of the earlier name is renamed first.
130
+ const target = configPathOf(root);
131
+ if (file.earlier) {
132
+ fs.renameSync(file.path, target);
133
+ log(`${symbols.success} Renamed ${SIMPLIX_DIR}/${EARLIER_CONFIG_FILE_NAME} to ${SIMPLIX_DIR}/${CONFIG_FILE_NAME}`);
134
+ }
135
+
119
136
  const version = toReleaseVersion(getGeneratorVersion());
120
- recordGeneratorVersion(configPath, version);
121
- log(`${symbols.success} Recorded generator version ${style.cyan(version)} in ${configPath}`);
137
+ recordGeneratorVersion(target, version);
138
+ log(`${symbols.success} Recorded generator version ${style.cyan(version)} in ${target}`);
122
139
  return;
123
140
  }
124
141
 
142
+ const notice = root === undefined ? undefined : earlierConfigNotice(root);
143
+ if (notice !== undefined) output.notice(notice);
144
+
125
145
  const config = configPath ? readProjectConfig(root) : null;
126
146
  const status = collectVersionStatus({ config, includeLatest: true });
127
147
 
@@ -69,13 +69,18 @@ export function tolerateClosedReader(stream) {
69
69
  * Where a command writes: progress and reports as lines, and a machine-readable result as the one
70
70
  * line a script reads.
71
71
  *
72
- * @returns {{ log: (message?: string) => void, result: (text: string) => void }}
72
+ * A notice goes to standard error, so the report or the result on standard output stays whole.
73
+ *
74
+ * @returns {{ log: (message?: string) => void, result: (text: string) => void, notice: (message: string) => void }}
73
75
  */
74
76
  export function createOutput() {
75
77
  return {
76
78
  log(message = '') {
77
79
  process.stdout.write(`${message}\n`);
78
80
  },
81
+ notice(message) {
82
+ process.stderr.write(`${symbols.warning} ${message}\n`);
83
+ },
79
84
  result(text) {
80
85
  process.stdout.write(`${text}\n`);
81
86
  },
@@ -73,7 +73,7 @@ function validate(config, root, log) {
73
73
  /**
74
74
  * Reads what `generate` needs out of the project configuration.
75
75
  *
76
- * @param {object} config the parsed `.simplix/generator-simplix.json`
76
+ * @param {object} config the parsed project configuration
77
77
  * @param {string} root the project root
78
78
  * @param {(message: string) => void} log where warnings go
79
79
  * @returns {object} the resolved settings
@@ -90,6 +90,19 @@ function generatedAt() {
90
90
  return shifted.toISOString().replace('Z', '+09:00');
91
91
  }
92
92
 
93
+ /**
94
+ * The lookup a template asks whether the entity carries a field, declared by the entity itself or
95
+ * by a parent class.
96
+ *
97
+ * @param {object[]} fields the entity's own fields
98
+ * @param {object[]} inheritedFields the fields of its parent classes
99
+ * @returns {(name: string) => boolean} whether a field of that name exists
100
+ */
101
+ export function entityFieldLookup(fields, inheritedFields) {
102
+ const names = new Set([...fields, ...inheritedFields].map(field => field.name));
103
+ return name => names.has(name);
104
+ }
105
+
93
106
  /**
94
107
  * Builds the variables every template is rendered with.
95
108
  *
@@ -99,6 +112,8 @@ function generatedAt() {
99
112
  * @param {string} input.entityComment the entity's table comment
100
113
  * @param {object} input.analysis what the entity analyzer read from the source
101
114
  * @param {object[]} input.fields the entity fields, with service imports resolved
115
+ * @param {object[]} [input.inheritedFields] the fields of the entity's parent classes whose source is
116
+ * under the scan path, without those the entity declares again
102
117
  * @param {string} input.controllerName the REST controller's class name
103
118
  * @param {string[]} input.dtoExcludeFields the fields every DTO leaves out
104
119
  * @param {object} input.searchFields the embedded id and entity search fields
@@ -113,6 +128,7 @@ export function buildTemplateVars({
113
128
  entityComment,
114
129
  analysis,
115
130
  fields,
131
+ inheritedFields = [],
116
132
  controllerName,
117
133
  dtoExcludeFields,
118
134
  searchFields,
@@ -133,6 +149,8 @@ export function buildTemplateVars({
133
149
  fields,
134
150
  idType,
135
151
  entityFields: fields,
152
+ inheritedFields,
153
+ entityHasField: entityFieldLookup(fields, inheritedFields),
136
154
  entityNameLowerFirst: props.entityName.charAt(0).toLowerCase() + props.entityName.slice(1),
137
155
  idFieldName: entityConfig?.idField || 'id',
138
156
  controllerName,
@@ -7,7 +7,10 @@ import { CliError } from './errors.js';
7
7
  export const SIMPLIX_DIR = '.simplix';
8
8
 
9
9
  /** The project configuration file, inside {@link SIMPLIX_DIR}. */
10
- export const CONFIG_FILE_NAME = 'generator-simplix.json';
10
+ export const CONFIG_FILE_NAME = 'simplix-boot.json';
11
+
12
+ /** The name the configuration file had under generator-simplix, read while a project has no file of the current name. */
13
+ export const EARLIER_CONFIG_FILE_NAME = 'generator-simplix.json';
11
14
 
12
15
  /**
13
16
  * The nearest directory at or above `start` that holds a `.simplix` folder.
@@ -43,11 +46,47 @@ export function requireProjectRoot(start = process.cwd()) {
43
46
  return root;
44
47
  }
45
48
 
46
- /** Where the project configuration file lives under a project root. */
49
+ /** Where the project configuration file lives under a project root, and where it is written. */
47
50
  export function configPathOf(root) {
48
51
  return path.join(root, SIMPLIX_DIR, CONFIG_FILE_NAME);
49
52
  }
50
53
 
54
+ /**
55
+ * The configuration file a project has: the one of the current name, or else the one of the
56
+ * earlier name.
57
+ *
58
+ * @param {string} root the project root
59
+ * @returns {{ path: string, name: string, earlier: boolean } | undefined} the file, or undefined
60
+ * when the project has neither
61
+ */
62
+ export function findConfigFile(root) {
63
+ const current = configPathOf(root);
64
+ if (fs.existsSync(current)) return { path: current, name: CONFIG_FILE_NAME, earlier: false };
65
+
66
+ const earlier = path.join(root, SIMPLIX_DIR, EARLIER_CONFIG_FILE_NAME);
67
+ if (fs.existsSync(earlier)) return { path: earlier, name: EARLIER_CONFIG_FILE_NAME, earlier: true };
68
+
69
+ return undefined;
70
+ }
71
+
72
+ /**
73
+ * What a project that still has a configuration file of the earlier name is told.
74
+ *
75
+ * @param {string} root the project root
76
+ * @returns {string | undefined} the notice, or undefined when the project has no such file
77
+ */
78
+ export function earlierConfigNotice(root) {
79
+ if (!fs.existsSync(path.join(root, SIMPLIX_DIR, EARLIER_CONFIG_FILE_NAME))) return undefined;
80
+
81
+ const current = `${SIMPLIX_DIR}/${CONFIG_FILE_NAME}`;
82
+ const earlier = `${SIMPLIX_DIR}/${EARLIER_CONFIG_FILE_NAME}`;
83
+ if (fs.existsSync(configPathOf(root))) {
84
+ return `${earlier} is not read: ${current} is the configuration file. Delete ${earlier}.`;
85
+ }
86
+
87
+ return `${earlier} is the earlier name of the configuration file. Rename it to ${current}.`;
88
+ }
89
+
51
90
  /** Where an entity's yml lives under a project root. */
52
91
  export function entityConfigPathOf(root, entityName) {
53
92
  return path.join(root, SIMPLIX_DIR, 'entity', `${entityName}.yml`);
@@ -61,14 +100,14 @@ export function entityConfigPathOf(root, entityName) {
61
100
  * @throws {CliError} when the file is not valid JSON
62
101
  */
63
102
  export function readProjectConfig(root) {
64
- const configPath = configPathOf(root);
65
- if (!fs.existsSync(configPath)) return undefined;
103
+ const file = findConfigFile(root);
104
+ if (file === undefined) return undefined;
66
105
 
67
106
  try {
68
- return JSON.parse(fs.readFileSync(configPath, 'utf8'));
107
+ return JSON.parse(fs.readFileSync(file.path, 'utf8'));
69
108
  } catch (error) {
70
109
  if (!(error instanceof SyntaxError)) throw error;
71
- throw new CliError(`Failed to parse ${CONFIG_FILE_NAME}: ${error.message}`);
110
+ throw new CliError(`Failed to parse ${file.name}: ${error.message}`);
72
111
  }
73
112
  }
74
113
 
@@ -2,6 +2,7 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { resolveControllerName } from './controller-name.js';
4
4
  import { CliError } from './errors.js';
5
+ import { CONFIG_FILE_NAME } from './project.js';
5
6
 
6
7
  function resolvePath(template, modulePath) {
7
8
  if (!template) throw new Error('Path template is undefined');
@@ -27,7 +28,7 @@ function generatedTestBase(config) {
27
28
  *
28
29
  * @param {object} target
29
30
  * @param {string} target.root the project root
30
- * @param {object} target.config the parsed `.simplix/generator-simplix.json`
31
+ * @param {object} target.config the parsed project configuration
31
32
  * @param {string} target.entityName the entity class name
32
33
  * @param {object} target.entityConfig the parsed entity yml, which carries `modulePath`
33
34
  * @param {string} target.moduleName the target module under the module root (`admin/jobs`)
@@ -36,7 +37,7 @@ function generatedTestBase(config) {
36
37
  export function promoteFiles({ root, config, entityName, entityConfig, moduleName }) {
37
38
  const modulePath = entityConfig?.modulePath;
38
39
  if (!modulePath) throw new CliError(`modulePath not found in ${entityName}.yml`);
39
- if (!config.target?.targetPath) throw new CliError('target.targetPath not found in generator-simplix.json');
40
+ if (!config.target?.targetPath) throw new CliError(`target.targetPath not found in ${CONFIG_FILE_NAME}`);
40
41
  const moduleRoot = config.promote?.moduleRoot || 'modules';
41
42
  const packagePath = config.target.basePackage.replace(/\./g, '/');
42
43
  const main = (target, fileName) => ({
@@ -137,6 +137,32 @@ export function mergeThreeWay(base, ours, theirs) {
137
137
  }
138
138
  }
139
139
 
140
+ const SINGLE_IMPORT = /^import (?:static )?[\w.]+\.(\w+);$/;
141
+
142
+ /**
143
+ * Puts back each import the edited file had and the merge dropped while the merged code still names
144
+ * the imported class or member: a template that stops importing a class cannot see that code
145
+ * written into the file by hand still uses it.
146
+ *
147
+ * @param {string} ours the edited file
148
+ * @param {string} merged the result of the three-way merge
149
+ * @returns {string} the merge with those imports after its last import line
150
+ */
151
+ export function keepUsedImports(ours, merged) {
152
+ const mergedLines = merged.split('\n');
153
+ const present = new Set(mergedLines.filter(line => SINGLE_IMPORT.test(line)));
154
+ const code = mergedLines.filter(line => !line.startsWith('import ')).join('\n');
155
+ const dropped = ours.split('\n').filter(line => {
156
+ const name = SINGLE_IMPORT.exec(line)?.[1];
157
+ return name !== undefined && !present.has(line) && new RegExp(`\\b${name}\\b`).test(code);
158
+ });
159
+ if (dropped.length === 0) return merged;
160
+ const lastImport = mergedLines.findLastIndex(line => line.startsWith('import '));
161
+ if (lastImport < 0) return merged;
162
+ mergedLines.splice(lastImport + 1, 0, ...new Set(dropped));
163
+ return mergedLines.join('\n');
164
+ }
165
+
140
166
  /**
141
167
  * What a promote of one fresh render into one file comes to, without writing anything.
142
168
  *
@@ -164,7 +190,9 @@ export function planTracked(root, filePath, stamped) {
164
190
  if (base === undefined) return { outcome: 'no-base' };
165
191
  // The stamp lines name the render a file was read against and are not content: every side takes
166
192
  // the fresh render's, so a fingerprint that moved never collides with one an edit carried.
167
- const { text, hunks } = mergeThreeWay(carryStamp(base, stamped), carryStamp(ours, stamped), stamped);
193
+ const merge = mergeThreeWay(carryStamp(base, stamped), carryStamp(ours, stamped), stamped);
194
+ const hunks = merge.hunks;
195
+ const text = filePath.endsWith('.java') ? keepUsedImports(ours, merge.text) : merge.text;
168
196
  if (hunks.length > 0) return { outcome: 'conflict', text, hunks };
169
197
  if (text === ours || text === carryStamp(ours, stamped)) return { outcome: 'current', text: ours };
170
198
  return { outcome: 'merged', text };
@@ -17,7 +17,7 @@ const NPM_LOOKUP_TIMEOUT_MS = 15000;
17
17
 
18
18
  /**
19
19
  * Version of the CLI this project is built against, as recorded in
20
- * generator-simplix.json under `generator.version`. Null when not recorded.
20
+ * project configuration under `generator.version`. Null when not recorded.
21
21
  */
22
22
  export function readRequiredVersion(config) {
23
23
  const recorded = config?.generator?.version;
@@ -28,7 +28,7 @@ const GENERATOR_VERSION_FIELD = /("generator"\s*:\s*\{[^{}]*?"version"\s*:\s*)"[
28
28
  const GENERATOR_BLOCK_OPEN = /"generator"\s*:\s*\{/;
29
29
 
30
30
  /**
31
- * Write `generator.version` into generator-simplix.json.
31
+ * Write `generator.version` into the project configuration file.
32
32
  * The surrounding text is preserved byte for byte so recording a version never
33
33
  * reformats a configuration file the project maintains by hand.
34
34
  */
@@ -50,6 +50,7 @@ import dev.simplecore.searchable.core.condition.SearchCondition;
50
50
  import dev.simplecore.searchable.openapi.annotation.SearchableParams;
51
51
  import io.swagger.v3.oas.annotations.Operation;
52
52
  import io.swagger.v3.oas.annotations.tags.Tag;
53
+ import jakarta.validation.Valid;
53
54
  import org.springframework.data.domain.Page;
54
55
  <% if (exportConfig.enabled) { -%>
55
56
  import dev.simplecore.simplix.excel.export.ExportFormat;
@@ -179,13 +180,14 @@ public class <%= controllerName %> extends SimpliXBaseController<<%= entityName
179
180
  /**
180
181
  * Updates multiple <%= entityName %> entities in a single operation.
181
182
  *
182
- * @param updateDtos set of DTOs containing update data
183
+ * @param updateDtos set of DTOs containing update data; {@code @Valid} on the element validates
184
+ * each one as a single update is, since a bare set is not validated
183
185
  * @return response containing the list of updated <%= classPrefix %>DetailDTOs
184
186
  */
185
187
  @PatchMapping
186
188
  @Operation(summary = "Update Multiple <%= entityName %>", description = "Updates multiple existing <%= entityName %>")
187
189
  @PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'edit')")
188
- public SimpliXApiResponse<List<<%= classPrefix %>DetailDTO>> multiUpdate(@RequestBody Set<<%= classPrefix %>UpdateDTO> updateDtos) {
190
+ public SimpliXApiResponse<List<<%= classPrefix %>DetailDTO>> multiUpdate(@RequestBody Set<@Valid <%= classPrefix %>UpdateDTO> updateDtos) {
189
191
  <% if (hasTreeEntity) { %>
190
192
  // TreeService doesn't support multiUpdate - use service instead
191
193
  List<<%= classPrefix %>DetailDTO> updatedItems = service.multiUpdate(updateDtos);
@@ -329,7 +331,7 @@ public class <%= controllerName %> extends SimpliXBaseController<<%= entityName
329
331
  @PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'edit')")
330
332
  public SimpliXApiResponse<List<<%= classPrefix %>ListDTO>> updateTreeOrder(
331
333
  @RequestParam(required = false) <%= idType %> parentId,
332
- @RequestBody @Validated List<<%= classPrefix %>OrderUpdateDTO> orderUpdateDtos) {
334
+ @RequestBody List<@Valid <%= classPrefix %>OrderUpdateDTO> orderUpdateDtos) {
333
335
  try {
334
336
  List<<%= classPrefix %>ListDTO> updatedEntities = treeService.updateOrders(parentId, orderUpdateDtos);
335
337
  return SimpliXApiResponse.success(updatedEntities, "<%= entityName %> orders updated successfully");
@@ -350,7 +352,7 @@ public class <%= controllerName %> extends SimpliXBaseController<<%= entityName
350
352
  @SimpliXStandardApi
351
353
  @PreAuthorize("hasPermission('<%= ymlConfig.permissionGroup || entityName %>', 'edit')")
352
354
  public SimpliXApiResponse<List<<%= classPrefix %>DetailDTO>> updateOrder(
353
- @RequestBody @Validated List<<%= classPrefix %>OrderUpdateDTO> orderUpdateDtos) {
355
+ @RequestBody List<@Valid <%= classPrefix %>OrderUpdateDTO> orderUpdateDtos) {
354
356
  List<<%= classPrefix %>DetailDTO> updatedEntities = service.updateOrders(orderUpdateDtos);
355
357
  return SimpliXApiResponse.success(updatedEntities, "<%= entityName %> orders updated successfully");
356
358
  }
@@ -155,7 +155,7 @@ const isTreeEntity = typeof hasTreeEntity !== 'undefined' ? hasTreeEntity :
155
155
  // Build entityFields name set for quick lookup
156
156
  const entityFieldNames = new Set(entityFields.map(f => f.name));
157
157
 
158
- // Build excluded fields set from generator-simplix.json configuration
158
+ // Build excluded fields set from the project configuration
159
159
  const excludedFieldsSet = new Set(dtoExcludeFields || []);
160
160
 
161
161
  // Helper: Check if a field should be excluded from DTO generation
@@ -78,7 +78,7 @@ import static org.mockito.ArgumentMatchers.*;
78
78
  import static org.mockito.Mockito.*;
79
79
 
80
80
  <%
81
- // Build excluded fields set from generator-simplix.json configuration (same as DTO template)
81
+ // Build excluded fields set from the project configuration (same as DTO template)
82
82
  const excludedFieldsSet = new Set(dtoExcludeFields || []);
83
83
 
84
84
  // Helper: Check if a field should be excluded from DTO generation
@@ -86,6 +86,12 @@ function isExcludedField(fieldName) {
86
86
  return excludedFieldsSet.has(fieldName);
87
87
  }
88
88
 
89
+ // Helper: whether the entity carries an audit timestamp. The yml lists it, or the entity or a
90
+ // parent class whose source is under the scan path declares it.
91
+ function hasTimestamp(fieldName) {
92
+ return Boolean(ymlConfig.fields?.[fieldName]) || entityHasField(fieldName);
93
+ }
94
+
89
95
  // Helper: Check if field name already ends with 'Id' (to avoid 'IdId' pattern)
90
96
  function fieldNameEndsWithId(fieldName) {
91
97
  return fieldName.endsWith('Id') && fieldName !== 'Id';
@@ -250,8 +256,8 @@ class <%= classPrefix %>ServiceTest {
250
256
  entity.set<%= setterSuffix %>(true);
251
257
  <% }
252
258
  }
253
- }); %><% if (ymlConfig.fields?.createdAt) { %>
254
- entity.setCreatedAt(Instant.now());<% } %><% if (ymlConfig.fields?.updatedAt) { %>
259
+ }); %><% if (hasTimestamp('createdAt')) { %>
260
+ entity.setCreatedAt(Instant.now());<% } %><% if (hasTimestamp('updatedAt')) { %>
255
261
  entity.setUpdatedAt(Instant.now());<% } %>
256
262
 
257
263
  // Setup DTOs
@@ -58,13 +58,19 @@ import static org.mockito.ArgumentMatchers.*;
58
58
  import static org.mockito.Mockito.*;
59
59
 
60
60
  <%
61
- // Build excluded fields set from generator-simplix.json configuration (same as DTO template)
61
+ // Build excluded fields set from the project configuration (same as DTO template)
62
62
  const excludedFieldsSet = new Set(dtoExcludeFields || []);
63
63
 
64
64
  // Helper: Check if a field should be excluded from DTO generation
65
65
  function isExcludedField(fieldName) {
66
66
  return excludedFieldsSet.has(fieldName);
67
67
  }
68
+
69
+ // Helper: whether the entity carries an audit timestamp. The yml lists it, or the entity or a
70
+ // parent class whose source is under the scan path declares it.
71
+ function hasTimestamp(fieldName) {
72
+ return Boolean(ymlConfig.fields?.[fieldName]) || entityHasField(fieldName);
73
+ }
68
74
  %>
69
75
  /**
70
76
  * Unit tests for <%= classPrefix %>TreeService
@@ -161,8 +167,8 @@ class <%= classPrefix %>TreeServiceTest {
161
167
  entity.set<%= field.name.charAt(0).toUpperCase() + field.name.slice(1) %>(true);
162
168
  <% }
163
169
  }
164
- }); %><% if (ymlConfig.fields?.createdAt) { %>
165
- entity.setCreatedAt(Instant.now());<% } %><% if (ymlConfig.fields?.updatedAt) { %>
170
+ }); %><% if (hasTimestamp('createdAt')) { %>
171
+ entity.setCreatedAt(Instant.now());<% } %><% if (hasTimestamp('updatedAt')) { %>
166
172
  entity.setUpdatedAt(Instant.now());<% } %>
167
173
 
168
174
  // Setup child entity
@@ -185,8 +191,8 @@ class <%= classPrefix %>TreeServiceTest {
185
191
  childEntity.set<%= field.name.charAt(0).toUpperCase() + field.name.slice(1) %>(true);
186
192
  <% }
187
193
  }
188
- }); %><% if (ymlConfig.fields?.createdAt) { %>
189
- childEntity.setCreatedAt(Instant.now());<% } %><% if (ymlConfig.fields?.updatedAt) { %>
194
+ }); %><% if (hasTimestamp('createdAt')) { %>
195
+ childEntity.setCreatedAt(Instant.now());<% } %><% if (hasTimestamp('updatedAt')) { %>
190
196
  childEntity.setUpdatedAt(Instant.now());<% } %>
191
197
 
192
198
  // Setup DTOs