From db0d315c918cdac3022ed4a5396d3edbabb2b2f8 Mon Sep 17 00:00:00 2001 From: "tuna.yu" Date: Wed, 2 Oct 2024 03:19:10 +0800 Subject: [PATCH] feat(OpenAPISpecWriter): add description to schema --- src/Writing/OpenAPISpecWriter.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Writing/OpenAPISpecWriter.php b/src/Writing/OpenAPISpecWriter.php index 27bcde10..11a6a84d 100644 --- a/src/Writing/OpenAPISpecWriter.php +++ b/src/Writing/OpenAPISpecWriter.php @@ -586,10 +586,13 @@ 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 = [ @@ -615,6 +618,9 @@ 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)) {