Skip to content

[api-platform/core] sane defaults for API Platform 3.2 #1240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

soyuka
Copy link
Contributor

@soyuka soyuka commented Sep 15, 2023

Q A
License MIT

In API Platform 4 json will be disabled by default so it's now recommended to explicit formats.
For event_listeners_backward_compatibility_layer see api-platform/core#5657
We're using the Symfony Inflector now but this will probably break current code so we need a flag to keep_legacy_inflector
The rfc_7807_compliant_errors is to make Hydra errors compatible with the JSON Problem specification. This may lead to unexpected error fields and therefore we need a compatibility flag.

@symfony-recipes-bot symfony-recipes-bot enabled auto-merge (squash) September 15, 2023 15:52
@github-actions
Copy link

github-actions bot commented Sep 15, 2023

Thanks for the PR 😍

How to test these changes in your application

  1. Define the SYMFONY_ENDPOINT environment variable:

    # On Unix-like (BSD, Linux and macOS)
    export SYMFONY_ENDPOINT=https://raw.githubusercontent.com/symfony/recipes/flex/pull-1240/index.json
    # On Windows
    SET SYMFONY_ENDPOINT=https://raw.githubusercontent.com/symfony/recipes/flex/pull-1240/index.json
  2. Install the package(s) related to this recipe:

    composer req 'symfony/flex:^1.16'
    composer req 'api-platform/core:^3.2'
  3. Don't forget to unset the SYMFONY_ENDPOINT environment variable when done:

    # On Unix-like (BSD, Linux and macOS)
    unset SYMFONY_ENDPOINT
    # On Windows
    SET SYMFONY_ENDPOINT=

Diff between recipe versions

In order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes.
I'm going keep this comment up to date with any updates of the attached patch.

api-platform/core

2.1 vs 2.5
diff --git a/api-platform/core/2.1/config/packages/api_platform.yaml b/api-platform/core/2.5/config/packages/api_platform.yaml
index e453d1d..2eb7b4c 100644
--- a/api-platform/core/2.1/config/packages/api_platform.yaml
+++ b/api-platform/core/2.5/config/packages/api_platform.yaml
@@ -1,3 +1,7 @@
 api_platform:
     mapping:
         paths: ['%kernel.project_dir%/src/Entity']
+    patch_formats:
+        json: ['application/merge-patch+json']
+    swagger:
+        versions: [3]
2.5 vs 3.0
diff --git a/api-platform/core/2.5/config/packages/api_platform.yaml b/api-platform/core/2.5/config/packages/api_platform.yaml
deleted file mode 100644
index 2eb7b4c..0000000
--- a/api-platform/core/2.5/config/packages/api_platform.yaml
+++ /dev/null
@@ -1,7 +0,0 @@
-api_platform:
-    mapping:
-        paths: ['%kernel.project_dir%/src/Entity']
-    patch_formats:
-        json: ['application/merge-patch+json']
-    swagger:
-        versions: [3]
diff --git a/api-platform/core/2.5/manifest.json b/api-platform/core/3.0/manifest.json
index a886a48..af16452 100644
--- a/api-platform/core/2.5/manifest.json
+++ b/api-platform/core/3.0/manifest.json
@@ -1,6 +1,6 @@
 {
     "bundles": {
-        "ApiPlatform\\Core\\Bridge\\Symfony\\Bundle\\ApiPlatformBundle": ["all"]
+        "ApiPlatform\\Symfony\\Bundle\\ApiPlatformBundle": ["all"]
     },
     "copy-from-recipe": {
         "config/": "%CONFIG_DIR%/",
diff --git a/api-platform/core/2.5/src/Entity/.gitignore b/api-platform/core/3.0/src/ApiResource/.gitignore
similarity index 100%
rename from api-platform/core/2.5/src/Entity/.gitignore
rename to api-platform/core/3.0/src/ApiResource/.gitignore
3.0 vs 3.1
diff --git a/api-platform/core/3.1/config/packages/api_platform.yaml b/api-platform/core/3.1/config/packages/api_platform.yaml
new file mode 100644
index 0000000..41c7993
--- /dev/null
+++ b/api-platform/core/3.1/config/packages/api_platform.yaml
@@ -0,0 +1,10 @@
+api_platform:
+    title: Hello API Platform
+    version: 1.0.0
+    # Good defaults for REST APIs
+    defaults:
+        stateless: true
+        cache_headers:
+            vary: ['Content-Type', 'Authorization', 'Origin']
+        extra_properties:
+            standard_put: true
3.1 vs 3.2
diff --git a/api-platform/core/3.1/config/packages/api_platform.yaml b/api-platform/core/3.2/config/packages/api_platform.yaml
index 41c7993..219eefa 100644
--- a/api-platform/core/3.1/config/packages/api_platform.yaml
+++ b/api-platform/core/3.2/config/packages/api_platform.yaml
@@ -1,10 +1,18 @@
 api_platform:
     title: Hello API Platform
     version: 1.0.0
-    # Good defaults for REST APIs
+    formats:
+        jsonld: ['application/ld+json']
+    doc_formats:
+        jsonld: ['application/ld+json']
+        jsonopenapi: ['application/vnd.openapi+json']
+        html: ['text/html']
     defaults:
         stateless: true
         cache_headers:
             vary: ['Content-Type', 'Authorization', 'Origin']
         extra_properties:
             standard_put: true
+            rfc_7807_compliant_errors: true
+    event_listeners_backward_compatibility_layer: false
+    keep_legacy_inflector: false

auto-merge was automatically disabled September 16, 2023 07:59

Head branch was pushed to by a user without write access

@symfony-recipes-bot symfony-recipes-bot enabled auto-merge (squash) September 16, 2023 07:59
auto-merge was automatically disabled September 17, 2023 09:40

Head branch was pushed to by a user without write access

@symfony-recipes-bot symfony-recipes-bot enabled auto-merge (squash) September 17, 2023 09:40
auto-merge was automatically disabled September 17, 2023 10:15

Head branch was pushed to by a user without write access

@symfony-recipes-bot symfony-recipes-bot enabled auto-merge (squash) September 17, 2023 10:15
dunglas
dunglas previously approved these changes Sep 17, 2023
auto-merge was automatically disabled September 17, 2023 10:59

Head branch was pushed to by a user without write access

@symfony-recipes-bot symfony-recipes-bot enabled auto-merge (squash) September 17, 2023 10:59
nicolas-grekas
nicolas-grekas previously approved these changes Sep 19, 2023
auto-merge was automatically disabled September 19, 2023 10:27

Head branch was pushed to by a user without write access

@symfony-recipes-bot symfony-recipes-bot enabled auto-merge (squash) September 19, 2023 10:27
@symfony-recipes-bot symfony-recipes-bot merged commit a5c8679 into symfony:main Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants