Skip to content

Commit

Permalink
Implement for property level extension
Browse files Browse the repository at this point in the history
  • Loading branch information
SOHELAHMED7 committed Nov 20, 2024
1 parent 53416d2 commit 3815cb3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/lib/AttributeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function resolve(): DbModel
//For valid primary keys for junction tables
'junctionCols' => $this->isJunctionSchema ? $this->junctions->junctionCols($this->schemaName) : [],
'isNotDb' => $this->componentSchema->isNonDb(),
'descriptionIsComment' => !empty(($this->componentSchema->{CustomSpecAttr::DESC_IS_COMMENT})) ? $this->componentSchema->{CustomSpecAttr::DESC_IS_COMMENT} : false,
'descriptionIsComment' => !empty(($this->componentSchema->getSchema()->{CustomSpecAttr::DESC_IS_COMMENT}))
],
]);
}
Expand Down Expand Up @@ -226,6 +226,7 @@ protected function resolveProperty(
->setDefault($property->guessDefault())
->setXDbType($property->getAttr(CustomSpecAttr::DB_TYPE))
->setXDbDefaultExpression($property->getAttr(CustomSpecAttr::DB_DEFAULT_EXPRESSION))
->setXDescriptionIsComment($property->getAttr(CustomSpecAttr::DESC_IS_COMMENT))
->setNullable($nullableValue)
->setIsPrimary($property->isPrimaryKey())
->setForeignKeyColumnName($property->fkColName)
Expand Down
25 changes: 18 additions & 7 deletions src/lib/items/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ class Attribute extends BaseObject
*/
public $dbType = 'string';

/**
* Custom db type
* string | null | false
* if `false` then this attribute is virtual
*/
public $xDbType;

/**
* nullable
* bool | null
Expand Down Expand Up @@ -128,6 +121,18 @@ class Attribute extends BaseObject
**/
public $isVirtual = false;

/**
* Custom db type
* string | null | false
* if `false` then this attribute is virtual
*/
public $xDbType;

/**
* @see \cebe\yii2openapi\lib\CustomSpecAttr::DESC_IS_COMMENT
*/
public ?bool $xDescriptionIsComment = false;

public function __construct(string $propertyName, array $config = [])
{
$this->propertyName = $propertyName;
Expand Down Expand Up @@ -397,4 +402,10 @@ public function handleDecimal(ColumnSchema $columnSchema): void
$columnSchema->dbType = $decimalAttributes['dbType'];
}
}

public function setXDescriptionIsComment($xDescriptionIsComment): Attribute
{
$this->xDescriptionIsComment = $xDescriptionIsComment;
return $this;
}
}
14 changes: 11 additions & 3 deletions src/lib/migrations/MysqlMigrationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,17 @@ protected function compareColumns(ColumnSchema $current, ColumnSchema $desired):
, 'dbType', 'phpType'
, 'precision', 'scale', 'unsigned'#, 'comment'
];
if (!empty($this->config->getOpenApi()->{CustomSpecAttr::DESC_IS_COMMENT})) {
$properties[] = 'comment';
} elseif ($this->model->descriptionIsComment) { // TODO
$comment = false;
if ($this->model->attributes[$desired->name]->xDescriptionIsComment) {
$comment = true;
}
if ($this->model->descriptionIsComment) {
$comment = true;
}
if ($this->config && !empty($this->config->getOpenApi()->{CustomSpecAttr::DESC_IS_COMMENT})) {
$comment = true;
}
if ($comment) {
$properties[] = 'comment';
}
foreach ($properties as $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
#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 All @@ -8,43 +8,48 @@ components:
schemas:
Fruit:
type: object
# x-description-is-comment: true
properties:
id:
type: integer
name:
type: string
description: desc with ' quote
x-description-is-comment: true
description:
type: number
x-db-type: double precision
description: desc ' 2
x-description-is-comment: true
Animal:
type: object
# x-description-is-comment: true
properties:
id:
type: integer
name:
type: integer
# description: desc
# description:
# type: string
# x-db-type: varchar
# description: desc 2
x-description-is-comment: true
g:
type: string
description: desc for g
x-description-is-comment: true
g2:
type: string
description: changed comment on g2 col
x-description-is-comment: true
g3:
type: string
description: the comment on g3 col remains same
x-description-is-comment: true
g4:
type: integer
description: data type changes but comment remains same
x-description-is-comment: true
new_col:
type: string
description: new col added
x-description-is-comment: true

paths:
'/':
Expand Down

0 comments on commit 3815cb3

Please sign in to comment.