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

Subresource in swagger didn't have 'page' field. #1650

Closed
ln-e opened this issue Jan 15, 2018 · 7 comments
Closed

Subresource in swagger didn't have 'page' field. #1650

ln-e opened this issue Jan 15, 2018 · 7 comments

Comments

@ln-e
Copy link
Contributor

ln-e commented Jan 15, 2018

Although there is enabled pagination:

{
  "@context": "/api/contexts/Task",
  "@id": "/api/projects/3/tasks",
  "@type": "hydra:Collection",
  "hydra:member": [
    ...
  ],
  "hydra:totalItems": 33,
  "hydra:view": {
    "@id": "/api/projects/3/tasks?page=1",
    "@type": "hydra:PartialCollectionView",
    "hydra:first": "/api/projects/3/tasks?page=1",
    "hydra:last": "/api/projects/3/tasks?page=2",
    "hydra:next": "/api/projects/3/tasks?page=2"
  },
}

api-platform/core: v2.1.4

@Simperfit
Copy link
Contributor

Simperfit commented Apr 24, 2018

I don't really understand what's the issue here, firstly you are showing us a json-ld return not a swagger one and the page are in the hydra:view.

@ln-e
Copy link
Contributor Author

ln-e commented Apr 24, 2018

There is pagination in response.
But there isn't page field in swagger.

2018-04-24_16-06-59

@JumpIfBelow
Copy link

JumpIfBelow commented May 16, 2018

I actually have the same issue here: a subresource does not seem to have pagination activated.
I'll check the sources if I could where this issue belongs to. It is kinda weird that it is rendering in such a way. If I find a fix quickly, I'll do a merge request.

EDIT: to provide more informations, it is not just lack of documentation, but the parameter really is not there. If I use a page parameter manually, the response is an empty array, while I have more than 30 items. I'll get 30 of them if I'm not providing the page parameter, however the remaining data is not accessible.
I've dumped some data, and it seems that the documentation generator wants to add a page parameter, but it is not rendered in the end.

Here is the dumped documentation:
dumped_documentation
And now the result in the doc:
rendered_documentation

@JumpIfBelow
Copy link

JumpIfBelow commented May 16, 2018

Okay, so part of the problem actually is that I've named the subresource operation on my entity api_users_rights_get_subresource while API Platform is generating api_users_rights_get_subresourceRightCollection. I think I've been misled to the first name because I used the route name. But how to know this? I only discovered after dumping data in the core, maybe there is a lack of information somewhere (I'm not blaming here, just trying to understand)

The result of some operations made by the core is clearer now, but the final result seems to be the same for the documentation. Meanwhile, the result seems fixed: I can manually do the request with the page parameter.

Still, what is happening in Swagger\Serializer\DocumentationNormalizer.php:197 seems a bit confusing to me. I've seen the array beeing filled with two new entries in only one iteration. Some data are altered between what the getPathOperation returns and the storage in $paths variable. I'm not able to understand it more by myself.

@dunglas
Copy link
Member

dunglas commented May 16, 2018

We had a discussion about pagination with @sroze recently. We thought it would be nice to implement it has filters instead of this custom logic.

Anyway, it looks like a bug to me. The Swagger Normalizer probably not handle pagination for resources.

@JumpIfBelow
Copy link

This issue still hurts my brain to understand it completely.
So, by changing the name as I said above for api_users_rights_get_subresourceRightCollection, what I've done is basically saying goodbye to any custom configuration for this subresource. It means this name has nothing to do to customize the subresource. In the same time, the pagination is now active, the configuration is auto-generated.

If I use the api_users_rights_get_subresource, I am able to add some special things, like authorization. But somewhere in the code, the pagination ability is lost, so no more paginated result for this subresource.

So, the issue is about *ToMany subresources, with the Swagger\Serializer\DocumentationNormalizer missing the generated name route. It adds a <resource name>Collection sufix to the route name that makes the whole thing failing to provide a pagination. I guess this suffix should not be there, as it clearly is a conflict between auto-generated and customized subresources parameters.

@soyuka
Copy link
Member

soyuka commented Apr 7, 2019

Closing in favor of #2706

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants