ApiPlatform - 自定义操作,返回资源属性中的 DTO 数组

问题描述 投票:0回答:1

我使用 ApiPlatform 3.1,并且我创建了一个自定义操作,它是 ApiResource 目录中的对象 - 如果我理解 ApiPlatform 3.X 中的新正确做法,那么这是创建自定义操作的新方法。我还定义了一个返回该集合的提供者。我对 Swagger 和返回的文档有疑问。该模型具有数组和聚合其他 DTO 的属性。响应是正确的,但 Swagger 将这些字段定义为 string[]:

namespace App\ApiResource; 

#[GetCollection(
    uriTemplate: '/agents/details',
    paginationEnabled: false,
    provider: AgentDetailsProvider::class
)]
class AgentDetails
{
    #[ApiProperty(identifier: true)]
    private string $key;

    private int $count;

    private array $inputs;

    private array $outputs;
/** and constructor/setter etc **/
}

大摇大摆:

{
  "hydra:member": [
    {
      "@id": "string",
      "@type": "string",
      "key": "string",
      "count": 0,
      "inputs": [
        "string"
      ],
      "outputs": [
        "string"
      ]
    }
  ],
/** something **/

我想查看这些 DTO 的输入和输出属性的结构。我测试了在属性和序列化组之前的注释中添加

@var
,该属性和序列化组在 GetCollection 中定义并在“主”DTO 和下一个 DTO 中使用。没用。

例如:

{
  "hydra:member": [
    {
      "@id": "string",
      "@type": "string",
      "key": "string",
      "count": 0,
      "inputs": [
        {
           "@id": "string",
           "value": "string",
           "count": 1 
        }
      ],
      "outputs": [
        {
           "@id": "string",
           "value": "string",
           "key": "string" 
        }
      ]
    }
  ],
/** something **/

我知道我可以通过

OpenApi\Annotations
或类似的解决方案手动定义它,但我想找到一种自动生成它的方法。实体和实体中的集合工作正常,所以我认为在我的情况下也应该工作,对吗?

php symfony openapi api-platform.com
1个回答
0
投票

你能解决这个问题吗?有同样的问题,但似乎没有任何作用:/

© www.soinside.com 2019 - 2024. All rights reserved.