Can't Implement maxDepth in API-Platform using YAML
I have an entity with the following
/**
* @ORM\Table(name="category")
* @ORM\Entity(repositoryClass="AppBundle\Repository\CategoryRepository")
*/
class Category
{
...
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Category", mappedBy="parent")
*/
private $children;
...
}
and i've defined the "children" as an API-Subresource using YAML:
AppBundle\Entity\Category:
properties:
children:
subresource:
resourceClass: 'App\Entity\Category'
How to set a maxDepth for the $children without using annotation like
/**
* @ApiSubresource(maxDepth=1)
*/
I have a similar problem with xml configuration. "maxDepth" seems to do nothing here.
https://github.com/api-platform/api-platform/issues/592 ?
Hey, the maxDepth in ApiSubresource annotation is only for Subresource ROUTE maxDepth generation.
i.e. If you have foo/{id}/bar and bar/{id}/other, Api platform will generate all subresource route such as foo/{id}/bar/{id}/other. You can chose the maxdepth of subresource route generation with the maxDepth parameter in ApiSubresource annotation.
If you want maxDepth for serialization, use directly @maxDepth annotation.
Note: @ApiSubresource(maxDepth=1) is not released yet. Only on master branch.
confirming bug with xml config. maxdepth for route generation does not work. Works as expected with annotations.
Found it, We need to handle $maxDepth here https://github.com/api-platform/core/blob/master/src/Metadata/Property/Factory/ExtractorPropertyMetadataFactory.php#L151
I will make a PR today to fix this.
@ctrl-f5 @soyuka Fix in this PR https://github.com/api-platform/core/pull/2019
Was this fixed?
yes, fix & merged see #2019
Do you still have this issue?