Skip to content
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

Resolve: Inverse relation must not be generated for self-referenced component schema #68 #71

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
16 changes: 16 additions & 0 deletions src/lib/openapi/PropertySchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,22 @@ public function isRefPointerToSchema():bool

public function isRefPointerToSelf():bool
{
$schema = Json::decode(Json::encode($this->schema->getSchema()->getSerializableData()));
SOHELAHMED7 marked this conversation as resolved.
Show resolved Hide resolved

if (isset($schema['properties'][$this->name]['allOf'])) { # fixes https://github.com/php-openapi/yii2-openapi/issues/68
$allOfs = $schema['properties'][$this->name]['allOf'];
$refCounter = 0;
foreach ($allOfs as $allOf) {
if (isset($allOf['$ref'])) {
$refCounter++;
}
}
if ($refCounter === 1) {
return $this->isRefPointerToSchema()
&& str_ends_with($this->refPointer, '/' . $this->schema->getName()) !== false;
}
}

return $this->isRefPointerToSchema()
&& strpos($this->refPointer, '/' . $this->schema->getName() . '/') !== false
&& strpos($this->refPointer, '/properties/') !== false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,4 @@ public function getAnimal()
{
return $this->hasOne(\app\models\Animal::class, ['id' => 'animal_id']);
}

public function getInvoice()
{
return $this->hasOne(\app\models\Invoice::class, ['reference_invoice_id' => 'id'])->inverseOf('reference_invoice');
}

public function getInvoice2()
{
return $this->hasOne(\app\models\Invoice::class, ['reference_invoice_2_id' => 'id'])->inverseOf('reference_invoice_2');
}
}
Loading