@@ -269,28 +269,32 @@ private function getMetadata(string $className, string $type = Schema::TYPE_OUTP
269
269
];
270
270
}
271
271
272
- // The best here is to use an Operation when calling `buildSchema`, we try to do a smart guess otherwise
273
- if (!$ operation || !$ operation ->getClass ()) {
274
- $ resourceMetadataCollection = $ this ->resourceMetadataFactory ->create ($ className );
275
-
276
- if ($ operation && $ operation ->getName ()) {
277
- $ operation = $ resourceMetadataCollection ->getOperation ($ operation ->getName ());
278
- } else {
279
- // Guess the operation and use the first one that matches criterias
280
- foreach ($ resourceMetadataCollection as $ resourceMetadata ) {
281
- foreach ($ resourceMetadata ->getOperations () ?? [] as $ op ) {
282
- if ($ operation instanceof CollectionOperationInterface && $ op instanceof CollectionOperationInterface) {
283
- $ operation = $ op ;
284
- break 2 ;
285
- }
286
-
287
- if (Schema::TYPE_INPUT === $ type && \in_array ($ op ->getMethod (), ['POST ' , 'PATCH ' , 'PUT ' ], true )) {
288
- $ operation = $ op ;
289
- break 2 ;
290
- }
291
-
292
- if (!$ operation ) {
293
- $ operation = new HttpOperation ();
272
+ if (null === $ operation ) {
273
+ $ operation = $ this ->resourceMetadataFactory ->create ($ className )->getOperation ();
274
+ } else {
275
+ // The best here is to use an Operation when calling `buildSchema`, we try to do a smart guess otherwise
276
+ if (!$ operation ->getClass ()) {
277
+ $ resourceMetadataCollection = $ this ->resourceMetadataFactory ->create ($ className );
278
+
279
+ if ($ operation ->getName ()) {
280
+ $ operation = $ resourceMetadataCollection ->getOperation ($ operation ->getName ());
281
+ } else {
282
+ // Guess the operation and use the first one that matches criterias
283
+ foreach ($ resourceMetadataCollection as $ resourceMetadata ) {
284
+ foreach ($ resourceMetadata ->getOperations () ?? [] as $ op ) {
285
+ if ($ operation instanceof CollectionOperationInterface && $ op instanceof CollectionOperationInterface) {
286
+ $ operation = $ op ;
287
+ break 2 ;
288
+ }
289
+
290
+ if (Schema::TYPE_INPUT === $ type && \in_array ($ op ->getMethod (), ['POST ' , 'PATCH ' , 'PUT ' ], true )) {
291
+ $ operation = $ op ;
292
+ break 2 ;
293
+ }
294
+
295
+ if (!$ operation ) {
296
+ $ operation = new HttpOperation ();
297
+ }
294
298
}
295
299
}
296
300
}
0 commit comments