@@ -197,7 +197,7 @@ protected function generateEndpointParametersSpec(OutputEndpointData $endpoint):
197
197
return $ parameters ;
198
198
}
199
199
200
- protected function generateEndpointRequestBodySpec (OutputEndpointData $ endpoint )
200
+ protected function generateEndpointRequestBodySpec (OutputEndpointData $ endpoint ): array | \ stdClass
201
201
{
202
202
$ body = [];
203
203
@@ -405,9 +405,9 @@ protected function generateResponseContentSpec(?string $responseContent, OutputE
405
405
406
406
case 'object ' :
407
407
$ properties = collect ($ decoded )->mapWithKeys (function ($ value , $ key ) use ($ endpoint ) {
408
- return [$ key => $ this ->generateSchemaForValue ($ value , $ endpoint , $ key )];
408
+ return [$ key => $ this ->generateSchemaForResponseValue ($ value , $ endpoint , $ key )];
409
409
})->toArray ();
410
- $ required = $ this ->filterRequiredFields ($ endpoint , array_keys ($ properties ));
410
+ $ required = $ this ->filterRequiredResponseFields ($ endpoint , array_keys ($ properties ));
411
411
412
412
$ data = [
413
413
'application/json ' => [
@@ -551,6 +551,7 @@ public function generateFieldData($field): array
551
551
'properties ' => $ this ->objectIfEmpty (collect ($ field ->__fields )->mapWithKeys (function ($ subfield , $ subfieldName ) {
552
552
return [$ subfieldName => $ this ->generateFieldData ($ subfield )];
553
553
})->all ()),
554
+ 'required ' => collect ($ field ->__fields )->filter (fn ($ f ) => $ f ['required ' ])->keys ()->toArray (),
554
555
];
555
556
} else {
556
557
$ schema = [
@@ -589,17 +590,18 @@ protected function objectIfEmpty(array $field): array|\stdClass
589
590
* object)}, and possibly a description for each property. The $endpoint and $path are used for looking up response
590
591
* field descriptions.
591
592
*/
592
- public function generateSchemaForValue (mixed $ value , OutputEndpointData $ endpoint , string $ path ): array
593
+ public function generateSchemaForResponseValue (mixed $ value , OutputEndpointData $ endpoint , string $ path ): array
593
594
{
595
+ // If $value is a JSON object
594
596
if ($ value instanceof \stdClass) {
595
597
$ value = (array )$ value ;
596
598
$ properties = [];
597
599
// Recurse into the object
598
600
foreach ($ value as $ subField => $ subValue ) {
599
601
$ subFieldPath = sprintf ('%s.%s ' , $ path , $ subField );
600
- $ properties [$ subField ] = $ this ->generateSchemaForValue ($ subValue , $ endpoint , $ subFieldPath );
602
+ $ properties [$ subField ] = $ this ->generateSchemaForResponseValue ($ subValue , $ endpoint , $ subFieldPath );
601
603
}
602
- $ required = $ this ->filterRequiredFields ($ endpoint , array_keys ($ properties ), $ path );
604
+ $ required = $ this ->filterRequiredResponseFields ($ endpoint , array_keys ($ properties ), $ path );
603
605
604
606
$ schema = [
605
607
'type ' => 'object ' ,
@@ -633,10 +635,10 @@ public function generateSchemaForValue(mixed $value, OutputEndpointData $endpoin
633
635
634
636
if ($ typeOfEachItem === 'object ' ) {
635
637
$ schema ['items ' ]['properties ' ] = collect ($ sample )->mapWithKeys (function ($ v , $ k ) use ($ endpoint , $ path ) {
636
- return [$ k => $ this ->generateSchemaForValue ($ v , $ endpoint , "$ path. $ k " )];
638
+ return [$ k => $ this ->generateSchemaForResponseValue ($ v , $ endpoint , "$ path. $ k " )];
637
639
})->toArray ();
638
640
639
- $ required = $ this ->filterRequiredFields ($ endpoint , array_keys ($ schema ['items ' ]['properties ' ]), $ path );
641
+ $ required = $ this ->filterRequiredResponseFields ($ endpoint , array_keys ($ schema ['items ' ]['properties ' ]), $ path );
640
642
if ($ required ) {
641
643
$ schema ['required ' ] = $ required ;
642
644
}
@@ -649,7 +651,7 @@ public function generateSchemaForValue(mixed $value, OutputEndpointData $endpoin
649
651
/**
650
652
* Given an enpoint and a set of object keys at a path, return the properties that are specified as required.
651
653
*/
652
- public function filterRequiredFields (OutputEndpointData $ endpoint , array $ properties , string $ path = '' ): array
654
+ public function filterRequiredResponseFields (OutputEndpointData $ endpoint , array $ properties , string $ path = '' ): array
653
655
{
654
656
$ required = [];
655
657
foreach ($ properties as $ property ) {
0 commit comments