Skip to content

fix(2.7 upgrade): text inconsistencies #1426

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
Mar 13, 2022
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
6 changes: 3 additions & 3 deletions core/content-negotiation.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ api_platform:

## Configuring Formats For a Specific Resource or Operation

Support for specific formats can also be configured at resource and operation level using the `input_formats` and `output_formats` attributes.
`input_formats` controls the formats accepted in request bodies while `output_formats` controls formats available for responses.
Support for specific formats can also be configured at resource and operation level using the `inputFormats` and `outputFormats` attributes.
`inputFormats` controls the formats accepted in request bodies while `outputFormats` controls formats available for responses.

The `formats` attribute can be used as a shortcut, it sets both the `input_formats` and `output_formats` in one time.
The `format` attribute can be used as a shortcut, it sets both the `inputFormats` and `outputFormats` in one time.

```php
<?php
Expand Down
13 changes: 6 additions & 7 deletions core/controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ automatically instantiated and injected, without having to declare it explicitly

In the following examples, the built-in `GET` operation is registered as well as a custom operation called `post_publication`.

By default, API Platform uses the first `GET` operation defined in `itemOperations` to generate the IRI of an item and the first `GET` operation defined in `collectionOperations` to generate the IRI of a collection.
By default, API Platform uses the first `Get` operation defined to generate the IRI of an item and the first `GetCollection` operation to generate the IRI of a collection.

If you create a custom operation, you will probably want to properly document it.
See the [OpenAPI](swagger.md) part of the documentation to do so.
Expand Down Expand Up @@ -147,7 +147,7 @@ the associated controller respectively.

## Using Serialization Groups

You may want different serialization groups for your custom operations. Just configure the proper `normalization_context` and/or `denormalization_context` in your operation:
You may want different serialization groups for your custom operations. Just configure the proper `normalizationContext` and/or `denormalizationContext` in your operation:

[codeSelector]

Expand Down Expand Up @@ -222,7 +222,7 @@ App\Entity\Book:

## Retrieving the Entity

If you want to bypass the automatic retrieval of the entity in your custom operation, you can set `"read"=false` in the
If you want to bypass the automatic retrieval of the entity in your custom operation, you can set `read: false` in the
operation attribute:

[codeSelector]
Expand Down Expand Up @@ -297,7 +297,7 @@ the configuration at the same time in the routing and the resource configuration
The `post_publication` operation references the Symfony route named `book_post_publication`.

Since version 2.3, you can also use the route name as operation name by convention, as shown in the following example
for `book_post_discontinuation` when neither `method` nor `route_name` attributes are specified.
for `book_post_discontinuation` when neither `method` nor `routeName` attributes are specified.

First, let's create your resource configuration:

Expand Down Expand Up @@ -380,7 +380,7 @@ class CreateBookPublication extends AbstractController
methods: ['POST'],
defaults: [
'_api_resource_class' => Book::class,
'_api_item_operation_name' => 'post_publication',
'_api_operation_name' => '_api_/books/{id}/publication_post',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be "post_publication" and not "api/books/{id}/publication_post" ?

],
)]
public function __invoke(Book $book): Book
Expand All @@ -392,8 +392,7 @@ class CreateBookPublication extends AbstractController
}
```

It is mandatory to set `_api_resource_class` and `_api_item_operation_name` (or `_api_collection_operation_name` for a collection
operation) in the parameters of the route (`defaults` key). It allows API Platform to work with the Symfony routing system.
It is mandatory to set `_api_resource_class` and `_api_operation_name` in the parameters of the route (`defaults` key). It allows API Platform to work with the Symfony routing system.

Alternatively, you can also use a traditional Symfony controller and YAML or XML route declarations. The following example does
the same thing as the previous example:
Expand Down
2 changes: 1 addition & 1 deletion core/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ In any other cases, your exception message will be sent to end users.

## Fine-grained Configuration

The `exception_to_status` configuration can be set on resources and operations:
The `exceptionToStatus` configuration can be set on resources and operations:

