Skip to content

Commit 9a37739

Browse files
authored
Backport AugmentItems processor (#1863)
1 parent 3d83540 commit 9a37739

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

docs/examples/specs/api/annotations/ProductController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public function getProduct(?int $product_id)
6868
* @OA\MediaType(
6969
* mediaType="application/json",
7070
* @OA\Schema(
71-
* type="array",
7271
* @OA\Items(ref="#/components/schemas/Product")
7372
* )
7473
* )

docs/examples/specs/api/attributes/ProductController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public function getProduct(
4848
content: [new OAT\MediaType(
4949
mediaType: 'application/json',
5050
schema: new OAT\Schema(
51-
type: 'array',
5251
items: new OAT\Items(type: Product::class)
5352
)
5453
)]

docs/examples/specs/api/mixed/ProductController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public function getProduct(?int $product_id)
5757
* description="New product",
5858
* required=true,
5959
* @OA\JsonContent(
60-
* type="array",
6160
* @OA\Items(ref="#/components/schemas/Product")
6261
* )
6362
* )

src/Generator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ public function getProcessorPipeline(): Pipeline
237237
new Processors\BuildPaths(),
238238
new Processors\AugmentParameters(),
239239
new Processors\AugmentRefs(),
240+
new Processors\AugmentItems(),
240241
new Processors\MergeJsonContent(),
241242
new Processors\MergeXmlContent(),
242243
new Processors\AugmentMediaType(),

src/Processors/AugmentItems.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* @license Apache 2.0
5+
*/
6+
7+
namespace OpenApi\Processors;
8+
9+
use OpenApi\Analysis;
10+
use OpenApi\Annotations as OA;
11+
use OpenApi\Context;
12+
13+
/**
14+
* Use the Schema context to extract useful information and inject that into the annotation.
15+
*
16+
* Merges properties.
17+
*/
18+
class AugmentItems
19+
{
20+
public function __invoke(Analysis $analysis): void
21+
{
22+
$schemas = $analysis->getAnnotationsOfType(OA\Schema::class);
23+
24+
foreach ($schemas as $schema) {
25+
if ($schema->items instanceof OA\Items) {
26+
$schema->type = 'array';
27+
}
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)