|
6 | 6 |
|
7 | 7 | namespace OpenApi\Tests\Processors; |
8 | 8 |
|
| 9 | +use OpenApi\Annotations\Operation; |
| 10 | +use OpenApi\Annotations\Parameter; |
| 11 | +use OpenApi\Annotations\PathItem; |
9 | 12 | use OpenApi\Generator; |
| 13 | +use OpenApi\Processors\AugmentParameters; |
| 14 | +use OpenApi\Processors\BuildPaths; |
10 | 15 | use OpenApi\Processors\Concerns\DocblockTrait; |
| 16 | +use OpenApi\Processors\MergeIntoComponents; |
| 17 | +use OpenApi\Processors\MergeIntoOpenApi; |
11 | 18 | use OpenApi\Tests\OpenApiTestCase; |
12 | 19 |
|
13 | 20 | class AugmentParametersTest extends OpenApiTestCase |
@@ -56,4 +63,40 @@ public function testExtractTags(string $params, array $expected): void |
56 | 63 | $this->extractContent($mixed->comment, $tags); |
57 | 64 | $this->assertEquals($expected, $tags); |
58 | 65 | } |
| 66 | + |
| 67 | + /** |
| 68 | + * @requires PHP 8.1 |
| 69 | + */ |
| 70 | + public function testParameterNativeType(): void |
| 71 | + { |
| 72 | + $analysis = $this->analysisFromFixtures(['RequestUsingAttribute.php']); |
| 73 | + $analysis->process([ |
| 74 | + new MergeIntoOpenApi(), |
| 75 | + new MergeIntoComponents(), |
| 76 | + new BuildPaths(), |
| 77 | + new AugmentParameters(), |
| 78 | + ]); |
| 79 | + |
| 80 | + $findPathItemByPath = function (string $path) use ($analysis): PathItem { |
| 81 | + foreach ($analysis->openapi->paths as $pathItem) { |
| 82 | + if ($pathItem->path === $path) { |
| 83 | + return $pathItem; |
| 84 | + } |
| 85 | + } |
| 86 | + throw new \InvalidArgumentException('Not found'); |
| 87 | + }; |
| 88 | + $findParameterByName = function (string $name, Operation $operation): Parameter { |
| 89 | + foreach ($operation->parameters as $parameter) { |
| 90 | + if ($parameter->name === $name) { |
| 91 | + return $parameter; |
| 92 | + } |
| 93 | + } |
| 94 | + throw new \InvalidArgumentException('Not found'); |
| 95 | + }; |
| 96 | + |
| 97 | + $pathItem = $findPathItemByPath('/get/{id}'); |
| 98 | + $parameter = $findParameterByName('id', $pathItem->get); |
| 99 | + |
| 100 | + $this->assertEquals('integer', $parameter->schema->type); |
| 101 | + } |
59 | 102 | } |
0 commit comments