Skip to content

Add documentation on enabling format for specific operation #507

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 2 commits into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions core/content-negotiation.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,32 @@ Because the Symfony Serializer component is able to serialize objects in XML, se
`text/xml` string as value is enough to retrieve XML documents from our API. However API Platform knows nothing about the
`myformat` format. We need to register an encoder and optionally a normalizer for this format.


## Enabling Additional Formats On a Specific Resource/Operation

Support for specific formats can also be added at resource or operation level, using the `formats` attribute.

```php
<?php
// api/src/Entity/Book.php

namespace App\Entity;

/**
* @ApiResource(attributes={"formats"={"xml", "jsonld", "csv"={"text/csv"}}})
*/
class Book
{
// ...
}
```

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.
Additionally the `csv` format is added with the mime type `text/csv`.

It is also important to notice that the usage of this attribute will override the formats defined in the configuration, therefore
this configuration might disable the `json` or the `htlm` on this resource for example.

## Registering a Custom Serializer

If you are adding support for a format not supported by default by API Platform nor by the Symfony Serializer Component,
Expand Down
1 change: 0 additions & 1 deletion core/swagger.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ swagger_ui:

Change `/docs` to your desired URI you wish Swagger to be accessible on.

<<<<<<< HEAD
## Using the Swagger Command

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