@@ -393,18 +393,26 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
393
393
'The "openapiContext" option is deprecated, use "openapi" instead. '
394
394
);
395
395
$ openapiOperation = $ openapiOperation ->withRequestBody (new RequestBody ($ contextRequestBody ['description ' ] ?? '' , new \ArrayObject ($ contextRequestBody ['content ' ]), $ contextRequestBody ['required ' ] ?? false ));
396
- } elseif (
397
- null === $ openapiOperation -> getRequestBody () && \in_array ($ method , ['PATCH ' , 'PUT ' , 'POST ' ], true )
396
+ } else if (
397
+ \in_array ($ method , ['PATCH ' , 'PUT ' , 'POST ' ], true )
398
398
&& !(false === ($ input = $ operation ->getInput ()) || (\is_array ($ input ) && null === $ input ['class ' ]))
399
399
) {
400
- $ operationInputSchemas = [];
401
- foreach ($ requestMimeTypes as $ operationFormat ) {
402
- $ operationInputSchema = $ this ->jsonSchemaFactory ->buildSchema ($ resourceClass , $ operationFormat , Schema::TYPE_INPUT , $ operation , $ schema , null , $ forceSchemaCollection );
403
- $ operationInputSchemas [$ operationFormat ] = $ operationInputSchema ;
404
- $ this ->appendSchemaDefinitions ($ schemas , $ operationInputSchema ->getDefinitions ());
400
+ $ content = $ openapiOperation ->getRequestBody ()?->getContent();
401
+ if (null === $ content ) {
402
+ $ operationInputSchemas = [];
403
+ foreach ($ requestMimeTypes as $ operationFormat ) {
404
+ $ operationInputSchema = $ this ->jsonSchemaFactory ->buildSchema ($ resourceClass , $ operationFormat , Schema::TYPE_INPUT , $ operation , $ schema , null , $ forceSchemaCollection );
405
+ $ operationInputSchemas [$ operationFormat ] = $ operationInputSchema ;
406
+ $ this ->appendSchemaDefinitions ($ schemas , $ operationInputSchema ->getDefinitions ());
407
+ }
408
+ $ content = $ this ->buildContent ($ requestMimeTypes , $ operationInputSchemas );
405
409
}
406
410
407
- $ openapiOperation = $ openapiOperation ->withRequestBody (new RequestBody (sprintf ('The %s %s resource ' , 'POST ' === $ method ? 'new ' : 'updated ' , $ resourceShortName ), $ this ->buildContent ($ requestMimeTypes , $ operationInputSchemas ), true ));
411
+ $ openapiOperation = $ openapiOperation ->withRequestBody (new RequestBody (
412
+ description: $ openapiOperation ->getRequestBody ()?->getDescription() ?? sprintf ('The %s %s resource ' , 'POST ' === $ method ? 'new ' : 'updated ' , $ resourceShortName ),
413
+ content: $ content ,
414
+ required: $ openapiOperation ->getRequestBody ()?->getRequired() ?? true ,
415
+ ));
408
416
}
409
417
410
418
// TODO Remove in 4.0
@@ -758,17 +766,17 @@ private function hasParameter(Model\Operation $operation, Parameter $parameter):
758
766
private function mergeParameter (Parameter $ actual , Parameter $ defined ): Parameter
759
767
{
760
768
foreach ([
761
- 'name ' ,
762
- 'in ' ,
763
- 'description ' ,
764
- 'required ' ,
765
- 'deprecated ' ,
766
- 'allowEmptyValue ' ,
767
- 'style ' ,
768
- 'explode ' ,
769
- 'allowReserved ' ,
770
- 'example ' ,
771
- ] as $ method ) {
769
+ 'name ' ,
770
+ 'in ' ,
771
+ 'description ' ,
772
+ 'required ' ,
773
+ 'deprecated ' ,
774
+ 'allowEmptyValue ' ,
775
+ 'style ' ,
776
+ 'explode ' ,
777
+ 'allowReserved ' ,
778
+ 'example ' ,
779
+ ] as $ method ) {
772
780
$ newValue = $ defined ->{"get $ method " }();
773
781
if (null !== $ newValue && $ actual ->{"get $ method " }() !== $ newValue ) {
774
782
$ actual = $ actual ->{"with $ method " }($ newValue );
0 commit comments