Closed IcarusSosie closed 1 month ago
Parameters and Filters are two different things, you should probably try to use https://api-platform.com/docs/core/filters/#parameters directly. Filters are only working on collection operations.
Haha I really needed this vacation. Sorry about that !
I'll take a look at parameters and open another issue if I'm still having trouble. Closing this for now.
API Platform version(s) affected: tested on main, but the code mentioned here is also present on 3.3.11
Description
Query/header parameter documentation generated as a result of adding a filter to an
ApiResource
, either via theApiFilter
attribute, or thefilters
parameter onApiResource
/Metadata
, seem to only show up in swagger for endpoints corresponding to a GetCollection operation.I've tested this on my API-Platform project, with both a custom filter and
PropertyFilter
.I'm honestly not sure this isn't the expected behavior, but I've followed the generation of the OpenApi document via debugger and it seems there's something missing. Either behavior-wise or documentation-wise.
First, in
ParameterResourceMetadataCollectionFactory::addFilterValidation
, for each filter on the current operation metadata is being collected for, a simple QueryParameter gets added with the sole purpose of containing the constraints associated with the filter's definition. A comment mentions :// we disable openapi and hydra on purpose as their docs comes from filters see the condition for addFilterValidation above
.This comment leaves me confused as to where the docs actually come from. Is it some other
ResourceMetadataCollectionFactoryInterface
, is itOpenApiFactory
itself ? A link to the code actually creating the documentation for this parameter would be welcome here.Second, in
OpenApiFactory
, thegetFiltersParameters
method is responsible for returning an array of filters applicable to an operation. According to the method signature, it takes either anHttpOperation
or aCollectionOperationInterface
. This looks to me like the method is meant to be able to act on both types of operations. However, this method is used only incollectPaths
, in this context :So far this seems like the only place where the aforementioned docs generation happens, but it's limited to
GetCollection
operations.Whilst most filters really only operate to remove elements or reorder elements in a list of results, currently filters are generic enough in behavior to apply to all types of operations.
PropertyFilter
andGroupFilter
are two filters that can apply to a unique item.How to reproduce
Add an
#[ApiFilter(PropertyFilter::class)]
attribute on anApiResource
that has all operations. Access the swagger documentation. Only the GetCollection endpoints have theproperties[]
parameter documented.Possible Solution
I'm currently thinking of adding a step to my decoration of
OpenApiFactory
to "fix" this behavior and test if that has any side-effects.Additional context