```php
<?php
Expand Down
4 changes: 2 additions & 2 deletions core/fosuser-bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ api_platform:
Here's an example of declaration of a [Doctrine ORM User class](https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.rst#a-doctrine-orm-user-class).
There's also an example for a [Doctrine MongoDB ODM](https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.rst#b-mongodb-user-class).
You need to use serialization groups to hide some properties like `plainPassword` (only in read) and `password`. The properties
shown are handled with [`normalization_context`](serialization.md#normalization), while the properties
you can modify are handled with [`denormalization_context`](serialization.md#denormalization).
shown are handled with [`normalizationContext`](serialization.md#normalization), while the properties
you can modify are handled with [`denormalizationContext`](serialization.md#denormalization).

Create your User entity with serialization groups:

Expand Down
2 changes: 1 addition & 1 deletion core/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ You may want to restrict some resource's attributes to your GraphQL clients.

As described in the [serialization process](serialization.md) documentation, you can use serialization groups to expose only the attributes you want in queries or in mutations.

If the (de)normalization context between GraphQL and REST is different, you need to change it in each GraphQL operation.
If the (de)normalization context between GraphQL and REST is different, use the `(de)normalizationContext` key to change it in each query and mutations.

Note that:

Expand Down
4 changes: 2 additions & 2 deletions core/openapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ This will produce the following Swagger documentation:
}
```

To pass a context to the OpenAPI **v2** generator, use the `swagger_context` attribute (notice the prefix: `swagger_` instead of `openapi_`).
To pass a context to the OpenAPI **v2** generator, use the `swaggerContext` attribute (notice the prefix: `swagger` instead of `openapi`).

## Changing the Name of a Definition

API Platform generates a definition name based on the serializer `groups` defined
in the (`de`)`normalization_context`. It's possible to override the name
in the (`de`)`normalizationContext`. It's possible to override the name
thanks to the `swagger_definition_name` option:

```php
Expand Down
96 changes: 82 additions & 14 deletions core/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,17 @@ Implementing [the standard `PUT` behavior](https://httpwg.org/specs/rfc7231.html
If no operation is specified, all default CRUD operations are automatically registered. It is also possible - and recommended
for large projects - to define operations explicitly.

Keep in mind that `collectionOperations` and `itemOperations` behave independently. For instance, if you don't explicitly
configure operations for `collectionOperations`, `GET` and `POST` operations will be automatically registered, even if you
explicitly configure `itemOperations`. The reverse is also true.
Keep in mind that once you explicitly set up an operation, the automatically registered CRUD will no longer be.
If you declare even one operation manually, such as `#[GET]`, you must declare the others manually as well if you need them.

Operations can be configured using annotations, XML or YAML. In the following examples, we enable only the built-in operation
for the `GET` method for both `collectionOperations` and `itemOperations` to create a readonly endpoint.

`itemOperations` and `collectionOperations` are arrays containing a list of operations. Each operation is defined by a key
corresponding to the name of the operation that can be anything you want and an array of properties as value. If an
empty list of operations is provided, all operations are disabled.
for the `GET` method for both `collection` and `item` to create a readonly endpoint.

If the operation's name matches a supported HTTP methods (`GET`, `POST`, `PUT`, `PATCH` or `DELETE`), the corresponding `method` property
will be automatically added.

Note: The `#[GetCollection]` attribute is an alias for `#[Get(collection: true)]`

[codeSelector]

```php
Expand Down Expand Up @@ -115,6 +112,7 @@ App\Entity\Book:

[/codeSelector]


The previous example can also be written with an explicit method definition:

[codeSelector]
Expand Down Expand Up @@ -189,7 +187,7 @@ use ApiPlatform\Metadata\ApiResource;
read: false,
output: false
)]
#[GetCollection]
#[GetCollection]
class Book
{
// ...
Expand Down Expand Up @@ -319,13 +317,11 @@ App\Entity\Book:

[/codeSelector]

In all these examples, the `method` attribute is omitted because it matches the operation name.

## Prefixing All Routes of All Operations

Sometimes it's also useful to put a whole resource into its own "namespace" regarding the URI. Let's say you want to
put everything that's related to a `Book` into the `library` so that URIs become `library/book/{id}`. In that case
you don't need to override all the operations to set the path but configure the `route_prefix` attribute for the whole entity instead:
you don't need to override all the operations to set the path but configure the `routePrefix` attribute for the whole entity instead:

[codeSelector]

Expand Down Expand Up @@ -363,7 +359,80 @@ App\Entity\Book:

[/codeSelector]

Alternatively, the more verbose attribute syntax can be used: `#[ApiResource(routePrefix: '/library')]`.
API Platform will automatically map this `post_publication` operation to the route `book_post_publication`. Let's create a custom action
and its related route using annotations:

