diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e75081c..4ca4f9dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,9 +12,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Removed +# 4.40.0 (3 February 2024) +## Added +- Correctly list required fields for nested objects in OpenAPI spec (request bodies) [99b71ebf0](https://github.com/knuckleswtf/scribe/commit/99b71ebf058e679c3020779583be4de6b576ba3b) +- Add support for defining Groups and Subgroups as enums [#932](https://github.com/knuckleswtf/scribe/pull/932) + # 4.39.0 (31 December 2024) ## Added -- Correctly list required fields for nested objects in OpenAPI spec [#905](https://github.com/knuckleswtf/scribe/pull/905) +- Correctly list required fields for nested objects in OpenAPI spec (responses) [#905](https://github.com/knuckleswtf/scribe/pull/905) - Cursor pagination support in API responses (`cursorPaginate`/`paginate=cursor`) [#917](https://github.com/knuckleswtf/scribe/pull/917) ## Fixed diff --git a/src/Commands/GenerateDocumentation.php b/src/Commands/GenerateDocumentation.php index ab48547b..2d593840 100644 --- a/src/Commands/GenerateDocumentation.php +++ b/src/Commands/GenerateDocumentation.php @@ -63,6 +63,7 @@ public function handle(RouteMatcherInterface $routeMatcher, GroupedEndpointsFact $this->writeExampleCustomEndpoint(); } + /** @var Writer $writer */ $writer = app(Writer::class, ['config' => $this->docConfig, 'paths' => $this->paths]); $writer->writeDocs($groupedEndpoints); diff --git a/src/Scribe.php b/src/Scribe.php index 80259669..6f7f51d6 100644 --- a/src/Scribe.php +++ b/src/Scribe.php @@ -9,7 +9,7 @@ class Scribe { - public const VERSION = '4.39.0'; + public const VERSION = '4.40.0'; /** * Specify a callback that will be executed just before a response call is made diff --git a/src/Writing/OpenAPISpecWriter.php b/src/Writing/OpenAPISpecWriter.php index 48081ddf..b4b8a70f 100644 --- a/src/Writing/OpenAPISpecWriter.php +++ b/src/Writing/OpenAPISpecWriter.php @@ -543,7 +543,7 @@ public function generateFieldData($field): array return $fieldData; } else if ($field->type === 'object') { - return [ + $data = [ 'type' => 'object', 'description' => $field->description ?: '', 'example' => $field->example, @@ -553,6 +553,11 @@ public function generateFieldData($field): array })->all()), 'required' => collect($field->__fields)->filter(fn ($f) => $f['required'])->keys()->toArray(), ]; + // The spec doesn't allow for an empty `required` array. Must have something there. + if (empty($data['required'])) { + unset($data['required']); + } + return $data; } else { $schema = [ 'type' => static::normalizeTypeName($field->type),