@@ -119,11 +119,7 @@ public function buildSchema(string $className, string $format = 'jsonapi', strin
119
119
return $ schema ;
120
120
}
121
121
122
- if ('input ' === $ type ) {
123
- return $ schema ;
124
- }
125
-
126
- if ($ key = $ schema ->getRootDefinitionKey ()) {
122
+ if (($ key = $ schema ->getRootDefinitionKey ()) || ($ key = $ schema ->getItemsDefinitionKey ())) {
127
123
$ definitions = $ schema ->getDefinitions ();
128
124
$ properties = $ definitions [$ key ]['properties ' ] ?? [];
129
125
@@ -132,28 +128,11 @@ public function buildSchema(string $className, string $format = 'jsonapi', strin
132
128
return $ schema ;
133
129
}
134
130
135
- $ definitions [$ key ]['properties ' ] = [
136
- 'data ' => [
137
- 'type ' => 'object ' ,
138
- 'properties ' => $ this ->buildDefinitionPropertiesSchema ($ key , $ className , $ schema , $ serializerContext ),
139
- 'required ' => ['type ' , 'id ' ],
140
- ],
141
- ];
142
-
143
- return $ schema ;
144
- }
145
-
146
- if ($ key = $ schema ->getItemsDefinitionKey ()) {
147
- $ definitions = $ schema ->getDefinitions ();
148
- $ properties = $ definitions [$ key ]['properties ' ] ?? [];
131
+ $ definitions [$ key ]['properties ' ] = $ this ->buildDefinitionPropertiesSchema ($ key , $ className , $ schema , $ serializerContext );
149
132
150
- // Prevent reapplying
151
- if (isset ($ properties ['id ' ], $ properties ['type ' ]) || isset ($ properties ['data ' ])) {
133
+ if ($ schema ->getRootDefinitionKey ()) {
152
134
return $ schema ;
153
135
}
154
-
155
- $ definitions [$ key ]['properties ' ] = $ this ->buildDefinitionPropertiesSchema ($ key , $ className , $ schema , $ serializerContext );
156
- $ definitions [$ key ]['required ' ] = ['type ' , 'id ' ];
157
136
}
158
137
159
138
if (($ schema ['type ' ] ?? '' ) === 'array ' ) {
@@ -238,7 +217,13 @@ private function buildDefinitionPropertiesSchema(string $key, string $className,
238
217
unset($ definitions [$ key ]['required ' ]);
239
218
}
240
219
241
- return $ replacement ;
220
+ return [
221
+ 'data ' => [
222
+ 'type ' => 'object ' ,
223
+ 'properties ' => $ replacement ,
224
+ 'required ' => ['type ' , 'id ' ],
225
+ ],
226
+ ];
242
227
}
243
228
244
229
private function getRelationship (string $ resourceClass , string $ property , ?array $ serializerContext ): ?array
0 commit comments