diff --git a/src/Support/OperationExtensions/ParameterExtractor/AttributesParametersExtractor.php b/src/Support/OperationExtensions/ParameterExtractor/AttributesParametersExtractor.php index 79da93b9..6e63cfda 100644 --- a/src/Support/OperationExtensions/ParameterExtractor/AttributesParametersExtractor.php +++ b/src/Support/OperationExtensions/ParameterExtractor/AttributesParametersExtractor.php @@ -35,11 +35,11 @@ public function handle(RouteInfo $routeInfo, array $parameterExtractionResults): ->map(fn (ReflectionAttribute $ra) => $this->createParameter($parameterExtractionResults, $ra->newInstance(), $ra->getArguments())) ->all(); - $extractedAttributes = collect($parameters)->map->name->all(); + $extractedAttributes = collect($parameters)->map(fn ($p) => "$p->name.$p->in")->all(); foreach ($parameterExtractionResults as $automaticallyExtractedParameters) { $automaticallyExtractedParameters->parameters = collect($automaticallyExtractedParameters->parameters) - ->filter(fn (Parameter $p) => ! in_array($p->name, $extractedAttributes)) + ->filter(fn (Parameter $p) => ! in_array("$p->name.$p->in", $extractedAttributes)) ->values() ->all(); } diff --git a/tests/Attributes/ParameterAnnotationsTest.php b/tests/Attributes/ParameterAnnotationsTest.php index 9f2fa13b..c57f0880 100644 --- a/tests/Attributes/ParameterAnnotationsTest.php +++ b/tests/Attributes/ParameterAnnotationsTest.php @@ -86,6 +86,22 @@ class SameNameParametersController_ParameterAnnotationsTest public function __invoke() {} } +it('allows defining parameters with the same names as inferred in different locations', function () { + $openApi = generateForRoute(fn (Router $r) => $r->get('api/test/{test}', SameNameParametersAsInferredController_ParameterAnnotationsTest::class)); + + expect($parameters = $openApi['paths']['/test/{test}']['get']['parameters']) + ->toHaveCount(2) + ->and($parameters[0]['name'])->toBe('test') + ->and($parameters[1]['name'])->toBe('test') + ->and($parameters[0]['in'])->toBe('path') + ->and($parameters[1]['in'])->toBe('query'); +}); +class SameNameParametersAsInferredController_ParameterAnnotationsTest +{ + #[QueryParameter('test')] + public function __invoke(string $test) {} +} + it('supports complex examples for Parameter annotations', function () { $openApi = generateForRoute(fn (Router $r) => $r->get('api/test', ParameterComplexExampleController_ParameterAnnotationsTest::class));