@@ -364,14 +364,12 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
364364 $ existingResponses = $ openapiOperation ->getResponses () ?: [];
365365 $ overrideResponses = $ operation ->getExtraProperties ()[self ::OVERRIDE_OPENAPI_RESPONSES ] ?? $ this ->openApiOptions ->getOverrideResponses ();
366366 $ errors = null ;
367+ /** @var array<class-string|string, Error> */
368+ $ errorOperations = [];
367369 if ($ operation instanceof HttpOperation && null !== ($ errors = $ operation ->getErrors ())) {
368- /** @var array<class-string|string, Error> */
369- $ errorOperations = [];
370370 foreach ($ errors as $ error ) {
371371 $ errorOperations [$ error ] = $ this ->getErrorResource ($ error );
372372 }
373-
374- $ openapiOperation = $ this ->addOperationErrors ($ openapiOperation , $ errorOperations , $ resourceMetadataCollection , $ schema , $ schemas , $ operation );
375373 }
376374
377375 if ($ overrideResponses || !$ existingResponses ) {
@@ -385,24 +383,16 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
385383 $ successStatus = (string ) $ operation ->getStatus () ?: 201 ;
386384 $ openapiOperation = $ this ->buildOpenApiResponse ($ existingResponses , $ successStatus , \sprintf ('%s resource created ' , $ resourceShortName ), $ openapiOperation , $ operation , $ responseMimeTypes , $ operationOutputSchemas , $ resourceMetadataCollection );
387385
388- if (null === $ errors ) {
389- $ openapiOperation = $ this ->addOperationErrors ($ openapiOperation , [
390- $ defaultError ->withStatus (400 )->withDescription ('Invalid input ' ),
391- $ defaultValidationError ,
392- ], $ resourceMetadataCollection , $ schema , $ schemas , $ operation );
393- }
386+ $ errorOperations [] = $ defaultError ->withStatus (400 )->withDescription ('Invalid input ' );
387+ $ errorOperations [] = $ defaultValidationError ;
394388 break ;
395389 case 'PATCH ' :
396390 case 'PUT ' :
397391 $ successStatus = (string ) $ operation ->getStatus () ?: 200 ;
398392 $ openapiOperation = $ this ->buildOpenApiResponse ($ existingResponses , $ successStatus , \sprintf ('%s resource updated ' , $ resourceShortName ), $ openapiOperation , $ operation , $ responseMimeTypes , $ operationOutputSchemas , $ resourceMetadataCollection );
399393
400- if (null === $ errors ) {
401- $ openapiOperation = $ this ->addOperationErrors ($ openapiOperation , [
402- $ defaultError ->withStatus (400 )->withDescription ('Invalid input ' ),
403- $ defaultValidationError ,
404- ], $ resourceMetadataCollection , $ schema , $ schemas , $ operation );
405- }
394+ $ errorOperations [] = $ defaultError ->withStatus (400 )->withDescription ('Invalid input ' );
395+ $ errorOperations [] = $ defaultValidationError ;
406396 break ;
407397 case 'DELETE ' :
408398 $ successStatus = (string ) $ operation ->getStatus () ?: 204 ;
@@ -412,15 +402,15 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
412402 }
413403
414404 if ($ overrideResponses && !isset ($ existingResponses [403 ]) && $ operation ->getSecurity ()) {
415- $ openapiOperation = $ this ->addOperationErrors ($ openapiOperation , [
416- $ defaultError ->withStatus (403 )->withDescription ('Forbidden ' ),
417- ], $ resourceMetadataCollection , $ schema , $ schemas , $ operation );
405+ $ errorOperations [] = $ defaultError ->withStatus (403 )->withDescription ('Forbidden ' );
418406 }
419407
420408 if ($ overrideResponses && !$ operation instanceof CollectionOperationInterface && 'POST ' !== $ operation ->getMethod () && !isset ($ existingResponses [404 ]) && null === $ errors ) {
421- $ openapiOperation = $ this ->addOperationErrors ($ openapiOperation , [
422- $ defaultError ->withStatus (404 )->withDescription ('Not found ' ),
423- ], $ resourceMetadataCollection , $ schema , $ schemas , $ operation );
409+ $ errorOperations [] = $ defaultError ->withStatus (404 )->withDescription ('Not found ' );
410+ }
411+
412+ if ($ errorOperations ) {
413+ $ openapiOperation = $ this ->addOperationErrors ($ openapiOperation , $ errorOperations , $ resourceMetadataCollection , $ schema , $ schemas , $ operation );
424414 }
425415
426416 if (!$ openapiOperation ->getResponses ()) {
0 commit comments