maxDepth on ApiSubresource annotation leads to FileLoaderLoadException · Issue #488 · api-platform/api-platform · GitHub
Skip to content

maxDepth on ApiSubresource annotation leads to FileLoaderLoadException #488

Closed

Description

@Rebolon

I'm trying the api-platform (v2.1.4) for the first time and i read something on maxDepth parameter to prevent something like circular reference.
In my sample i have 2 entities : Book (looks like something in documentation ;-)
and Editor
Book is provided by an many editor company (usually one, but during re-edition another editor may have bought the rights from the first editor, so a collection can be edited by a company and another collection, by another company)
Editor has many books in its inventory

I think you see what i mean. In that case i need an association table, but at the same time i would like to be able to retrreive the editor of a book, or all books of an editor.

Here is a part of the classes :

/**
 * @ApiResource
 * @ORM\Entity
 */
class Book
{
    ...
    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Library\Serie", inversedBy="Book")
     * @ORM\JoinColumn(name="serie_id", referencedColumnName="id")
     * @ApiSubresource()
     */
    private $Serie;
    ...
}

/**
 * @ApiResource
 * @ORM\Entity
 */
class Serie
{
    ....
    /**
     * @ORM\OneToOne(targetEntity="App\Entity\Library\Book", mappedBy="book")
     * @ApiSubresource()
     */
    private $Book;
    ...
}

I added the annotation ApiSubresource because i want to get the best resource routes ever ! But the problem is that now i have some stupid routes :

  • /api/books/{id}/serie/books
  • /api/series/{id}/books/{book}/serie

or even thos ones if i add a review entity which rely on a Book (reviews are link to 1 book, and a book can have many reviews) :

  • /api/series/{id}/books/{book}/reviews/{Reviews}/book/serie whereas only this one is useful : /api/series/{id}/books/{book}/reviews/{Reviews}
  • /api/reviews/{id}/book/serie/books/{book}/reviews : where i would prefer only this one /api/reviews/{id}/book/serie/
  • ... WTF

So i tried the params maxDepth on the @ApiSubresource annotation, But each time i set this i have that error :

(4/4) FileLoaderLoadException[Creation Error] The annotation @ApiSubresource declared on property App\Entity\Library\Book::$serie does not have a property named "maxDepth". Available properties: in . (which is being imported from "/dev/php/projects/php-sf-flex-webpack-encore-vuejs/config/routes/api_platform.yaml"). Make sure there is a loader supporting the "api_platform" type.
--
in FileLoader.php (line 168)

I thought i had follow explanation from https://api-platform.com/docs/core/operations#subresources but it appears that i misunderstood...

Any help is welcome. The project can be found in https://github.com/Rebolon/php-sf-flex-webpack-encore-vuejs/tree/feature/orm-for-form-demo

Activity

  1. soyuka commented on Dec 12, 2017

    @soyuka
    Member

    maxDepth on subresources has been added recently as a new feature but hasn't landed in the release yet.

  2. Rebolon commented on Dec 12, 2017

    @Rebolon
    Author

    sad to see it on documentation whereas it's not released... you should mark beta feature on the documentation.
    I will try with branch master even if it's risky, to test it.
    Thx

  3. soyuka commented on Dec 12, 2017

    @soyuka
    Member

    Yes our mistake I'm not sure how it landed in the documentation, sorry about that.

  4. Rebolon commented on Dec 12, 2017

    @Rebolon
    Author

    argh i used flex to install api-platform, i cannot easily override the version to dev-master.
    Have to wait for a new release

  5. Aerendir commented on Dec 12, 2017

    @Aerendir

    OFFTOPIC: in which way does Flex influences your ability to use a dev version? I have not yet used it extensively but only tried it during a process of migrating an existing app to SF4 (failed due to unavailability of some bundles for SF4, so an incomplete experience with it).

  6. Rebolon commented on Dec 13, 2017

    @Rebolon
    Author

    in fact the recipes is just a project with a composer.json (don't know if there is also other files to manage the Kernel and the config) that list all deps. So, using this package, you cannot specify a specific version for one deps.
    Maybe the solution would be to remove the recipes package and add all deps manually with the wished version (for testing purpose i'll do this but i prefer using Flex).

  7. Aerendir commented on Dec 13, 2017

    @Aerendir

    I continue to not understand.

    Flex is a Composer plugin, but all the deps are in composer.json.

    Once installed using composer req api-platform/api-platform, why you cannot simply change the version to dev-master in your composer.json?

  8. Rebolon commented on Dec 13, 2017

    @Rebolon
    Author

    When you use Flex you will not require "api-platform/core": "dev-master"
    but
    "api-platform/api-pack": "^1.0"

    this last one is the felx recipes, now look at its composer json
    that way you cannot load a specific version of api-platform/core

  9. Aerendir commented on Dec 13, 2017

    @Aerendir

    Ok, you can fork api-platform/api-pack, edit its composer.json file and push to your fork, then require the forked version in your app instead of the original one in the mean time.

  10. Rebolon commented on Dec 13, 2017

    @Rebolon
    Author

    It's more work, but i like the idea, and i don't kow why i didn't get it because i already did it, sometime i feel stupid (and tired)... :-) Thx for the tips

  11. sandoche commented on Jan 29, 2018

    @sandoche

    Do you know when "maxDepth" will be released, even in "dev-master"?

  12. Rebolon commented on Jan 30, 2018

    @Rebolon
    Author

    maxDepth should already be available on master, and even in 2.2.0-beta1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions