Skip to content

Resolve: Description of a property in spec must correspond to DB TABLE COLUMN COMMENT #60 #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9ec5b1b
Create PR
SOHELAHMED7 Sep 28, 2024
87b01da
Add failing test
SOHELAHMED7 Sep 28, 2024
1e408b7
Fix this issue
SOHELAHMED7 Sep 28, 2024
2fb2d7b
Move `resolve()` method
SOHELAHMED7 Sep 28, 2024
f998279
Add test to ensure existing comments are preserved
SOHELAHMED7 Sep 28, 2024
4a11785
Fix failing tests
SOHELAHMED7 Sep 28, 2024
d4dd074
Add comments handling for PgSQL as it is different from MySQL - WIP
SOHELAHMED7 Sep 28, 2024
b18c521
Add comments handling for PgSQL as it is different from MySQL - 2
SOHELAHMED7 Sep 29, 2024
72a7a6a
Add comments handling for PgSQL as it is different from MySQL - done
SOHELAHMED7 Sep 29, 2024
7d557c4
Complete the test
SOHELAHMED7 Sep 29, 2024
d0415fb
Fix bug and failing tests
SOHELAHMED7 Sep 30, 2024
fa47121
Rename function and constant
SOHELAHMED7 Sep 30, 2024
3fbf3c7
Handle quoting of values
SOHELAHMED7 Oct 1, 2024
6ea5f1d
Resolve TODOs
SOHELAHMED7 Oct 1, 2024
2647645
Merge branches 'master' and '60-description-of-a-property-in-spec-mus…
SOHELAHMED7 Nov 15, 2024
7fa9cde
Fix failing test
SOHELAHMED7 Nov 15, 2024
af961aa
Make this feature optional - WIP - https://github.com/php-openapi/yii…
SOHELAHMED7 Nov 15, 2024
d549831
Implement for table/compo schema - WIP
SOHELAHMED7 Nov 18, 2024
53416d2
WIP
SOHELAHMED7 Nov 19, 2024
3815cb3
Implement for property level extension
SOHELAHMED7 Nov 20, 2024
8fd5b8b
Add more tests
SOHELAHMED7 Nov 21, 2024
051900a
Fix failing tests
SOHELAHMED7 Nov 21, 2024
9d4dc38
Add doc
SOHELAHMED7 Nov 21, 2024
20fad45
Resolve TODO
SOHELAHMED7 Nov 21, 2024
692c4aa
Implement for PgSQL
SOHELAHMED7 Nov 21, 2024
d5be8ce
Refactor
SOHELAHMED7 Nov 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make this feature optional - WIP - #61 (comment)
  • Loading branch information
SOHELAHMED7 committed Nov 15, 2024
commit af961aa83c39b285764701ba3ab7dded642fa3cc
4 changes: 4 additions & 0 deletions src/lib/CustomSpecAttr.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ class CustomSpecAttr
* Custom route (controller ID/action ID) instead of auto-generated. See README for usage docs. https://github.com/cebe/yii2-openapi/issues/144
*/
public const ROUTE = 'x-route';


// TODO docs here + in README.md
public const DESC_IS_COMMENT = 'x-description-is-comment';
}
2 changes: 1 addition & 1 deletion src/lib/generators/MigrationsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected function createBuilder(DbModel $model):BaseMigrationBuilder
if ($this->db->getDriverName() === 'pgsql') {
return Yii::createObject(PostgresMigrationBuilder::class, [$this->db, $model]);
}
return Yii::createObject(MysqlMigrationBuilder::class, [$this->db, $model]);
return Yii::createObject(MysqlMigrationBuilder::class, [$this->db, $model, $this->config]);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/lib/migrations/BaseMigrationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use cebe\yii2openapi\generator\ApiGenerator;
use cebe\yii2openapi\lib\ColumnToCode;
use cebe\yii2openapi\lib\Config;
use cebe\yii2openapi\lib\items\DbModel;
use cebe\yii2openapi\lib\items\ManyToManyRelation;
use cebe\yii2openapi\lib\items\MigrationModel;
Expand Down Expand Up @@ -53,19 +54,22 @@ abstract class BaseMigrationBuilder
*/
protected $recordBuilder;

public ?Config $config = null;

/**
* MigrationBuilder constructor.
* @param \yii\db\Connection $db
* @param \cebe\yii2openapi\lib\items\DbModel $model
* @throws \yii\base\InvalidConfigException
* @throws \yii\base\NotSupportedException
*/
public function __construct(Connection $db, DbModel $model)
public function __construct(Connection $db, DbModel $model, ?Config $config = null)
{
$this->db = $db;
$this->model = $model;
$this->tableSchema = $db->getTableSchema($model->getTableAlias(), true);
$this->recordBuilder = Yii::createObject(MigrationRecordBuilder::class, [$db->getSchema()]);
$this->config = $config;
}

/**
Expand Down
13 changes: 9 additions & 4 deletions src/lib/migrations/MysqlMigrationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use cebe\yii2openapi\generator\ApiGenerator;
use cebe\yii2openapi\lib\ColumnToCode;
use cebe\yii2openapi\lib\CustomSpecAttr;
use cebe\yii2openapi\lib\items\DbIndex;
use yii\base\NotSupportedException;
use yii\db\ColumnSchema;
Expand Down Expand Up @@ -59,10 +60,14 @@ protected function compareColumns(ColumnSchema $current, ColumnSchema $desired):
$this->modifyDesiredInContextOfCurrent($current, $desiredFromDb);
$this->modifyDesiredFromDbInContextOfDesired($desired, $desiredFromDb);

foreach (['type', 'size', 'allowNull', 'defaultValue', 'enumValues'
, 'dbType', 'phpType'
, 'precision', 'scale', 'unsigned', 'comment'
] as $attr) {
$properties = ['type', 'size', 'allowNull', 'defaultValue', 'enumValues'
, 'dbType', 'phpType'
, 'precision', 'scale', 'unsigned'#, 'comment'
];
if (!empty($this->config->getOpenApi()->{CustomSpecAttr::DESC_IS_COMMENT})) {
$properties[] = 'comment';
}
foreach ($properties as $attr) {
if ($attr === 'defaultValue') {
if ($this->isDefaultValueChanged($current, $desiredFromDb)) {
$changedAttributes[] = $attr;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
openapi: 3.0.3

x-description-is-comment: true
info:
title: 'Description of a property in spec must correspond to DB TABLE COLUMN COMMENT #60'
version: 1.0.0
Expand Down
Loading