@@ -364,14 +364,12 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
364
364
$ existingResponses = $ openapiOperation ->getResponses () ?: [];
365
365
$ overrideResponses = $ operation ->getExtraProperties ()[self ::OVERRIDE_OPENAPI_RESPONSES ] ?? $ this ->openApiOptions ->getOverrideResponses ();
366
366
$ errors = null ;
367
+ /** @var array<class-string|string, Error> */
368
+ $ errorOperations = [];
367
369
if ($ operation instanceof HttpOperation && null !== ($ errors = $ operation ->getErrors ())) {
368
- /** @var array<class-string|string, Error> */
369
- $ errorOperations = [];
370
370
foreach ($ errors as $ error ) {
371
371
$ errorOperations [$ error ] = $ this ->getErrorResource ($ error );
372
372
}
373
-
374
- $ openapiOperation = $ this ->addOperationErrors ($ openapiOperation , $ errorOperations , $ resourceMetadataCollection , $ schema , $ schemas , $ operation );
375
373
}
376
374
377
375
if ($ overrideResponses || !$ existingResponses ) {
@@ -385,24 +383,16 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
385
383
$ successStatus = (string ) $ operation ->getStatus () ?: 201 ;
386
384
$ openapiOperation = $ this ->buildOpenApiResponse ($ existingResponses , $ successStatus , \sprintf ('%s resource created ' , $ resourceShortName ), $ openapiOperation , $ operation , $ responseMimeTypes , $ operationOutputSchemas , $ resourceMetadataCollection );
387
385
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 ;
394
388
break ;
395
389
case 'PATCH ' :
396
390
case 'PUT ' :
397
391
$ successStatus = (string ) $ operation ->getStatus () ?: 200 ;
398
392
$ openapiOperation = $ this ->buildOpenApiResponse ($ existingResponses , $ successStatus , \sprintf ('%s resource updated ' , $ resourceShortName ), $ openapiOperation , $ operation , $ responseMimeTypes , $ operationOutputSchemas , $ resourceMetadataCollection );
399
393
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 ;
406
396
break ;
407
397
case 'DELETE ' :
408
398
$ successStatus = (string ) $ operation ->getStatus () ?: 204 ;
@@ -412,15 +402,15 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
412
402
}
413
403
414
404
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 ' );
418
406
}
419
407
420
408
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 );
424
414
}
425
415
426
416
if (!$ openapiOperation ->getResponses ()) {
0 commit comments