Skip to content

Commit 918f5bf

Browse files
committed
Handle nullable value
1 parent 7d0f71f commit 918f5bf

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/lib/AttributeResolver.php

+16-11
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,7 @@ public function resolve(): DbModel
8787
/** @var $property PropertySchema */
8888

8989
$isRequired = $this->componentSchema->isRequiredProperty($property->getName());
90-
$nullableValue = false; # https://github.com/OAI/OpenAPI-Specification/blob/main/proposals/2019-10-31-Clarify-Nullable.md
91-
92-
if ($property->hasAttr('nullable')) {
93-
if ($property->getAttr('nullable') === true) {
94-
$nullableValue = true;
95-
}
96-
}
90+
$nullableValue = $this->nullableValue($property);
9791

9892
if ($this->isJunctionSchema) {
9993
$this->resolveJunctionTableProperty($property, $isRequired);
@@ -214,10 +208,7 @@ protected function resolveProperty(
214208
$nullableValue = 'ARG_ABSENT'
215209
): void {
216210
if ($nullableValue === 'ARG_ABSENT') {
217-
$nullableValue = false;
218-
if ($property->hasAttr('nullable') && $property->getAttr('nullable') === true) {
219-
$nullableValue = true;
220-
}
211+
$nullableValue = $this->nullableValue($property);
221212
}
222213
$attribute = Yii::createObject(Attribute::class, [$property->getName()]);
223214

@@ -542,4 +533,18 @@ public function addInverseRelation(
542533
$inverseRelation->setInverse($property->getName());
543534
$this->inverseRelations[$relatedClassName][] = $inverseRelation;
544535
}
536+
537+
/**
538+
* Compute nullable value
539+
*/
540+
private function nullableValue(PropertySchema $property): bool
541+
{
542+
$nullableValue = false; # https://github.com/OAI/OpenAPI-Specification/blob/main/proposals/2019-10-31-Clarify-Nullable.md
543+
544+
if ($property->hasAttr('nullable') && $property->getAttr('nullable') === true) {
545+
$nullableValue = true;
546+
}
547+
548+
return $nullableValue;
549+
}
545550
}

0 commit comments

Comments
 (0)