一个类似的问题已经出现,但在Symfony和NelmioApiDoc上有不同的版本控制。我不确定是这个组合还是那个事实,我也在上面使用FesRestBundle。
我的问题如下:在运行单元测试时,我确实得到了以下错误
语义错误方法App\RestController\DnsEndpointsController::getDnsEndpointsAction()中的注释“@OpenAPI\注释\标记”从未导入。您可能忘记为这个注释添加"use“语句了吗?
下面是导致此错误的相关代码:
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
(...)
相关的配置如下:
config/routes/annotations.yaml:
(...)
rest-controllers:
resource: ../../src/RestController/
prefix: /api
type: annotation
以及:
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"
},
(...)
注意我在这些注释中涉及的三个问题:
use OpenAPI\Annotations\Tag;
,但它是不被认可的。这个注释甚至完全类似于Zircote这里的显式示例:Swagger-PHP v3.x。还请注意,前面的@Rest\Route
被传递并正确地被解析。use OpenAPI\Annotations as OA;
,以及后来的@OA\Tag
,还是显式类导入(如示例中所示),结果都没有区别。对这个有什么想法吗?我遗漏了什么?
发布于 2021-07-25 13:12:55
使用Windows,当测试管道在基于linux的主机上运行时,OpenAPI
和OpenApi
之间的情况不匹配就没人注意到了,因此产生了差异。谢谢@GuilhemN注意到这一点。
https://stackoverflow.com/questions/68502922
复制相似问题