File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ public function generate(JsonApi $api): array
62
62
$ type = $ resource ->type ();
63
63
64
64
$ schemas [$ type ] = $ this ->buildSchema ($ resource , $ schema , [
65
+ 'required ' => ['id ' ],
65
66
'properties ' => ['id ' => ['type ' => 'string ' , 'readOnly ' => true ]],
66
67
]);
67
68
@@ -89,10 +90,17 @@ public function generate(JsonApi $api): array
89
90
90
91
private function buildSchema (Resource $ resource , array $ schema , array $ overrides = []): array
91
92
{
93
+ $ hasAttributes = !empty ($ schema ['attributes ' ]);
94
+ $ hasRelationships = !empty ($ schema ['relationships ' ]);
95
+
92
96
return array_replace_recursive (
93
97
[
94
98
'type ' => 'object ' ,
95
- 'required ' => ['type ' ],
99
+ 'required ' => array_filter ([
100
+ 'type ' ,
101
+ $ hasAttributes ? 'attributes ' : null ,
102
+ $ hasRelationships ? 'relationships ' : null ,
103
+ ]),
96
104
'properties ' => [
97
105
'type ' => ['type ' => 'string ' , 'const ' => $ resource ->type ()],
98
106
'attributes ' => ['type ' => 'object ' ] + ($ schema ['attributes ' ] ?? []),
You can’t perform that action at this time.
0 commit comments