Skip to content

Commit f5e5c01

Browse files
committed
Implementation in progress
1 parent d9e47b0 commit f5e5c01

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

src/lib/AttributeResolver.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ protected function resolveProperty(
278278
if ($property->isRefPointerToSelf()) {
279279
$relation->asSelfReference();
280280
}
281-
if (empty($property->getAttr(CustomSpecAttr::NO_RELATION))) {
282-
$this->relations[$property->getName()] = $relation;
283-
}
281+
// if (empty($property->getAttr(CustomSpecAttr::NO_RELATION))) {
282+
$this->relations[$property->getName()] = $relation;
283+
// }
284284
if (!$property->isRefPointerToSelf()) {
285285
$this->addInverseRelation($relatedClassName, $attribute, $property, $fkProperty);
286286
}
@@ -323,25 +323,25 @@ protected function resolveProperty(
323323
$fkProperty->getName(),
324324
'_id'
325325
)) {
326-
if (empty($property->getAttr(CustomSpecAttr::NO_RELATION))) {
327-
$this->relations[$property->getName()] =
326+
// if (empty($property->getAttr(CustomSpecAttr::NO_RELATION))) {
327+
$this->relations[$property->getName()] =
328328
Yii::createObject(
329329
AttributeRelation::class,
330330
[static::relationName($property->getName(), $property->fkColName), $relatedTableName, $relatedClassName]
331331
)
332332
->asHasMany([$fkProperty->getName() => $fkProperty->getName()])->asSelfReference();
333-
}
333+
// }
334334
return;
335335
}
336336
$foreignPk = Inflector::camel2id($fkProperty->getName(), '_') . '_id';
337-
if (empty($property->getAttr(CustomSpecAttr::NO_RELATION))) {
338-
$this->relations[$property->getName()] =
337+
// if (empty($property->getAttr(CustomSpecAttr::NO_RELATION))) {
338+
$this->relations[$property->getName()] =
339339
Yii::createObject(
340340
AttributeRelation::class,
341341
[static::relationName($property->getName(), $property->fkColName), $relatedTableName, $relatedClassName]
342342
)
343343
->asHasMany([$foreignPk => $this->componentSchema->getPkName()]);
344-
}
344+
// }
345345
return;
346346
}
347347
$relatedClassName = $property->getRefClassName();
@@ -355,15 +355,15 @@ protected function resolveProperty(
355355
return;
356356
}
357357
$attribute->setPhpType($relatedClassName . '[]');
358-
if (empty($property->getAttr(CustomSpecAttr::NO_RELATION))) {
359-
$this->relations[$property->getName()] =
358+
// if (empty($property->getAttr(CustomSpecAttr::NO_RELATION))) {
359+
$this->relations[$property->getName()] =
360360
Yii::createObject(
361361
AttributeRelation::class,
362362
[static::relationName($property->getName(), $property->fkColName), $relatedTableName, $relatedClassName]
363363
)
364364
->asHasMany([Inflector::camel2id($this->schemaName, '_') . '_id' => $this->componentSchema->getPkName()])
365365
->setInverse(Inflector::variablize($this->schemaName));
366-
}
366+
// }
367367
return;
368368
}
369369
if ($this->componentSchema->isNonDb() && $attribute->isReference()) {

src/lib/openapi/ComponentSchema.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
use cebe\yii2openapi\lib\SchemaToDatabase;
1515
use Generator;
1616
use Yii;
17-
use yii\helpers\Inflector;
18-
use yii\helpers\StringHelper;
1917
use function in_array;
2018

2119
class ComponentSchema
@@ -106,7 +104,9 @@ public function isRequiredProperty(string $propName):bool
106104

107105
public function isNonDb():bool
108106
{
109-
return isset($this->schema->{CustomSpecAttr::TABLE}) && $this->schema->{CustomSpecAttr::TABLE} === false;
107+
return
108+
isset($this->schema->{CustomSpecAttr::TABLE}) &&
109+
$this->schema->{CustomSpecAttr::TABLE} === false;
110110
}
111111

112112
public function resolveTableName(string $schemaName):string

src/lib/openapi/PropertySchema.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ public function __construct(SpecObjectInterface $property, string $name, Compone
145145
$property = $this->property;
146146
}
147147

148+
if ($this->getAttr(CustomSpecAttr::NO_RELATION)) {
149+
return;
150+
}
151+
148152
if ($property instanceof Reference) {
149153
$this->initReference();
150154
} elseif (
@@ -182,6 +186,10 @@ private function initReference():void
182186
if ($this->refSchema && $this->refSchema->isNonDb()) {
183187
$this->isNonDbReference = true;
184188
}
189+
if ($this->getAttr(CustomSpecAttr::NO_RELATION)) {
190+
$this->isReference = false;
191+
$this->isNonDbReference = true;
192+
}
185193
}
186194

187195
/**
@@ -191,6 +199,9 @@ private function initReference():void
191199
private function initItemsReference():void
192200
{
193201
$this->isItemsReference = true;
202+
if ($this->getAttr(CustomSpecAttr::NO_RELATION)) {
203+
$this->isItemsReference = false;
204+
}
194205
$items = $this->property->items ?? null;
195206
if (!$items) {
196207
return;
@@ -206,6 +217,9 @@ private function initItemsReference():void
206217
if ($this->refSchema && $this->refSchema->isNonDb()) {
207218
$this->isNonDbReference = true;
208219
}
220+
if ($this->getAttr(CustomSpecAttr::NO_RELATION)) {
221+
$this->isNonDbReference = true;
222+
}
209223
}
210224

211225
public function setName(string $name):void

tests/specs/issue_fix/23_consider_openapi_extension_x_no_relation_also_in_other_pertinent_place/index.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ components:
2525
type: array
2626
x-no-relation: true
2727
items:
28+
# type: string
2829
$ref: '#/components/schemas/Sample'
2930

3031
Sample:

0 commit comments

Comments
 (0)