Skip to content

Commit 36e65b3

Browse files
committed
Add documentation on enabling format for specific operation
api-platform/core#1798
1 parent d2925f4 commit 36e65b3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

core/content-negotiation.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,32 @@ Because the Symfony Serializer component is able to serialize objects in XML, se
5555
`text/xml` string as value is enough to retrieve XML documents from our API. However API Platform knows nothing about the
5656
`myformat` format. We need to register an encoder and optionally a normalizer for this format.
5757

58+
59+
## Enabling Additional Formats On a Specific Resource/Operation
60+
61+
Since Api-platform 2.3, support for specific formats can also be added at resource or operation level, using the `formats` attribute.
62+
63+
```php
64+
<?php
65+
// api/src/Entity/Book.php
66+
67+
namespace App\Entity;
68+
69+
/**
70+
* @ApiResource(attributes={"formats"={"xml", "jsonld", "csv"={"text/csv"}}})
71+
*/
72+
class Book
73+
{
74+
// ...
75+
}
76+
```
77+
78+
In the example above, `xml` or `jsonld` will be allowed and there is no need to specify the mime types as they are already defined in the configuration.
79+
Additionally the `csv` format is added with the mime type `text/csv`.
80+
81+
It is also important to notice that the usage of this attribute will override the formats defined in the configuration, therefore
82+
this configuration might disable the `json` or the `htlm` on this resource for example.
83+
5884
## Registering a Custom Serializer
5985

6086
If you are adding support for a format not supported by default by API Platform nor by the Symfony Serializer Component,

core/swagger.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ swagger_ui:
276276
277277
Change `/docs` to your desired URI you wish Swagger to be accessible on.
278278

279-
<<<<<<< HEAD
280279
## Using the Swagger Command
281280

282281
You can also dump your current Swagger documentation using the provided command:

0 commit comments

Comments
 (0)