diff --git a/src/lib/openapi/PropertySchema.php b/src/lib/openapi/PropertySchema.php index 38f1873c..9ff64094 100644 --- a/src/lib/openapi/PropertySchema.php +++ b/src/lib/openapi/PropertySchema.php @@ -269,6 +269,24 @@ public function isRefPointerToSchema():bool public function isRefPointerToSelf():bool { + $allOfInSchema = null; + if (isset($this->schema->getSchema()->properties[$this->name]->allOf)) { + $allOfInSchema = $this->schema->getSchema()->properties[$this->name]->allOf; + } + + if ($allOfInSchema) { # fixes https://github.com/php-openapi/yii2-openapi/issues/68 + $refCounter = 0; + foreach ($allOfInSchema as $aAllOfElement) { + if ($aAllOfElement instanceof Reference) { + $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; diff --git a/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/base/Invoice.php b/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/base/Invoice.php index 73190e01..8e944b9b 100644 --- a/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/base/Invoice.php +++ b/tests/specs/issue_fix/52_bug_dependenton_allof_with_x_faker_false/mysql/models/base/Invoice.php @@ -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'); - } }