【问题标题】:API Platform DTO not used in Swagger documentationSwagger 文档中未使用 API 平台 DTO
【发布时间】:2021-06-15 16:21:00
【问题描述】:

我有一个实体和一个 DTO,我想在 POST 请求中使用它们。这是我的两门课。

<?php

declare(strict_types=1);

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use App\Dto\TestPost;

/**
 * @ApiResource(
 *     collectionOperations={
 *          "post"={
 *              "input"=TestPost::class
 *          }
 *     },
 *     itemOperations={}
 * )
 */
final class Test
{
    public string $foo;

    public string $bar;
}
<?php

declare(strict_types=1);

namespace App\Dto;

final class TestPost
{
    /**
     * @var string
     */
    public string $xxx;
}

我希望在 Swagger 文档中显示“xxx”字段。而是显示原始实体的两个字段“foo”和“bar”。我是不是忘记了什么?

【问题讨论】:

    标签: php symfony api-platform.com


    【解决方案1】:

    看来我也必须定义输出。当我像这样添加“输出”键时它可以工作:

    <?php
    
    declare(strict_types=1);
    
    namespace App\Entity;
    
    use ApiPlatform\Core\Annotation\ApiResource;
    use App\Dto\TestPost;
    
    /**
     * @ApiResource(
     *     collectionOperations={
     *          "post"={
     *              "input"=TestPost::class,
     *              "output"=false
     *          }
     *     },
     *     itemOperations={}
     * )
     */
    final class Test
    {
        public string $foo;
    
        public string $bar;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多