diff --git a/src/Writing/OpenAPISpecWriter.php b/src/Writing/OpenAPISpecWriter.php index fc89ace4..11a6a84d 100644 --- a/src/Writing/OpenAPISpecWriter.php +++ b/src/Writing/OpenAPISpecWriter.php @@ -586,19 +586,20 @@ public function generateSchemaForValue(mixed $value, OutputEndpointData $endpoin $properties[$subField] = $this->generateSchemaForValue($subValue, $endpoint, $subFieldPath); } - return [ + $schema = [ 'type' => 'object', 'properties' => $this->objectIfEmpty($properties), ]; + $this->setDescription($schema, $endpoint, $path); + + return $schema; } $schema = [ 'type' => $this->convertScribeOrPHPTypeToOpenAPIType(gettype($value)), 'example' => $value, ]; - if (isset($endpoint->responseFields[$path]->description)) { - $schema['description'] = $endpoint->responseFields[$path]->description; - } + $this->setDescription($schema, $endpoint, $path); if ($schema['type'] === 'array' && !empty($value)) { $schema['example'] = json_decode(json_encode($schema['example']), true); // Convert stdClass to array @@ -616,4 +617,14 @@ public function generateSchemaForValue(mixed $value, OutputEndpointData $endpoin return $schema; } + + /** + * Set the description for the schema. If the field has a description, it is set in the schema. + */ + private function setDescription(array &$schema, OutputEndpointData $endpoint, string $path): void + { + if (isset($endpoint->responseFields[$path]->description)) { + $schema['description'] = $endpoint->responseFields[$path]->description; + } + } }