core icon indicating copy to clipboard operation
core copied to clipboard

Can't Implement maxDepth in API-Platform using YAML

Open fawazIbrahim opened this issue 8 years ago • 8 comments

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)
*/

fawazIbrahim avatar Feb 19 '18 23:02 fawazIbrahim

I have a similar problem with xml configuration. "maxDepth" seems to do nothing here.

remoteclient avatar Mar 01 '18 11:03 remoteclient

https://github.com/api-platform/api-platform/issues/592 ?

soyuka avatar Mar 01 '18 13:03 soyuka

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.

Nightbr avatar Mar 05 '18 08:03 Nightbr

confirming bug with xml config. maxdepth for route generation does not work. Works as expected with annotations.

ctrl-f5 avatar Mar 05 '18 21:03 ctrl-f5

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.

Nightbr avatar Jun 13 '18 10:06 Nightbr

@ctrl-f5 @soyuka Fix in this PR https://github.com/api-platform/core/pull/2019

Nightbr avatar Jun 13 '18 12:06 Nightbr

Was this fixed?

Hadh avatar Apr 01 '20 10:04 Hadh

yes, fix & merged see #2019

Do you still have this issue?

Nightbr avatar Apr 01 '20 12:04 Nightbr