@omnifyjp/ts 2.1.2 → 2.1.3

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.
@@ -276,6 +276,13 @@ function buildDocProperties(properties, expandedProperties, propertyOrder) {
276
276
  const phpType = nullable ? 'int|null' : 'int';
277
277
  lines.push(` * @property ${phpType} $${snakeName}`);
278
278
  }
279
+ else if (relation === 'MorphTo') {
280
+ const morphName = prop['morphName'] || toSnakeCase(propName);
281
+ const nullable = prop['nullable'] ?? true;
282
+ const nullSuffix = nullable ? '|null' : '';
283
+ lines.push(` * @property string${nullSuffix} $${morphName}_type`);
284
+ lines.push(` * @property string${nullSuffix} $${morphName}_id`);
285
+ }
279
286
  continue;
280
287
  }
281
288
  if (expandedProperties[propName]) {
@@ -329,6 +336,11 @@ function buildFillable(properties, expandedProperties, propertyOrder) {
329
336
  if (relation === 'ManyToOne') {
330
337
  fields.push(toSnakeCase(propName) + '_id');
331
338
  }
339
+ else if (relation === 'MorphTo') {
340
+ const morphName = prop['morphName'] || toSnakeCase(propName);
341
+ fields.push(morphName + '_type');
342
+ fields.push(morphName + '_id');
343
+ }
332
344
  continue;
333
345
  }
334
346
  if (expandedProperties[propName]) {
@@ -73,17 +73,34 @@ function generateBaseRequest(name, schema, reader, config, action) {
73
73
  }
74
74
  continue;
75
75
  }
76
- // Skip non-fillable associations except ManyToOne
76
+ // Association handling
77
77
  if (type === 'Association') {
78
78
  const relation = prop['relation'] ?? '';
79
- if (relation !== 'ManyToOne')
80
- continue;
81
- const snakeName = toSnakeCase(propName) + '_id';
82
- const rules = isUpdate
83
- ? toUpdateRules(prop, tableName, modelRouteParam)
84
- : toStoreRules(prop, tableName);
85
- rulesLines.push(` '${snakeName}' => ${formatRules(rules)},`);
86
- attributeKeys.push(snakeName);
79
+ if (relation === 'ManyToOne') {
80
+ const snakeName = toSnakeCase(propName) + '_id';
81
+ const rules = isUpdate
82
+ ? toUpdateRules(prop, tableName, modelRouteParam)
83
+ : toStoreRules(prop, tableName);
84
+ rulesLines.push(` '${snakeName}' => ${formatRules(rules)},`);
85
+ attributeKeys.push(snakeName);
86
+ }
87
+ else if (relation === 'MorphTo') {
88
+ const morphName = prop['morphName'] || toSnakeCase(propName);
89
+ const nullable = prop['nullable'] ?? true;
90
+ const requiredRule = nullable ? 'nullable' : 'required';
91
+ const targets = prop['targets'] ?? [];
92
+ // {morphName}_type rules
93
+ const typeRules = [requiredRule, 'string'];
94
+ if (targets.length > 0) {
95
+ typeRules.push(`in:${targets.join(',')}`);
96
+ }
97
+ rulesLines.push(` '${morphName}_type' => [${typeRules.map(r => `'${r}'`).join(', ')}],`);
98
+ attributeKeys.push(morphName + '_type');
99
+ // {morphName}_id rules
100
+ const idRules = [requiredRule, 'string'];
101
+ rulesLines.push(` '${morphName}_id' => [${idRules.map(r => `'${r}'`).join(', ')}],`);
102
+ attributeKeys.push(morphName + '_id');
103
+ }
87
104
  continue;
88
105
  }
89
106
  // File type: generate array item rules for multiple files
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnifyjp/ts",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "TypeScript model type generator from Omnify schemas.json",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",