0

I use ApiPlatform 3.1, and I've created a custom action which is the object in ApiResource directory - If I understand a new correctly practice in ApiPlatform 3.X, it's a new way to create a custom action. I also have defined a provider that returns this collection. I have a problem with Swagger and the docs that are returned. This model has attributes that are array and aggregate other DTOs. The response is correct but Swagger defines these fields as 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 **/
}

Swagger:

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

I would like to see the structure of these DTOs for inputs and outputs attributes. I tested adding @var in the comment before attributes and serialized group which is defined in GetCollection and used in the "main" DTO and in the next DTOs. It doesn't work.

For example:

{
  "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 **/

I know that I can define it manually by OpenApi\Annotations or a similar solution, but I want to find a way that will generate it automatically. Entities and collection in entities work fine so I think that in my situation also should work, right?

2
  • 1
    Just add serialization groups to your DTO and if im correct it should work
    – ThomasL
    Commented May 17, 2023 at 11:58
  • @ThomasL - Getter needs a comment with type but without array - for example: @return PostTitle[], but @return PostTitle[]|array - shows strings...
    – viko
    Commented Jun 20, 2023 at 15:53

0

Browse other questions tagged or ask your own question.