首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Symfony 4.4 / NelmioApiDocBundle 4.0.1发行注释

Symfony 4.4 / NelmioApiDocBundle 4.0.1发行注释
EN

Stack Overflow用户
提问于 2021-07-23 17:15:37
回答 1查看 1.4K关注 0票数 2

一个类似的问题已经出现,但在Symfony和NelmioApiDoc上有不同的版本控制。我不确定是这个组合还是那个事实,我也在上面使用FesRestBundle。

我的问题如下:在运行单元测试时,我确实得到了以下错误

语义错误方法App\RestController\DnsEndpointsController::getDnsEndpointsAction()中的注释“@OpenAPI\注释\标记”从未导入。您可能忘记为这个注释添加"use“语句了吗?

下面是导致此错误的相关代码:

代码语言:javascript
运行
复制
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
(...)

相关的配置如下:

代码语言:javascript
运行
复制
config/routes/annotations.yaml:
(...)
rest-controllers:
    resource: ../../src/RestController/
    prefix: /api
    type: annotation

以及:

代码语言:javascript
运行
复制
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"
    },
(...)

注意我在这些注释中涉及的三个问题:

  1. 尽管我确实明确地声明了use OpenAPI\Annotations\Tag;,但它是不被认可的。这个注释甚至完全类似于Zircote这里的显式示例:Swagger-PHP v3.x。还请注意,前面的@Rest\Route被传递并正确地被解析。
  2. 无论我是否使用缩写的导入,比如use OpenAPI\Annotations as OA;,以及后来的@OA\Tag,还是显式类导入(如示例中所示),结果都没有区别。
  3. 是否有方法显式地验证注释,而不是等待phpunit运行测试?在这个阶段,我正等着几百分钟,盯着管道的进展,这使我对这个问题更加感到沮丧。

对这个有什么想法吗?我遗漏了什么?

EN

Stack Overflow用户

发布于 2021-07-25 13:12:55

使用Windows,当测试管道在基于linux的主机上运行时,OpenAPIOpenApi之间的情况不匹配就没人注意到了,因此产生了差异。谢谢@GuilhemN注意到这一点。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68502922

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档