A similar question is already out, but with a different versioning on Symfony and NelmioApiDoc. And I am not sure it is this combination or that fact that also I am using FesRestBundle on top.
My issue is the following: I do get the following error when running the unit tests
[Semantical Error] The annotation "@OpenAPI\Annotations\Tag" in method App\RestController\DnsEndpointsController::getDnsEndpointsAction() was never imported. Did you maybe forget to add a "use" statement for this annotation?
Here is my relevant code leading to this error:
DnsEndpointsController.php:
<?php
declare(strict_types=1);
namespace App\RestController;
(...)
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Request\ParamFetcherInterface;
use Nelmio\ApiDocBundle\Annotation\Model;
use OpenAPI\Annotations\Get;
use OpenAPI\Annotations\Items;
use OpenAPI\Annotations\JsonContent;
use OpenAPI\Annotations\Parameter;
use OpenAPI\Annotations\Response as OAResponse;
use OpenAPI\Annotations\Schema;
use OpenAPI\Annotations\Tag;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\Validation;
class DnsEndpointsController extends AbstractFOSRestController
{
(...)
/**
* The endpoint to get all DNS Endpoints listed in the database
*
* This call will return all DNS Endpoints that are matching the filter criteria handed in as query parameter.
*
* @Rest\Route("/subjects/dnsendpoints", name="rest_api_subjects_get_dns_endpoints", methods={"GET"})
*
* @Tag("Subjects - DnsEndpoints")
*
* @Get(
* route="/subjects/dnsendpoints",
* @OAResponse(
* response=200,
* description="Returned when successful",
*
* @JsonContent(
* type="array",
* @Items(ref=@Model(type=NsdPrdplDnsEndpoint::class))
* )
* )
* )
*
* @Parameter(
* name="page", in="query", required=false,
* description="number of page requested",
* @Schema(type="integer")
* )
* @Parameter(
* name="perPage", in="query", required=false,
* description="number entries per page",
* @Schema(type="integer")
* )
(...)
*
* @param ParamFetcherInterface $paramFetcher
*
* @return Response
*
* @throws \LogicException
*/
public function getDnsEndpointsAction(ParamFetcherInterface $paramFetcher): Response
(...)
The relevant configuration is this:
config/routes/annotations.yaml:
(...)
rest-controllers:
resource: ../../src/RestController/
prefix: /api
type: annotation
and:
composer.json:
(...)
"require": {
"php": ">=7.1.0",
"ext-json": "*",
"beberlei/doctrineextensions": "^1.2",
"composer/package-versions-deprecated": "^1.11",
"doctrine/annotations": "^1.0",
"doctrine/doctrine-bundle": "^2.1",
"doctrine/doctrine-migrations-bundle": "^2.2.0",
"doctrine/orm": "^2.6",
"friendsofsymfony/rest-bundle": "^2.8",
"incenteev/composer-parameter-handler": "^2.1",
"jms/serializer-bundle": "^2.4",
"lexik/jwt-authentication-bundle": "^2.8",
"nelmio/api-doc-bundle": "^4.0",
"phpdocumentor/reflection-docblock": "^4.3",
"sensio/framework-extra-bundle": "^5.5",
"symfony/asset": "^4.4",
"symfony/flex": "^1.9",
"symfony/form": "^4.4",
"symfony/mailer": "^4.4",
"symfony/monolog-bundle": "^3.6",
"symfony/polyfill-apcu": "^1.0",
"symfony/property-access": "4.4.0",
"symfony/property-info": "4.4.0",
"symfony/security": "^4.4",
"symfony/security-bundle": "^4.4",
"symfony/serializer": "4.4.0",
"symfony/swiftmailer-bundle": "^3.1",
"symfony/templating": "4.4.0",
"symfony/translation": "^4.4",
"symfony/twig-bundle": "^4.4",
"symfony/validator": "^4.4",
"twig/extra-bundle": "^2.12|^3.0",
"twig/twig": "^2.12|^3.0"
},
(...)
Note three issues that I have around these annotations:
Despite the fact that I do explicitly state
use OpenAPI\Annotations\Tag;
it is not recognized. This annotation is even in full analogy to the explicit example from Zircote here: Swagger-PHP v3.x. Note also, that the preceding@Rest\Route
is passed and properly parsed.Whether I use the abbreviated import like
use OpenAPI\Annotations as OA;
and consequently@OA\Tag
later or the explicit class import as in the example makes no difference in the result.Is there a way to validate the annotations explicitly rather than waiting for phpunit to run the tests? I am waisting hundreds of minutes at this stage staring at the pipeline progress which increases my frustration about this issue even more.
Any idea on this one? What am I missing?