@@ -496,22 +496,26 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
496496 }
497497 }
498498
499- private function buildOpenApiResponse (array $ existingResponses , int |string $ status , string $ description , ?Operation $ openapiOperation = null , ?HttpOperation $ operation = null , ?array $ responseMimeTypes = null , ?array $ operationOutputSchemas = null , ?ResourceMetadataCollection $ resourceMetadataCollection = null ): Operation
499+ /**
500+ * @param array<Response> $existingResponses
501+ *
502+ * @return Operation
503+ */
504+ private function buildOpenApiResponse (array $ existingResponses , int |string $ status , string $ description , Operation $ openapiOperation , ?HttpOperation $ operation = null , ?array $ responseMimeTypes = null , ?array $ operationOutputSchemas = null , ?ResourceMetadataCollection $ resourceMetadataCollection = null ): Operation
500505 {
501506 $ noOutput = \is_array ($ operation ?->getOutput()) && null === $ operation ->getOutput ()['class ' ];
502507
503- if (isset ($ existingResponses [$ status ])) {
504- return $ openapiOperation ;
505- }
506- $ responseLinks = $ responseContent = null ;
507- if ($ responseMimeTypes && $ operationOutputSchemas && !$ noOutput ) {
508- $ responseContent = $ this ->buildContent ($ responseMimeTypes , $ operationOutputSchemas );
508+ $ response = $ existingResponses [$ status ] ?? new Response ($ description );
509+
510+ if (!$ response ->getContent () && $ responseMimeTypes && $ operationOutputSchemas && !$ noOutput ) {
511+ $ response = $ response ->withContent ($ this ->buildContent ($ responseMimeTypes , $ operationOutputSchemas ));
509512 }
510- if ($ resourceMetadataCollection && $ operation ) {
511- $ responseLinks = $ this ->getLinks ($ resourceMetadataCollection , $ operation );
513+
514+ if (!$ response ->getLinks () && $ resourceMetadataCollection && $ operation ) {
515+ $ response = $ response ->withLinks ($ this ->getLinks ($ resourceMetadataCollection , $ operation ));
512516 }
513517
514- return $ openapiOperation ->withResponse ($ status , new Response ( $ description , $ responseContent , null , $ responseLinks ) );
518+ return $ openapiOperation ->withResponse ($ status , $ response );
515519 }
516520
517521 /**
0 commit comments