Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3676 - fixed subresource pagination support if primary resource has pagination disabled #3678

Merged
merged 1 commit into from
Aug 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/Swagger/Serializer/DocumentationNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ private function updateGetOperation(bool $v3, \ArrayObject $pathOperation, array
$pathOperation['responses'] ?? $pathOperation['responses'] = [$successStatus => $successResponse];
$pathOperation['parameters'] ?? $pathOperation['parameters'] = $this->getFiltersParameters($v3, $resourceClass, $operationName, $resourceMetadata);

$this->addPaginationParameters($v3, $resourceMetadata, $operationName, $pathOperation);
$this->addPaginationParameters($v3, $resourceMetadata, OperationType::COLLECTION, $operationName, $pathOperation);

return $pathOperation;
}
Expand All @@ -350,9 +350,9 @@ private function updateGetOperation(bool $v3, \ArrayObject $pathOperation, array
return $pathOperation;
}

private function addPaginationParameters(bool $v3, ResourceMetadata $resourceMetadata, string $operationName, \ArrayObject $pathOperation)
private function addPaginationParameters(bool $v3, ResourceMetadata $resourceMetadata, string $operationType, string $operationName, \ArrayObject $pathOperation)
{
if ($this->paginationEnabled && $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_enabled', true, true)) {
if ($this->paginationEnabled && $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'pagination_enabled', true, true)) {
$paginationParameter = [
'name' => $this->paginationPageParameterName,
'in' => 'query',
Expand All @@ -365,7 +365,7 @@ private function addPaginationParameters(bool $v3, ResourceMetadata $resourceMet
] : $paginationParameter['type'] = 'integer';
$pathOperation['parameters'][] = $paginationParameter;

if ($resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_client_items_per_page', $this->clientItemsPerPage, true)) {
if ($resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'pagination_client_items_per_page', $this->clientItemsPerPage, true)) {
$itemPerPageParameter = [
'name' => $this->itemsPerPageParameterName,
'in' => 'query',
Expand All @@ -375,15 +375,15 @@ private function addPaginationParameters(bool $v3, ResourceMetadata $resourceMet
if ($v3) {
$itemPerPageParameter['schema'] = [
'type' => 'integer',
'default' => $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_items_per_page', 30, true),
'default' => $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'pagination_items_per_page', 30, true),
'minimum' => 0,
];

$maxItemsPerPage = $resourceMetadata->getCollectionOperationAttribute($operationName, 'maximum_items_per_page', null, true);
$maxItemsPerPage = $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'maximum_items_per_page', null, true);
if (null !== $maxItemsPerPage) {
@trigger_error('The "maximum_items_per_page" option has been deprecated since API Platform 2.5 in favor of "pagination_maximum_items_per_page" and will be removed in API Platform 3.', E_USER_DEPRECATED);
}
$maxItemsPerPage = $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_maximum_items_per_page', $maxItemsPerPage, true);
$maxItemsPerPage = $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'pagination_maximum_items_per_page', $maxItemsPerPage, true);

if (null !== $maxItemsPerPage) {
$itemPerPageParameter['schema']['maximum'] = $maxItemsPerPage;
Expand All @@ -396,7 +396,7 @@ private function addPaginationParameters(bool $v3, ResourceMetadata $resourceMet
}
}

if ($this->paginationEnabled && $resourceMetadata->getCollectionOperationAttribute($operationName, 'pagination_client_enabled', $this->paginationClientEnabled, true)) {
if ($this->paginationEnabled && $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'pagination_client_enabled', $this->paginationClientEnabled, true)) {
$paginationEnabledParameter = [
'name' => $this->paginationClientEnabledParameterName,
'in' => 'query',
Expand Down Expand Up @@ -467,7 +467,7 @@ private function addSubresourceOperation(bool $v3, array $subresourceOperation,
}

if ($subresourceOperation['collection']) {
$this->addPaginationParameters($v3, $resourceMetadata, $operationName, $pathOperation);
$this->addPaginationParameters($v3, $subResourceMetadata, OperationType::SUBRESOURCE, $subresourceOperation['operation_name'], $pathOperation);
}

return new \ArrayObject(['get' => $pathOperation]);
Expand Down