Skip to content

Commit

Permalink
feat(ApiPlatform): Disabled metadata_backward_compatibility_layer a…
Browse files Browse the repository at this point in the history
…nd migrated all API resources, filters, extensions to new `Operation` syntax

BREAKING CHANGE: You must migrate your `config/api_resources/*.yml` files to use new [ApiPlatform interfaces and resource YML syntax](https://api-platform.com/docs/core/upgrade-guide/#summary-of-the-changes-between-26-and-2730)

- Remove and regenerate your NS entities with `bin/console generate:nsentities` to update namespaces
- Remove and regenerate your Resource configs with `bin/console generate:api-resources`
    - If you do not want to remove existing config, [you'll have to move `itemOperations` and `collectionOperations` to single `operations` node](https://api-platform.com/docs/core/upgrade-guide/#metadata-changes) and add `class` with `ApiPlatform\Metadata\Get` or `ApiPlatform\Metadata\GetCollection`
    - Rename `iri` to `types` and wrap single values into array
    - Rename `path` to `uriTemplate`
    - Rename `normalization_context` to `normalizationContext`
    - Rename `openapi_context` to `openapiContext`
    - Move `shortName` to each `operation`
    - Rename `attributes` to `extraProperties` (for `/archives` endpoints)
    - Add `uriTemplate` for your custom endpoints (for `/archives` endpoints)
    - Prefix all named operations with `api_` to  avoid conflict with non API routes
- All filters and extensions use new interfaces
- Removed all deprecated DataTransformer and Dto classes
- Once everything is migrated changed `metadata_backward_compatibility_layer: false` in `config/packages/api_platform.yaml`
  • Loading branch information
ambroisemaupate committed Jul 20, 2023
1 parent 1ef33a8 commit f0317aa
Show file tree
Hide file tree
Showing 122 changed files with 1,233 additions and 2,430 deletions.
11 changes: 5 additions & 6 deletions config/api_resources/attribute_value.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
---
RZ\Roadiz\CoreBundle\Entity\AttributeValue:
collectionOperations:
get:
operations:
ApiPlatform\Metadata\GetCollection:
method: "GET"
normalization_context:
normalizationContext:
groups: ["urls", "attribute", "document_display", "attribute_node", "attribute_documents"]
enable_max_depth: true
itemOperations:
get:
ApiPlatform\Metadata\Get:
method: 'GET'
normalization_context:
normalizationContext:
groups: ["urls", "attribute", "document_display", "attribute_node", "attribute_documents"]
enable_max_depth: true

8 changes: 4 additions & 4 deletions config/api_resources/common_content.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
App\Api\Model\CommonContent:
collectionOperations: {}
itemOperations:
operations:
getCommonContent:
class: ApiPlatform\Metadata\Get
method: 'GET'
path: '/common_content'
uriTemplate: '/common_content'
read: false
controller: App\Controller\GetCommonContentController
pagination_enabled: false
normalization_context:
normalizationContext:
enable_max_depth: true
pagination_enabled: false
groups:
Expand Down
25 changes: 13 additions & 12 deletions config/api_resources/custom_form.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
---
RZ\Roadiz\CoreBundle\Entity\CustomForm:
collectionOperations:
get:
operations:
ApiPlatform\Metadata\GetCollection:
method: "GET"
normalization_context:
normalizationContext:
enable_max_depth: true

itemOperations:
get:
ApiPlatform\Metadata\Get:
method: 'GET'
normalization_context:
normalizationContext:
enable_max_depth: true

api_custom_forms_item_post:
method: 'POST'
route_name: api_custom_forms_item_post
normalization_context:
class: ApiPlatform\Metadata\Post
routeName: api_custom_forms_item_post
normalizationContext:
enable_max_depth: true
openapi_context:
openapiContext:
summary: Post a user custom form
description: |
Post a user custom form
Expand Down Expand Up @@ -59,10 +59,11 @@ RZ\Roadiz\CoreBundle\Entity\CustomForm:

api_custom_forms_item_definition:
method: 'GET'
route_name: api_custom_forms_item_definition
normalization_context:
class: ApiPlatform\Metadata\Get
routeName: api_custom_forms_item_definition
normalizationContext:
enable_max_depth: true
openapi_context:
openapiContext:
summary: Get a custom form definition for frontend
description: |
Get a custom form definition for frontend
Expand Down
12 changes: 6 additions & 6 deletions config/api_resources/document.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
RZ\Roadiz\CoreBundle\Entity\Document:
collectionOperations:
get:
operations:
ApiPlatform\Metadata\GetCollection:
method: "GET"
normalization_context:
normalizationContext:
groups: ["urls", "document_display", "document_folders", "document_folders_all", "document_display_sources"]
enable_max_depth: true
itemOperations:
get:

ApiPlatform\Metadata\Get:
method: 'GET'
normalization_context:
normalizationContext:
groups: ["urls", "document", "document_display", "document_folders", "document_folders_all", "document_display_sources"]
enable_max_depth: true

13 changes: 5 additions & 8 deletions config/api_resources/folder.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
---
RZ\Roadiz\CoreBundle\Entity\Folder:
iri: Folder
shortName: Folder
collectionOperations:
get:
operations:
ApiPlatform\Metadata\GetCollection:
method: "GET"
normalization_context:
normalizationContext:
groups: [ "folder" ]
enable_max_depth: true
itemOperations:
get:
ApiPlatform\Metadata\Get:
method: "GET"
normalization_context:
normalizationContext:
groups: [ "folder" ]
enable_max_depth: true
8 changes: 3 additions & 5 deletions config/api_resources/node.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
---
RZ\Roadiz\CoreBundle\Entity\Node:
shortName: Node
collectionOperations: []
itemOperations:
get:
operations:
ApiPlatform\Metadata\Get:
method: 'GET'
normalization_context:
normalizationContext:
groups: ["node", "document_display"]
enable_max_depth: true
39 changes: 21 additions & 18 deletions config/api_resources/nodes_sources.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
---
RZ\Roadiz\CoreBundle\Entity\NodesSources:
iri: NodesSources
shortName: NodesSources
collectionOperations:
get:
operations:
ApiPlatform\Metadata\GetCollection:
method: "GET"
normalization_context:
normalizationContext:
groups:
- nodes_sources_base
- nodes_sources_default
Expand All @@ -14,28 +12,33 @@ RZ\Roadiz\CoreBundle\Entity\NodesSources:
- tag_base
- translation_base
- document_display
archives:

api_nodes_sources_archives:
class: ApiPlatform\Metadata\GetCollection
method: 'GET'
path: '/nodes_sources/archives'
uriTemplate: '/nodes_sources/archives'
pagination_enabled: false
pagination_client_enabled: false
archive_enabled: true
archive_publication_field_name: publishedAt
normalization_context:
extraProperties:
archive_enabled: true
archive_publication_field_name: publishedAt
normalizationContext:
groups:
- get
- archives
openapi_context:
openapiContext:
summary: Get available NodesSources archives
parameters: ~
description: |
Get available NodesSources archives (years and months) based on their `publishedAt` field
search:
api_nodes_sources_search:
class: ApiPlatform\Metadata\GetCollection
method: 'GET'
path: '/nodes_sources/search'
uriTemplate: '/nodes_sources/search'
controller: RZ\Roadiz\CoreBundle\Api\Controller\NodesSourcesSearchController
read: false
normalization_context:
normalizationContext:
groups:
- get
- nodes_sources_base
Expand All @@ -44,7 +47,7 @@ RZ\Roadiz\CoreBundle\Entity\NodesSources:
- tag_base
- translation_base
- document_display
openapi_context:
openapiContext:
summary: Search NodesSources resources
description: |
Search all website NodesSources resources using **Solr** full-text search engine
Expand All @@ -56,8 +59,8 @@ RZ\Roadiz\CoreBundle\Entity\NodesSources:
description: Search pattern
schema:
type: string
itemOperations:
get:

ApiPlatform\Metadata\Get:
method: 'GET'
normalization_context:
normalizationContext:
groups: ["nodes_sources", "urls", "tag_base", "translation_base", "document_display"]
38 changes: 24 additions & 14 deletions config/api_resources/nsarticle.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
App\GeneratedEntity\NSArticle:
iri: Article
shortName: Article
collectionOperations:
get:
types:
- Article
operations:
ApiPlatform\Metadata\GetCollection:
method: GET
normalization_context:
shortName: Article
normalizationContext:
enable_max_depth: true
groups:
- nodes_sources_base
Expand All @@ -15,10 +16,19 @@ App\GeneratedEntity\NSArticle:
- document_display
- document_thumbnails
- document_display_sources
itemOperations:
get:
_api_article_archives:
method: GET
normalization_context:
class: ApiPlatform\Metadata\GetCollection
shortName: Article
uriTemplate: /articles/archives
extraProperties:
archive_enabled: true
openapiContext:
summary: 'Retrieve all Article ressources archives months and years'
ApiPlatform\Metadata\Get:
method: GET
shortName: Article
normalizationContext:
groups:
- nodes_sources
- urls
Expand All @@ -28,12 +38,13 @@ App\GeneratedEntity\NSArticle:
- document_thumbnails
- document_display_sources
getByPath:
method: 'GET'
path: '/web_response_by_path'
read: false
method: GET
class: ApiPlatform\Metadata\Get
uriTemplate: /web_response_by_path
read: 'false'
controller: RZ\Roadiz\CoreBundle\Api\Controller\GetWebResponseByPathController
pagination_enabled: false
normalization_context:
pagination_enabled: 'false'
normalizationContext:
enable_max_depth: true
groups:
- nodes_sources
Expand All @@ -49,4 +60,3 @@ App\GeneratedEntity\NSArticle:
- walker_metadata
- meta
- children
- children_count
12 changes: 6 additions & 6 deletions config/api_resources/nsbasicblock.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
App\GeneratedEntity\NSBasicBlock:
iri: BasicBlock
shortName: BasicBlock
collectionOperations: { }
itemOperations:
get:
types:
- BasicBlock
operations:
ApiPlatform\Metadata\Get:
method: GET
normalization_context:
shortName: BasicBlock
normalizationContext:
groups:
- nodes_sources
- urls
Expand Down
12 changes: 6 additions & 6 deletions config/api_resources/nsgroupblock.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
App\GeneratedEntity\NSGroupBlock:
iri: GroupBlock
shortName: GroupBlock
collectionOperations: { }
itemOperations:
get:
types:
- GroupBlock
operations:
ApiPlatform\Metadata\Get:
method: GET
normalization_context:
shortName: GroupBlock
normalizationContext:
groups:
- nodes_sources
- urls
Expand Down
12 changes: 6 additions & 6 deletions config/api_resources/nsmenu.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
App\GeneratedEntity\NSMenu:
iri: Menu
shortName: Menu
collectionOperations: { }
itemOperations:
get:
types:
- Menu
operations:
ApiPlatform\Metadata\Get:
method: GET
normalization_context:
shortName: Menu
normalizationContext:
groups:
- nodes_sources
- urls
Expand Down
12 changes: 6 additions & 6 deletions config/api_resources/nsmenulink.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
App\GeneratedEntity\NSMenuLink:
iri: MenuLink
shortName: MenuLink
collectionOperations: { }
itemOperations:
get:
types:
- MenuLink
operations:
ApiPlatform\Metadata\Get:
method: GET
normalization_context:
shortName: MenuLink
normalizationContext:
groups:
- nodes_sources
- urls
Expand Down
12 changes: 6 additions & 6 deletions config/api_resources/nsneutral.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
App\GeneratedEntity\NSNeutral:
iri: Neutral
shortName: Neutral
collectionOperations: { }
itemOperations:
get:
types:
- Neutral
operations:
ApiPlatform\Metadata\Get:
method: GET
normalization_context:
shortName: Neutral
normalizationContext:
groups:
- nodes_sources
- urls
Expand Down
Loading

0 comments on commit f0317aa

Please sign in to comment.