Skip to content

Commit a7fe3b1

Browse files
Keep Parameter description when generating OpenApiParameter
1 parent 582508e commit a7fe3b1

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/Doctrine/Common/Filter/OpenApiFilterTrait.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,19 @@ public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|arr
3333
$hasNonArraySchema = null !== $schema && !$isArraySchema;
3434

3535
if ($hasNonArraySchema || false === $castToArray) {
36-
return new OpenApiParameter(name: $parameter->getKey(), in: 'query');
36+
return new OpenApiParameter(
37+
name: $parameter->getKey(),
38+
in: 'query',
39+
description: $parameter->getDescription() ?? '',
40+
);
3741
}
3842

39-
return new OpenApiParameter(name: $parameter->getKey().'[]', in: 'query', style: 'deepObject', explode: true);
43+
return new OpenApiParameter(
44+
name: $parameter->getKey().'[]',
45+
in: 'query',
46+
description: $parameter->getDescription() ?? '',
47+
style: 'deepObject',
48+
explode: true,
49+
);
4050
}
4151
}

tests/Fixtures/TestBundle/Entity/ProductWithQueryParameter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
'brand' => new QueryParameter(
3131
filter: new ExactFilter(),
3232
),
33+
'brandWithDescription' => new QueryParameter(
34+
filter: new ExactFilter(),
35+
description: 'Extra description about the filter',
36+
),
3337
'search[:property]' => new QueryParameter(
3438
filter: new PartialSearchFilter(),
3539
properties: ['title', 'description']

tests/Functional/Parameters/DoctrineTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ private function loadProductFixtures(string $resourceClass): void
302302
}
303303

304304
#[DataProvider('openApiParameterDocumentationProvider')]
305-
public function testOpenApiParameterDocumentation(string $parameterName, bool $shouldHaveArrayNotation, string $expectedStyle, bool $expectedExplode, ?string $expectedSchemaType = null): void
305+
public function testOpenApiParameterDocumentation(string $parameterName, bool $shouldHaveArrayNotation, string $expectedStyle, bool $expectedExplode, ?string $expectedSchemaType = null, string $expectedDescription = ''): void
306306
{
307307
if ($this->isMongoDB()) {
308308
$this->markTestSkipped('Not tested with mongodb.');
@@ -339,6 +339,7 @@ public function testOpenApiParameterDocumentation(string $parameterName, bool $s
339339
$this->assertSame($expectedSchemaType, $foundParameter['schema']['type'], \sprintf('Parameter schema type should be %s', $expectedSchemaType));
340340
}
341341

342+
$this->assertSame($expectedDescription, $foundParameter['description'] ?? '', \sprintf('Description should be %s', $expectedDescription));
342343
$this->assertSame($expectedStyle, $foundParameter['style'] ?? 'form', \sprintf('Style should be %s', $expectedStyle));
343344
$this->assertSame($expectedExplode, $foundParameter['explode'] ?? false, \sprintf('Explode should be %s', $expectedExplode ? 'true' : 'false'));
344345
}
@@ -353,6 +354,14 @@ public static function openApiParameterDocumentationProvider(): array
353354
'expectedExplode' => true,
354355
'expectedSchemaType' => 'string',
355356
],
357+
'default behavior with an extra description' => [
358+
'parameterName' => 'brandWithDescription',
359+
'shouldHaveArrayNotation' => true,
360+
'expectedStyle' => 'deepObject',
361+
'expectedExplode' => true,
362+
'expectedSchemaType' => 'string',
363+
'expectedDescription' => 'Extra description about the filter',
364+
],
356365
'explicit schema type string should not use array notation' => [
357366
'parameterName' => 'exactBrand',
358367
'shouldHaveArrayNotation' => false,

0 commit comments

Comments
 (0)