|
@@ -197,7 +197,7 @@ class OpenAPISpecWriter
|
|
|
return $parameters;
|
|
|
}
|
|
|
|
|
|
- protected function generateEndpointRequestBodySpec(OutputEndpointData $endpoint)
|
|
|
+ protected function generateEndpointRequestBodySpec(OutputEndpointData $endpoint): array|\stdClass
|
|
|
{
|
|
|
$body = [];
|
|
|
|
|
@@ -405,9 +405,9 @@ class OpenAPISpecWriter
|
|
|
|
|
|
case 'object':
|
|
|
$properties = collect($decoded)->mapWithKeys(function ($value, $key) use ($endpoint) {
|
|
|
- return [$key => $this->generateSchemaForValue($value, $endpoint, $key)];
|
|
|
+ return [$key => $this->generateSchemaForResponseValue($value, $endpoint, $key)];
|
|
|
})->toArray();
|
|
|
- $required = $this->filterRequiredFields($endpoint, array_keys($properties));
|
|
|
+ $required = $this->filterRequiredResponseFields($endpoint, array_keys($properties));
|
|
|
|
|
|
$data = [
|
|
|
'application/json' => [
|
|
@@ -551,6 +551,7 @@ class OpenAPISpecWriter
|
|
|
'properties' => $this->objectIfEmpty(collect($field->__fields)->mapWithKeys(function ($subfield, $subfieldName) {
|
|
|
return [$subfieldName => $this->generateFieldData($subfield)];
|
|
|
})->all()),
|
|
|
+ 'required' => collect($field->__fields)->filter(fn ($f) => $f['required'])->keys()->toArray(),
|
|
|
];
|
|
|
} else {
|
|
|
$schema = [
|
|
@@ -589,17 +590,18 @@ class OpenAPISpecWriter
|
|
|
* object)}, and possibly a description for each property. The $endpoint and $path are used for looking up response
|
|
|
* field descriptions.
|
|
|
*/
|
|
|
- public function generateSchemaForValue(mixed $value, OutputEndpointData $endpoint, string $path): array
|
|
|
+ public function generateSchemaForResponseValue(mixed $value, OutputEndpointData $endpoint, string $path): array
|
|
|
{
|
|
|
+ // If $value is a JSON object
|
|
|
if ($value instanceof \stdClass) {
|
|
|
$value = (array)$value;
|
|
|
$properties = [];
|
|
|
// Recurse into the object
|
|
|
foreach ($value as $subField => $subValue) {
|
|
|
$subFieldPath = sprintf('%s.%s', $path, $subField);
|
|
|
- $properties[$subField] = $this->generateSchemaForValue($subValue, $endpoint, $subFieldPath);
|
|
|
+ $properties[$subField] = $this->generateSchemaForResponseValue($subValue, $endpoint, $subFieldPath);
|
|
|
}
|
|
|
- $required = $this->filterRequiredFields($endpoint, array_keys($properties), $path);
|
|
|
+ $required = $this->filterRequiredResponseFields($endpoint, array_keys($properties), $path);
|
|
|
|
|
|
$schema = [
|
|
|
'type' => 'object',
|
|
@@ -633,10 +635,10 @@ class OpenAPISpecWriter
|
|
|
|
|
|
if ($typeOfEachItem === 'object') {
|
|
|
$schema['items']['properties'] = collect($sample)->mapWithKeys(function ($v, $k) use ($endpoint, $path) {
|
|
|
- return [$k => $this->generateSchemaForValue($v, $endpoint, "$path.$k")];
|
|
|
+ return [$k => $this->generateSchemaForResponseValue($v, $endpoint, "$path.$k")];
|
|
|
})->toArray();
|
|
|
|
|
|
- $required = $this->filterRequiredFields($endpoint, array_keys($schema['items']['properties']), $path);
|
|
|
+ $required = $this->filterRequiredResponseFields($endpoint, array_keys($schema['items']['properties']), $path);
|
|
|
if ($required) {
|
|
|
$schema['required'] = $required;
|
|
|
}
|
|
@@ -649,7 +651,7 @@ class OpenAPISpecWriter
|
|
|
/**
|
|
|
* Given an enpoint and a set of object keys at a path, return the properties that are specified as required.
|
|
|
*/
|
|
|
- public function filterRequiredFields(OutputEndpointData $endpoint, array $properties, string $path = ''): array
|
|
|
+ public function filterRequiredResponseFields(OutputEndpointData $endpoint, array $properties, string $path = ''): array
|
|
|
{
|
|
|
$required = [];
|
|
|
foreach ($properties as $property) {
|