Skip to content

Commit 1e408b7

Browse files
committed
Fix this issue
1 parent 87b01da commit 1e408b7

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

src/lib/ColumnToCode.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ class ColumnToCode
8484
*/
8585
private $isPk = false;
8686

87-
private $rawParts = ['type' => null, 'nullable' => null, 'default' => null, 'position' => null];
87+
private $rawParts = ['type' => null, 'nullable' => null, 'default' => null, 'position' => null, 'comment' => null];
8888

89-
private $fluentParts = ['type' => null, 'nullable' => null, 'default' => null, 'position' => null];
89+
private $fluentParts = ['type' => null, 'nullable' => null, 'default' => null, 'position' => null, 'comment' => null];
9090

9191
/**
9292
* @var bool
@@ -160,7 +160,8 @@ public function getCode(bool $quoted = false):string
160160
$this->fluentParts['type'],
161161
$this->fluentParts['nullable'],
162162
$this->fluentParts['default'],
163-
$this->fluentParts['position']
163+
$this->fluentParts['position'],
164+
$this->fluentParts['comment'],
164165
]);
165166
array_unshift($parts, '$this');
166167
return implode('->', array_filter(array_map('trim', $parts)));
@@ -175,9 +176,12 @@ public function getCode(bool $quoted = false):string
175176
}
176177

177178
$code = $this->rawParts['type'] . ' ' . $this->rawParts['nullable'] . $default;
178-
if ((ApiGenerator::isMysql() || ApiGenerator::isMariaDb()) && $this->rawParts['position']) {
179-
$code .= ' ' . $this->rawParts['position'];
179+
180+
if ((ApiGenerator::isMysql() || ApiGenerator::isMariaDb())) {
181+
$code .= $this->rawParts['position'] ? ' ' . $this->rawParts['position'] : '';
182+
$code .= $this->rawParts['comment'] ? ' '.$this->rawParts['comment'] : '';
180183
}
184+
181185
if (ApiGenerator::isPostgres() && $this->alterByXDbType) {
182186
return $quoted ? VarDumper::export($this->rawParts['type']) : $this->rawParts['type'];
183187
}

src/lib/items/Attribute.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ public function toColumnSchema():ColumnSchema
318318
'allowNull' => $this->allowNull(),
319319
'size' => $this->size > 0 ? $this->size : null,
320320
'xDbType' => $this->xDbType,
321+
'comment' => $this->description,
321322
]);
322323
$column->isPrimaryKey = $this->primary;
323324
$column->autoIncrement = $this->primary && $this->phpType === 'int';

tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@
1111
'generateMigrations' => true,
1212
'generateModelFaker' => true, // `generateModels` must be `true` in order to use `generateModelFaker` as `true`
1313
];
14-

tests/specs/issue_fix/60_description_of_a_property_in_spec_must_correspond_to_db_table_column_comment/index.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ components:
1818
# type: string
1919
description:
2020
type: string
21+
x-db-type: varchar
22+
description: desc 2
2123

2224
paths:
2325
'/':

0 commit comments

Comments
 (0)