```php
<?php
// api/src/Controller/CreateBookPublication.php

namespace App\Controller;

use App\Entity\Book;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Annotation\Route;

#[AsController]
class CreateBookPublication extends AbstractController
{
public function __construct(
private BookPublishingHandler $bookPublishingHandler
) {}

#[Route(
path: '/books/{id}/publication',
name: 'book_post_publication',
defaults: [
'_api_resource_class' => Book::class,
'_api_operation_name' => '_api_/books/{id}/publication_post',
],
methods: ['POST'],
)]
public function __invoke(Book $book): Book
{
$this->bookPublishingHandler->handle($book);

return $book;
}
}
```

It is mandatory to set `_api_resource_class` and `_api_operation_name`in the parameters of the route (`defaults` key). It allows API Platform to work with the Symfony routing system.

Alternatively, you can also use a traditional Symfony controller and YAML or XML route declarations. The following example does
the exact same thing as the previous example:

```php
<?php
// api/src/Controller/BookController.php

namespace App\Controller;

use App\Entity\Book;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Attribute\AsController;

#[AsController]
class BookController extends AbstractController
{
public function createPublication(Book $book, BookPublishingHandler $bookPublishingHandler): Book
{
return $bookPublishingHandler->handle($book);
}
}
```

```yaml
# api/config/routes.yaml
book_post_publication:
path: /books/{id}/publication
methods: ['POST']
defaults:
_controller: App\Controller\BookController::createPublication
_api_resource_class: App\Entity\Book
_api_operation_name: post_publication
```

## Expose a Model Without Any Routes

Expand Down Expand Up @@ -502,7 +571,6 @@ Then, remove the route from the decorator:
```php
<?php
// src/OpenApi/OpenApiFactory.php

namespace App\OpenApi;

use ApiPlatform\Core\OpenApi\Factory\OpenApiFactoryInterface;
Expand Down
2 changes: 1 addition & 1 deletion core/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class Book

## Cursor-Based Pagination

To configure your resource to use the cursor-based pagination, select your unique sorted field as well as the direction you’ll like the pagination to go via filters and enable the `pagination_via_cursor` option.
To configure your resource to use the cursor-based pagination, select your unique sorted field as well as the direction you’ll like the pagination to go via filters and enable the `paginationViaCursor` option.
Note that for now you have to declare a `RangeFilter` and an `OrderFilter` on the property used for the cursor-based pagination.

The following configuration also works on a specific operation:
Expand Down
2 changes: 1 addition & 1 deletion core/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ final class UserResourcesSubscriber implements EventSubscriberInterface

## Setting Custom HTTP Cache Headers

The `cache_headers` attribute can be used to set custom HTTP cache headers:
The `cacheHeaders` attribute can be used to set custom HTTP cache headers:

```php
use ApiPlatform\Metadata\ApiResource;
Expand Down
4 changes: 2 additions & 2 deletions core/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,14 @@ class BookVoter extends Voter
}
```

*Note 1: When using Voters on POST methods: The voter needs an `$attribute` and `$subject` as input parameter, so you have to use the `security_post_denormalize` (i.e. `"post" = { "security_post_denormalize" = "is_granted('BOOK_CREATE', object)" }` ) because the object does not exist before denormalization (it is not created, yet.)*
*Note 1: When using Voters on POST methods: The voter needs an `$attribute` and `$subject` as input parameter, so you have to use the `securityPostDenormalize` (i.e. `"post" = { "securityPostDenormalize" = "is_granted('BOOK_CREATE', object)" }` ) because the object does not exist before denormalization (it is not created, yet.)*

*Note 2: You can't use Voters on the collection GET method, use [Collection Filters](https://api-platform.com/docs/core/security/#filtering-collection-according-to-the-current-user-permissions) instead.*

## Configuring the Access Control Error Message

By default when API requests are denied, you will get the "Access Denied" message.
You can change it by configuring the `security_message` attribute or the `security_post_denormalize_message` attribute.
You can change it by configuring the `securityMessage` attribute or the `securityPostDenormalizeMessage` attribute.

For example:

Expand Down
2 changes: 1 addition & 1 deletion core/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ App\Entity\Person:

The problem here is that the **$parent** property become automatically an embedded object. Besides, the property won't be shown on the OpenAPI view.

To force the **$parent** property to be used as an IRI, add an **#[ApiProperty(readableLink: false, writableLink: false)]** annotation:
To force the **$parent** property to be used as an IRI, add an `#[ApiProperty(readableLink: false, writableLink: false)]` annotation:

[codeSelector]

Expand Down