@@ -181,18 +181,31 @@ private function getPropertyNameCollectionFactoryContext(ResourceMetadata $resou
181
181
*/
182
182
private function getHydraProperties (string $ resourceClass , ResourceMetadata $ resourceMetadata , string $ shortName , string $ prefixedShortName , array $ context ): array
183
183
{
184
- $ properties = [];
185
- foreach ($ this ->propertyNameCollectionFactory ->create ($ resourceClass , $ this ->getPropertyNameCollectionFactoryContext ($ resourceMetadata )) as $ propertyName ) {
186
- $ propertyMetadata = $ this ->propertyMetadataFactory ->create ($ resourceClass , $ propertyName );
187
- if (true === $ propertyMetadata ->isIdentifier () && false === $ propertyMetadata ->isWritable ()) {
188
- continue ;
184
+ $ classes = [];
185
+ foreach ($ resourceMetadata ->getCollectionOperations () as $ operationName => $ operation ) {
186
+ if (false !== $ class = $ resourceMetadata ->getCollectionOperationAttribute ($ operationName , 'input_class ' , $ resourceClass , true )) {
187
+ $ classes [$ class ] = true ;
189
188
}
190
189
191
- if ($ this -> nameConverter ) {
192
- $ propertyName = $ this -> nameConverter -> normalize ( $ propertyName , $ resourceClass , self :: FORMAT , $ context ) ;
190
+ if (false !== $ class = $ resourceMetadata -> getCollectionOperationAttribute ( $ operationName , ' output_class ' , $ resourceClass , true ) ) {
191
+ $ classes [ $ class ] = true ;
193
192
}
193
+ }
194
194
195
- $ properties [] = $ this ->getProperty ($ propertyMetadata , $ propertyName , $ prefixedShortName , $ shortName );
195
+ $ properties = [];
196
+ foreach ($ classes as $ class => $ v ) {
197
+ foreach ($ this ->propertyNameCollectionFactory ->create ($ class , $ this ->getPropertyNameCollectionFactoryContext ($ resourceMetadata )) as $ propertyName ) {
198
+ $ propertyMetadata = $ this ->propertyMetadataFactory ->create ($ class , $ propertyName );
199
+ if (true === $ propertyMetadata ->isIdentifier () && false === $ propertyMetadata ->isWritable ()) {
200
+ continue ;
201
+ }
202
+
203
+ if ($ this ->nameConverter ) {
204
+ $ propertyName = $ this ->nameConverter ->normalize ($ propertyName , $ class , self ::FORMAT , $ context );
205
+ }
206
+
207
+ $ properties [] = $ this ->getProperty ($ propertyMetadata , $ propertyName , $ prefixedShortName , $ shortName );
208
+ }
196
209
}
197
210
198
211
return $ properties ;
@@ -244,6 +257,8 @@ private function getHydraOperation(string $resourceClass, ResourceMetadata $reso
244
257
}
245
258
246
259
$ shortName = $ resourceMetadata ->getShortName ();
260
+ $ inputClass = $ resourceMetadata ->getTypedOperationAttribute ($ operationType , $ operationName , 'input_class ' , null , true );
261
+ $ outputClass = $ resourceMetadata ->getTypedOperationAttribute ($ operationType , $ operationName , 'output_class ' , null , true );
247
262
248
263
if ('GET ' === $ method && OperationType::COLLECTION === $ operationType ) {
249
264
$ hydraOperation += [
@@ -255,34 +270,34 @@ private function getHydraOperation(string $resourceClass, ResourceMetadata $reso
255
270
$ hydraOperation += [
256
271
'@type ' => ['hydra:Operation ' , 'schema:FindAction ' ],
257
272
'hydra:title ' => $ subresourceMetadata && $ subresourceMetadata ->isCollection () ? "Retrieves the collection of $ shortName resources. " : "Retrieves a $ shortName resource. " ,
258
- 'returns ' => "# $ shortName " ,
273
+ 'returns ' => false === $ outputClass ? ' owl:Nothing ' : "# $ shortName " ,
259
274
];
260
275
} elseif ('GET ' === $ method ) {
261
276
$ hydraOperation += [
262
277
'@type ' => ['hydra:Operation ' , 'schema:FindAction ' ],
263
278
'hydra:title ' => "Retrieves $ shortName resource. " ,
264
- 'returns ' => $ prefixedShortName ,
279
+ 'returns ' => false === $ outputClass ? ' owl:Nothing ' : $ prefixedShortName ,
265
280
];
266
281
} elseif ('PATCH ' === $ method ) {
267
282
$ hydraOperation += [
268
283
'@type ' => 'hydra:Operation ' ,
269
284
'hydra:title ' => "Updates the $ shortName resource. " ,
270
- 'returns ' => $ prefixedShortName ,
271
- 'expects ' => $ prefixedShortName ,
285
+ 'returns ' => false === $ outputClass ? ' owl:Nothing ' : $ prefixedShortName ,
286
+ 'expects ' => false === $ inputClass ? ' owl:Nothing ' : $ prefixedShortName ,
272
287
];
273
288
} elseif ('POST ' === $ method ) {
274
289
$ hydraOperation += [
275
290
'@type ' => ['hydra:Operation ' , 'schema:CreateAction ' ],
276
291
'hydra:title ' => "Creates a $ shortName resource. " ,
277
- 'returns ' => $ prefixedShortName ,
278
- 'expects ' => $ prefixedShortName ,
292
+ 'returns ' => false === $ outputClass ? ' owl:Nothing ' : $ prefixedShortName ,
293
+ 'expects ' => false === $ inputClass ? ' owl:Nothing ' : $ prefixedShortName ,
279
294
];
280
295
} elseif ('PUT ' === $ method ) {
281
296
$ hydraOperation += [
282
297
'@type ' => ['hydra:Operation ' , 'schema:ReplaceAction ' ],
283
298
'hydra:title ' => "Replaces the $ shortName resource. " ,
284
- 'returns ' => $ prefixedShortName ,
285
- 'expects ' => $ prefixedShortName ,
299
+ 'returns ' => false === $ outputClass ? ' owl:Nothing ' : $ prefixedShortName ,
300
+ 'expects ' => false === $ inputClass ? ' owl:Nothing ' : $ prefixedShortName ,
286
301
];
287
302
} elseif ('DELETE ' === $ method ) {
288
303
$ hydraOperation += [
0 commit comments