Skip to content

Commit d883ccc

Browse files
committed
Fix to-one relationship schema
1 parent 56dd0c8 commit d883ccc

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/Schema/Field/ToOne.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,20 @@ public function deserializeValue(mixed $value, Context $context): mixed
6767

6868
protected function getDataSchema(JsonApi $api): array
6969
{
70-
return [
71-
'oneOf' => [
70+
$linkage = [
71+
'allOf' => [
72+
['$ref' => '#/components/schemas/jsonApiResourceIdentifier'],
7273
[
73-
'allOf' => [
74-
['$ref' => '#/components/schemas/jsonApiResourceIdentifier'],
75-
[
76-
'properties' => [
77-
'type' => [
78-
'type' => 'string',
79-
'enum' => $this->getRelatedResources($api),
80-
],
81-
],
74+
'properties' => [
75+
'type' => [
76+
'type' => 'string',
77+
'enum' => $this->getRelatedResources($api),
8278
],
8379
],
8480
],
85-
['type' => 'null'],
8681
],
8782
];
83+
84+
return $this->nullable ? ['oneOf' => [$linkage, ['type' => 'null']]] : $linkage;
8885
}
8986
}

0 commit comments

Comments
 (0)