core icon indicating copy to clipboard operation
core copied to clipboard

Filters on GET operation not added to docs

Open dannyvw opened this issue 2 years ago • 5 comments

Description
Filters applied on GET operation are not added to the docs. It is only applied for CollectionOperationInterface https://github.com/api-platform/core/blob/main/src/OpenApi/Factory/OpenApiFactory.php#L271

Is there any reason that this is only applied for CollectionOperationInterface?

dannyvw avatar Apr 04 '23 12:04 dannyvw

Indeed, in 2.6 this was not supported but now it should work as well with simple get operations. I'm not sure I want to fix this quite yet as I want the filters to be refactored for next year. Basically https://github.com/api-platform/api-platform/discussions/1724, probably also handle some kind of validation (we have this but architecture is quite distant from filtering) and transformation (https://github.com/symfony/symfony/pull/49134) from the query parameters may be of some interest.

I'll be alright with a fix on the documentation but it'll not work with doctrine (and will not be supported by the default providers for now).

soyuka avatar Apr 04 '23 20:04 soyuka

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 08 '23 08:06 stale[bot]

This should still be fixed

dannyvw avatar Jun 15 '23 11:06 dannyvw

I think the issue is not solved, or maybe I'm missing something but in my case, using api plarform v3.2.16 I still don't have the filter in the doc.

Here's my resource:

<?php

declare(strict_types=1);

namespace App\Catalog\Infrastructure\Symfony\Resource;

use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Serializer\Filter\PropertyFilter;

#[Get]
#[GetCollection]
#[ApiFilter(PropertyFilter::class)]
class Menu
{
    #[ApiProperty(identifier: true)]
    public ?string $uuid;
    public string $name;
    public array $tags = [];
    public array $channels = [];
}

Here's the generated doc: Capture d’écran 2024-03-13 à 15 49 49 Capture d’écran 2024-03-13 à 15 50 01

The filter actually works however if I do curl -X 'GET' 'http://localhost:8000/api/menus/018e33a1-2fee-735a-949c-4ea67d7a2dee?properties[]=name' -H 'accept: application/json'

atomiix avatar Mar 13 '24 14:03 atomiix

https://github.com/api-platform/core/pull/5995

soyuka avatar Mar 15 '24 09:03 soyuka