Skip to content

Commit 8f3361b

Browse files
authored
docs: 4.4 Content-Type charset + drop dead Symfony <=6.4 branch (#2329)
* docs(content-negotiation): document 4.4 charset change Since 4.4 (core #8226), Content-Type only gets `; charset=utf-8` for text/* and application/xml; JSON-family media types no longer carry it. Verified against formatContentType() in src/State/Util/HttpResponseHeadersTrait.php at upstream/4.4. * docs(serialization): drop unreachable Symfony <=6.4 branch Symfony floor is ^7.4 || ^8.0 since core #8397 (verified in src/Symfony/composer.json at upstream/4.4), so the annotations branch is unreachable and the >=7.0 branch is unconditional. Collapse both into a single attributes-only instruction. * docs(getting-started): state PHP/Symfony version floor No page stated the supported versions. Add PHP >=8.2 and Symfony ^7.4 || ^8.0, taken from composer.json and src/Symfony/composer.json at upstream/4.4.
1 parent 779f487 commit 8f3361b

3 files changed

Lines changed: 39 additions & 33 deletions

File tree

‎core/content-negotiation.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,37 @@ API Platform automatically adds two HTTP headers to responses for resources:
420420

421421
> See [LDP §4.2 / Primer notes on Accept-Post](https://www.w3.org/TR/ldp/#Accept-Post) and typical
422422
> exposure via OPTIONS.
423+
424+
## Content-Type Charset
425+
426+
> [!NOTE] Behavioral change in API Platform 4.4 (core
427+
> [#8226](https://github.com/api-platform/core/pull/8226)).
428+
429+
Since 4.4, the `; charset=utf-8` parameter is only appended to the `Content-Type` response header
430+
for media types whose IANA registration actually defines a `charset` parameter: `text/*` types (for
431+
example `text/html`, `text/csv`, `text/xml`) and `application/xml`. JSON-based media types —
432+
`application/json`, `application/ld+json`, `application/hal+json`, `application/vnd.api+json`,
433+
`application/merge-patch+json`, `application/problem+json`, and so on — do not define a `charset`
434+
parameter (per RFC 8259, and the `+json` structured syntax suffix of RFC 6839) and are always UTF-8,
435+
so the parameter is no longer added to them.
436+
437+
Before 4.4, `; charset=utf-8` was appended unconditionally to every response, including JSON-based
438+
formats. For example, for a JSON-LD response:
439+
440+
```diff
441+
- Content-Type: application/ld+json; charset=utf-8
442+
+ Content-Type: application/ld+json
443+
```
444+
445+
An XML response is unaffected, as `application/xml` still gets the parameter:
446+
447+
```http
448+
Content-Type: application/xml; charset=utf-8
449+
```
450+
451+
> [!WARNING] If a client or a test asserts on the exact `Content-Type` header value for a JSON-based
452+
> format, it will break after upgrading to 4.4: the `charset=utf-8` suffix is gone. Update those
453+
> assertions accordingly.
454+
455+
The rule is implemented in `formatContentType()` in
456+
[`HttpResponseHeadersTrait`](https://github.com/api-platform/core/blob/4.4/src/State/Util/HttpResponseHeadersTrait.php).

‎core/getting-started.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
You can choose your preferred stack between Symfony, Laravel, or bootstrapping the API Platform core
66
library manually.
77

8+
API Platform requires PHP 8.2 or higher. The Symfony variant requires Symfony `^7.4` or `^8.0`.
9+
810
> [!CAUTION] If you are migrating from an older version of API Platform, make sure you read the
911
> [Upgrade Guide](upgrade-guide.md).
1012

‎core/serialization.md‎

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,45 +62,15 @@ Just like other Symfony and API Platform components, the Serializer component ca
6262
using attributes, XML or YAML. Since attributes are easy to understand, we will use them in the
6363
following examples.
6464

65-
> [!NOTE] If you are not using the API Platform Symfony variant, you need to enable annotation
66-
> support in the serializer configuration as outlined below, depending on your Symfony version.
67-
68-
#### Configuration for Symfony `<= 6.4`
69-
70-
##### General Case
65+
> [!NOTE] If you are not using the API Platform Symfony variant, you need to enable attribute
66+
> support in the serializer configuration as outlined below.
7167
7268
Add the following configuration to your `framework.yaml` file:
7369

7470
```yaml
7571
# api/config/packages/framework.yaml
7672
framework:
77-
serializer: { enable_annotations: true }
78-
```
79-
80-
##### Using Symfony Flex
81-
82-
If you use [Symfony Flex](https://github.com/symfony/flex) and Symfony `<= 6.4`, simply run the
83-
following command:
84-
85-
```console
86-
composer req doctrine/annotations
87-
```
88-
89-
You're all set!
90-
91-
#### Configuration for Symfony `>= 7.0`
92-
93-
If you are using Symfony >= 7.0,
94-
[annotations have been replaced by attributes](https://www.doctrine-project.org/2022/11/04/annotations-to-attributes.html).
95-
96-
Update your configuration as follows:
97-
98-
```diff
99-
# api/config/packages/framework.yaml
100-
101-
framework:
102-
- serializer: { enable_annotations: true }
103-
+ serializer: { enable_attributes: true }
73+
serializer: { enable_attributes: true }
10474
```
10575
10676
#### Additional Syntax Configuration for All Versions

0 commit comments

Comments
 (0)