Skip to content

Commit c44bf5b

Browse files
committed
fix: Fix Api Docs generic type detection + add test
1 parent 23ad6c0 commit c44bf5b

File tree

22 files changed

+121
-67
lines changed

22 files changed

+121
-67
lines changed

.env.dist renamed to .env

File renamed without changes.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
.idea
2-
.env
2+
.env.local

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ stages:
1313
- cleanup
1414

1515
variables:
16-
DOCKER_IMAGE: docker:26.1
17-
DOCKER_DIND_IMAGE: docker:26.1-dind-rootless
16+
DOCKER_IMAGE: docker:27.1
17+
DOCKER_DIND_IMAGE: docker:27.1-dind-rootless
1818
PHP_VERSION: '8.3'
1919
PHP_DOCKER_RELEASE: 'bookworm'
2020

bin/publish-package.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ checkout_subtree () {
2323
}
2424

2525
cleanup () {
26-
# Delete the tag locally to avoid conflicts
27-
git tag -d ${PACKAGE_VERSION}
2826
git checkout origin/${CI_COMMIT_REF_NAME}
2927
git branch -D ${TEMP_BRANCH}
3028
}
@@ -36,6 +34,9 @@ publish_tag () {
3634
git tag -a ${PACKAGE_VERSION} -m "Version ${PACKAGE_VERSION}"
3735
git push -f ${PACKAGE} refs/tags/${PACKAGE_VERSION}:refs/tags/${PACKAGE_VERSION}
3836

37+
# Delete the tag locally to avoid conflicts
38+
git tag -d ${PACKAGE_VERSION}
39+
3940
cleanup
4041
}
4142

docker/php-cli/run.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/bin/bash -e
22

3-
cp -n .env.dist .env
43
source .env
54

5+
if [ -f .env.local ]; then
6+
source .env.local
7+
fi
8+
69
DIRECTORY="${1:-packages}"
710

811
docker build --build-arg PHP_VERSION=${PHP_VERSION} \

packages/api-documentation-bundle/composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "fusonic/api-documentation-bundle",
33
"license": "MIT",
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"description": "Symfony bundle for automated documentation with NelmioApiDocBundle.",
66
"type": "symfony-bundle",
77
"authors": [
@@ -32,14 +32,15 @@
3232
"phpstan/phpstan-strict-rules": "^1.6",
3333
"phpstan/phpstan-symfony": "^1.4",
3434
"phpunit/phpunit": "^11.2",
35+
"symfony/serializer": "^5.4 || ^6.0 || ^7.0",
3536
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
3637
"symfony/test-pack": "^1.0",
3738
"symfony/yaml": "^5.4 || ^6.0 || ^7.0",
3839
"tomasvotruba/type-coverage": "^0.3"
3940
},
4041
"require": {
4142
"php": ">=8.2",
42-
"nelmio/api-doc-bundle": "^4.11",
43+
"nelmio/api-doc-bundle": "^4.29",
4344
"symfony/config": "^5.4 || ^6.0 || ^7.0",
4445
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
4546
"symfony/dom-crawler": "^5.4 || ^6.0 || ^7.0",

packages/api-documentation-bundle/src/AnnotationBuilder/AnnotationBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class AnnotationBuilder
3232
public function __construct(
3333
private readonly DocumentedRoute $route,
3434
private readonly \ReflectionMethod $method,
35-
private readonly ?\ReflectionClass $requestObjectReflectionClass
35+
private readonly ?\ReflectionClass $requestObjectReflectionClass,
3636
) {
3737
$this->propertyExtractor = new PropertyExtractor();
3838

packages/api-documentation-bundle/src/AnnotationBuilder/PropertyExtractor.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ public function extractMethodReturnType(\ReflectionMethod $method): ?Type
5656

5757
public function extractCollectionReturnType(Type $returnType): ?Type
5858
{
59-
if (!$returnType->isCollection()) {
60-
return null;
61-
}
62-
6359
$collectionTypes = $returnType->getCollectionValueTypes();
6460

6561
if (\count($collectionTypes) > 0) {

packages/api-documentation-bundle/src/Attribute/DocumentedRoute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(
4141
private readonly ?string $output = null,
4242
private readonly ?bool $outputIsCollection = null,
4343
private readonly ?int $statusCode = null,
44-
private readonly ?string $description = null
44+
private readonly ?string $description = null,
4545
) {
4646
parent::__construct(
4747
path: $path,

packages/api-documentation-bundle/tests/App/Controller/TestController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Fusonic\ApiDocumentationBundle\Attribute\DocumentedRoute;
1313
use Fusonic\ApiDocumentationBundle\Tests\App\FromRequest;
1414
use Fusonic\ApiDocumentationBundle\Tests\App\Request\TestRequest;
15+
use Fusonic\ApiDocumentationBundle\Tests\App\Response\TestGenericResponse;
1516
use Fusonic\ApiDocumentationBundle\Tests\App\Response\TestResponse;
1617
use OpenApi\Attributes as OA;
1718
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -71,6 +72,15 @@ public function testAnnotationCustomReturnTypeArray(#[FromRequest] TestRequest $
7172
return [new TestResponse($query->id)];
7273
}
7374

75+
/**
76+
* @return TestGenericResponse<TestResponse>
77+
*/
78+
#[DocumentedRoute(path: '/test-generic-return-type/{id}', methods: ['GET'])]
79+
public function testGenericReturnType(#[FromRequest] TestRequest $query): TestGenericResponse
80+
{
81+
return new TestGenericResponse([new TestResponse($query->id)]);
82+
}
83+
7484
#[DocumentedRoute(path: '/test-combined-attributes/{id}', methods: ['POST'], description: 'Object found')]
7585
#[OA\Response(response: 404, description: 'Object was not found.')]
7686
public function testCombinedAttributes(#[FromRequest] TestRequest $query): TestResponse

0 commit comments

Comments
 (0)