Api-platform: api_resource/resource.yaml - Symfony 4 Location

Created on 31 Jan 2018  路  3Comments  路  Source: api-platform/api-platform

Hello,
what is the correct location for the resource yaml configuration in the symfony 4 flex version?

question

Most helpful comment

FML I wrote a big answer to this yesterday...

Oh okay please don't post the same issue in two repositories...

My original answer:
The one you want :).

IMO, standard version would be like:

src/Kernel.php
src/api_resources.yaml
src/Entity/Product.php

With config/packages/api_platform.yaml:

api_platform:
  mapping:
    paths:
      - '%kernel.project_dir%/src/api_resources.yaml'
  resource_class_directories:
    - '%kernel.project_dir%/src/Entity'

I have the following:

src/Kernel.php
src/Product/api_resources.yaml
src/Product/Entity/Product.php

With config/packages/api_platform.yaml:

api_platform:
  mapping:
    paths:
      - '%kernel.project_dir%/src/Product/api_resources.yaml'
  resource_class_directories:
    - '%kernel.project_dir%/src/Product/Entity' annotations from those files 

https://github.com/api-platform/core/issues/1671#issuecomment-361908539

All 3 comments

Hello,

I'm working with AP 2.1.5 and my config files are under src/Resources/config/api_resources

Then you can have a file per entity with the following structure:

# src/Resources/config/api_resources/market.yaml
resources:
    App\Entity\Market:
        attributes:
            pagination_items_per_page: 10
            filters:
                - name.search_filter
                - all_fields.order_filter
        properties:
            categories:
                subresource:
                    resourceClass: 'App\Entity\MarketCategory'
                    collection: true
        collectionOperations: ~
        itemOperations: ~

Notes that all entities namespaces must be under resources key

FML I wrote a big answer to this yesterday...

Oh okay please don't post the same issue in two repositories...

My original answer:
The one you want :).

IMO, standard version would be like:

src/Kernel.php
src/api_resources.yaml
src/Entity/Product.php

With config/packages/api_platform.yaml:

api_platform:
  mapping:
    paths:
      - '%kernel.project_dir%/src/api_resources.yaml'
  resource_class_directories:
    - '%kernel.project_dir%/src/Entity'

I have the following:

src/Kernel.php
src/Product/api_resources.yaml
src/Product/Entity/Product.php

With config/packages/api_platform.yaml:

api_platform:
  mapping:
    paths:
      - '%kernel.project_dir%/src/Product/api_resources.yaml'
  resource_class_directories:
    - '%kernel.project_dir%/src/Product/Entity' annotations from those files 

https://github.com/api-platform/core/issues/1671#issuecomment-361908539

@soyuka's responses seems the right thing to do, thanks!

If you still have an issue feel free to ping me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

achref-riahi picture achref-riahi  路  3Comments

irmantas picture irmantas  路  3Comments

ajaunasse picture ajaunasse  路  3Comments

raresserban picture raresserban  路  3Comments

sverraest picture sverraest  路  3Comments