api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.39k stars 848 forks source link

Filters on GET operation not added to docs #5527

Open dannyvw opened 1 year ago

dannyvw commented 1 year ago

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?

soyuka commented 1 year ago

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).

stale[bot] commented 1 year ago

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.

dannyvw commented 1 year ago

This should still be fixed

atomiix commented 3 months ago

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'

soyuka commented 3 months ago

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