I have a symfony project, where I use api-platform.
I have an entity, and I have data providers for it. I am in trouble with definition of additional parameters for a collection endpoint.
An entity is called suggestion. It has to return collection of documents from elastic search.
An endpoint is:
/suggestion
This endpoint listens to additional GET parameters:
page, level
These two params are read each time, when the endpoint is requested.
In my SuggestionsCollectionDataProvider.php
class I have:
/**
* Retrieves a collection.
*
* @param string $resourceClass
* @param string|null $operationName
* @return \Generator
*/
public function getCollection(string $resourceClass, string $operationName = null): \Generator
{
$query = $this->requestStack->getCurrentRequest()->query;
// I am reading these two parameters from RequestStack
// this one is built-in
$page = max($query->get('page', 1), 1);
// this is a custom one
$level = $query->get('level', 0);
...
In my SuggestionRepository.php
class:
/**
* @return \Generator
*/
public function find(int $page, int $level): \Generator
{
// here I can process with $level without problems
Page parameter is default parameter, that is generating in swagger for collections.
A screenshot from API platform generated Swagger doc:
But the page parameter is now the only parameter, that can be edited in web version.
I need to add more parameters (level
in this case) to swagger and describe them, so the user/tester knows which parameter actually goes to this endpoint.
Main question:
How to tell api-platform, that I want a user/tester of the API (from client side) to enter some other parameters, i.e. level
for example?