Skip to content

Commit 471f2e7

Browse files
authored
Fix method parameter type mapping (#1775)
1 parent b8ba6bd commit 471f2e7

3 files changed

Lines changed: 70 additions & 4 deletions

File tree

src/Processors/AugmentParameters.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,15 @@ protected function augmentOperationParameters(Analysis $analysis): void
9292
$parameter->description = $details['description'];
9393
}
9494
}
95-
96-
if (!Generator::isDefault($parameter->schema)) {
97-
$this->mapNativeType($parameter->schema, $parameter->schema->type);
98-
}
9995
}
10096
}
10197
}
98+
99+
foreach ($operation->parameters as $parameter) {
100+
if (!Generator::isDefault($parameter->schema)) {
101+
$this->mapNativeType($parameter->schema, $parameter->schema->type);
102+
}
103+
}
102104
}
103105
}
104106
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* @license Apache 2.0
5+
*/
6+
7+
namespace OpenApi\Tests\Fixtures;
8+
9+
use OpenApi\Attributes as OAT;
10+
11+
class RequestUsingAttribute
12+
{
13+
#[OAT\Get(
14+
path: '/get/{id}',
15+
summary: 'get desc'
16+
)]
17+
public function get(#[OAT\PathParameter] int $id)
18+
{
19+
20+
}
21+
}

tests/Processors/AugmentParametersTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66

77
namespace OpenApi\Tests\Processors;
88

9+
use OpenApi\Annotations\Operation;
10+
use OpenApi\Annotations\Parameter;
11+
use OpenApi\Annotations\PathItem;
912
use OpenApi\Generator;
13+
use OpenApi\Processors\AugmentParameters;
14+
use OpenApi\Processors\BuildPaths;
1015
use OpenApi\Processors\Concerns\DocblockTrait;
16+
use OpenApi\Processors\MergeIntoComponents;
17+
use OpenApi\Processors\MergeIntoOpenApi;
1118
use OpenApi\Tests\OpenApiTestCase;
1219

1320
class AugmentParametersTest extends OpenApiTestCase
@@ -56,4 +63,40 @@ public function testExtractTags(string $params, array $expected): void
5663
$this->extractContent($mixed->comment, $tags);
5764
$this->assertEquals($expected, $tags);
5865
}
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+
}
59102
}

0 commit comments

Comments
 (0)