0

I'm currently trying to make an API doc page thanks to nelmio-api-bundle. I only have one route which is a POST route. I'm receiving a JSON in the body of the request and I'm using the Serializer from symfony to deserialize it in a DTO. I'm also using a DTO for the response (which contains the status code, a bool set to true or false, and a message). Now I'm trying to use these DTO (for input and output) to build the API documentation with nelmio-api-bundle but how to make it ? I'm using PHP8.1 attributes to make it, for response it almost works (except that the response is shows as an array) but I don't know how to make it for the inputs.

Here is my current code:

#[Route('/user', methods: ['POST'])]
#[OA\Parameter(
    name: 'user',
    description: 'The user information in JSON',
    in: 'query',
    required: true
)]
#[OA\Response(
    response: 200,
    description: 'Returns the success response',
    content: new OA\JsonContent(
        type: 'array',
        items: new OA\Items(ref: new Model(type: SuccessResponseDTO::class))
    )
)]
public function registerUser(Request $request, LoggerInterface $logger): JsonResponse
{
    //the code to register the user
}

And here is the result: Result of the current code

Do someone know how to make it ?

jeff
  • 35
  • 6

1 Answers1

0

If I understand the question correctly, and you just don't need to wrap the response in an array, then:

use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Attributes as OA;

#[OA\Response(
    response: 200,
    description: 'Returns the success response',
    content: new Model(type: SuccessResponseDTO::class),
)]
vodevel
  • 144
  • 4