Skip to content

Commit af961aa

Browse files
committed
Make this feature optional - WIP - #61 (comment)
1 parent 7fa9cde commit af961aa

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

src/lib/CustomSpecAttr.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ class CustomSpecAttr
5656
* Custom route (controller ID/action ID) instead of auto-generated. See README for usage docs. https://github.com/cebe/yii2-openapi/issues/144
5757
*/
5858
public const ROUTE = 'x-route';
59+
60+
61+
// TODO docs here + in README.md
62+
public const DESC_IS_COMMENT = 'x-description-is-comment';
5963
}

src/lib/generators/MigrationsGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected function createBuilder(DbModel $model):BaseMigrationBuilder
142142
if ($this->db->getDriverName() === 'pgsql') {
143143
return Yii::createObject(PostgresMigrationBuilder::class, [$this->db, $model]);
144144
}
145-
return Yii::createObject(MysqlMigrationBuilder::class, [$this->db, $model]);
145+
return Yii::createObject(MysqlMigrationBuilder::class, [$this->db, $model, $this->config]);
146146
}
147147

148148
/**

src/lib/migrations/BaseMigrationBuilder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use cebe\yii2openapi\generator\ApiGenerator;
1111
use cebe\yii2openapi\lib\ColumnToCode;
12+
use cebe\yii2openapi\lib\Config;
1213
use cebe\yii2openapi\lib\items\DbModel;
1314
use cebe\yii2openapi\lib\items\ManyToManyRelation;
1415
use cebe\yii2openapi\lib\items\MigrationModel;
@@ -53,19 +54,22 @@ abstract class BaseMigrationBuilder
5354
*/
5455
protected $recordBuilder;
5556

57+
public ?Config $config = null;
58+
5659
/**
5760
* MigrationBuilder constructor.
5861
* @param \yii\db\Connection $db
5962
* @param \cebe\yii2openapi\lib\items\DbModel $model
6063
* @throws \yii\base\InvalidConfigException
6164
* @throws \yii\base\NotSupportedException
6265
*/
63-
public function __construct(Connection $db, DbModel $model)
66+
public function __construct(Connection $db, DbModel $model, ?Config $config = null)
6467
{
6568
$this->db = $db;
6669
$this->model = $model;
6770
$this->tableSchema = $db->getTableSchema($model->getTableAlias(), true);
6871
$this->recordBuilder = Yii::createObject(MigrationRecordBuilder::class, [$db->getSchema()]);
72+
$this->config = $config;
6973
}
7074

7175
/**

src/lib/migrations/MysqlMigrationBuilder.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use cebe\yii2openapi\generator\ApiGenerator;
1111
use cebe\yii2openapi\lib\ColumnToCode;
12+
use cebe\yii2openapi\lib\CustomSpecAttr;
1213
use cebe\yii2openapi\lib\items\DbIndex;
1314
use yii\base\NotSupportedException;
1415
use yii\db\ColumnSchema;
@@ -59,10 +60,14 @@ protected function compareColumns(ColumnSchema $current, ColumnSchema $desired):
5960
$this->modifyDesiredInContextOfCurrent($current, $desiredFromDb);
6061
$this->modifyDesiredFromDbInContextOfDesired($desired, $desiredFromDb);
6162

62-
foreach (['type', 'size', 'allowNull', 'defaultValue', 'enumValues'
63-
, 'dbType', 'phpType'
64-
, 'precision', 'scale', 'unsigned', 'comment'
65-
] as $attr) {
63+
$properties = ['type', 'size', 'allowNull', 'defaultValue', 'enumValues'
64+
, 'dbType', 'phpType'
65+
, 'precision', 'scale', 'unsigned'#, 'comment'
66+
];
67+
if (!empty($this->config->getOpenApi()->{CustomSpecAttr::DESC_IS_COMMENT})) {
68+
$properties[] = 'comment';
69+
}
70+
foreach ($properties as $attr) {
6671
if ($attr === 'defaultValue') {
6772
if ($this->isDefaultValueChanged($current, $desiredFromDb)) {
6873
$changedAttributes[] = $attr;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
openapi: 3.0.3
2-
2+
x-description-is-comment: true
33
info:
44
title: 'Description of a property in spec must correspond to DB TABLE COLUMN COMMENT #60'
55
version: 1.0.0

0 commit comments

Comments
 (0)