@@ -197,7 +197,7 @@ protected function generateEndpointParametersSpec(OutputEndpointData $endpoint):
197197 return $ parameters ;
198198 }
199199
200- protected function generateEndpointRequestBodySpec (OutputEndpointData $ endpoint )
200+ protected function generateEndpointRequestBodySpec (OutputEndpointData $ endpoint ): array | \ stdClass
201201 {
202202 $ body = [];
203203
@@ -405,9 +405,9 @@ protected function generateResponseContentSpec(?string $responseContent, OutputE
405405
406406 case 'object ' :
407407 $ 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 )];
409409 })->toArray ();
410- $ required = $ this ->filterRequiredFields ($ endpoint , array_keys ($ properties ));
410+ $ required = $ this ->filterRequiredResponseFields ($ endpoint , array_keys ($ properties ));
411411
412412 $ data = [
413413 'application/json ' => [
@@ -551,6 +551,7 @@ public function generateFieldData($field): array
551551 'properties ' => $ this ->objectIfEmpty (collect ($ field ->__fields )->mapWithKeys (function ($ subfield , $ subfieldName ) {
552552 return [$ subfieldName => $ this ->generateFieldData ($ subfield )];
553553 })->all ()),
554+ 'required ' => collect ($ field ->__fields )->filter (fn ($ f ) => $ f ['required ' ])->keys ()->toArray (),
554555 ];
555556 } else {
556557 $ schema = [
@@ -589,17 +590,18 @@ protected function objectIfEmpty(array $field): array|\stdClass
589590 * object)}, and possibly a description for each property. The $endpoint and $path are used for looking up response
590591 * field descriptions.
591592 */
592- public function generateSchemaForValue (mixed $ value , OutputEndpointData $ endpoint , string $ path ): array
593+ public function generateSchemaForResponseValue (mixed $ value , OutputEndpointData $ endpoint , string $ path ): array
593594 {
595+ // If $value is a JSON object
594596 if ($ value instanceof \stdClass) {
595597 $ value = (array )$ value ;
596598 $ properties = [];
597599 // Recurse into the object
598600 foreach ($ value as $ subField => $ subValue ) {
599601 $ subFieldPath = sprintf ('%s.%s ' , $ path , $ subField );
600- $ properties [$ subField ] = $ this ->generateSchemaForValue ($ subValue , $ endpoint , $ subFieldPath );
602+ $ properties [$ subField ] = $ this ->generateSchemaForResponseValue ($ subValue , $ endpoint , $ subFieldPath );
601603 }
602- $ required = $ this ->filterRequiredFields ($ endpoint , array_keys ($ properties ), $ path );
604+ $ required = $ this ->filterRequiredResponseFields ($ endpoint , array_keys ($ properties ), $ path );
603605
604606 $ schema = [
605607 'type ' => 'object ' ,
@@ -633,10 +635,10 @@ public function generateSchemaForValue(mixed $value, OutputEndpointData $endpoin
633635
634636 if ($ typeOfEachItem === 'object ' ) {
635637 $ 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 " )];
637639 })->toArray ();
638640
639- $ required = $ this ->filterRequiredFields ($ endpoint , array_keys ($ schema ['items ' ]['properties ' ]), $ path );
641+ $ required = $ this ->filterRequiredResponseFields ($ endpoint , array_keys ($ schema ['items ' ]['properties ' ]), $ path );
640642 if ($ required ) {
641643 $ schema ['required ' ] = $ required ;
642644 }
@@ -649,7 +651,7 @@ public function generateSchemaForValue(mixed $value, OutputEndpointData $endpoin
649651 /**
650652 * Given an enpoint and a set of object keys at a path, return the properties that are specified as required.
651653 */
652- public function filterRequiredFields (OutputEndpointData $ endpoint , array $ properties , string $ path = '' ): array
654+ public function filterRequiredResponseFields (OutputEndpointData $ endpoint , array $ properties , string $ path = '' ): array
653655 {
654656 $ required = [];
655657 foreach ($ properties as $ property ) {
0 commit comments