@@ -119,11 +119,7 @@ public function buildSchema(string $className, string $format = 'jsonapi', strin
119119 return $ schema ;
120120 }
121121
122- if ('input ' === $ type ) {
123- return $ schema ;
124- }
125-
126- if ($ key = $ schema ->getRootDefinitionKey ()) {
122+ if (($ key = $ schema ->getRootDefinitionKey ()) || ($ key = $ schema ->getItemsDefinitionKey ())) {
127123 $ definitions = $ schema ->getDefinitions ();
128124 $ properties = $ definitions [$ key ]['properties ' ] ?? [];
129125
@@ -132,28 +128,11 @@ public function buildSchema(string $className, string $format = 'jsonapi', strin
132128 return $ schema ;
133129 }
134130
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 );
149132
150- // Prevent reapplying
151- if (isset ($ properties ['id ' ], $ properties ['type ' ]) || isset ($ properties ['data ' ])) {
133+ if ($ schema ->getRootDefinitionKey ()) {
152134 return $ schema ;
153135 }
154-
155- $ definitions [$ key ]['properties ' ] = $ this ->buildDefinitionPropertiesSchema ($ key , $ className , $ schema , $ serializerContext );
156- $ definitions [$ key ]['required ' ] = ['type ' , 'id ' ];
157136 }
158137
159138 if (($ schema ['type ' ] ?? '' ) === 'array ' ) {
@@ -238,7 +217,13 @@ private function buildDefinitionPropertiesSchema(string $key, string $className,
238217 unset($ definitions [$ key ]['required ' ]);
239218 }
240219
241- return $ replacement ;
220+ return [
221+ 'data ' => [
222+ 'type ' => 'object ' ,
223+ 'properties ' => $ replacement ,
224+ 'required ' => ['type ' , 'id ' ],
225+ ],
226+ ];
242227 }
243228
244229 private function getRelationship (string $ resourceClass , string $ property , ?array $ serializerContext ): ?array
0 commit comments