Skip to content

Commit ed5738b

Browse files
PierreThibaudeausoyuka
PierreThibaudeau
andauthored
fix: text_inconsistencies (#1426)
_api_operation_name snake to camel case operations Co-authored-by: Antoine Bluchet <soyuka@users.noreply.github.com>
1 parent d74cd61 commit ed5738b

11 files changed

+102
-35
lines changed

core/content-negotiation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ api_platform:
9494

9595
## Configuring Formats For a Specific Resource or Operation
9696

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

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

102102
```php
103103
<?php

core/controllers.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ automatically instantiated and injected, without having to declare it explicitly
2121

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

24-
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.
24+
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.
2525

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

148148
## Using Serialization Groups
149149

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

152152
[codeSelector]
153153

@@ -222,7 +222,7 @@ App\Entity\Book:
222222

223223
## Retrieving the Entity
224224

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

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

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

302302
First, let's create your resource configuration:
303303

@@ -380,7 +380,7 @@ class CreateBookPublication extends AbstractController
380380
methods: ['POST'],
381381
defaults: [
382382
'_api_resource_class' => Book::class,
383-
'_api_item_operation_name' => 'post_publication',
383+
'_api_operation_name' => '_api_/books/{id}/publication_post',
384384
],
385385
)]
386386
public function __invoke(Book $book): Book
@@ -392,8 +392,7 @@ class CreateBookPublication extends AbstractController
392392
}
393393
```
394394

395-
It is mandatory to set `_api_resource_class` and `_api_item_operation_name` (or `_api_collection_operation_name` for a collection
396-
operation) in the parameters of the route (`defaults` key). It allows API Platform to work with the Symfony routing system.
395+
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.
397396

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

core/errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ In any other cases, your exception message will be sent to end users.
110110

111111
## Fine-grained Configuration
112112

113-
The `exception_to_status` configuration can be set on resources and operations:
113+
The `exceptionToStatus` configuration can be set on resources and operations:
114114

115115
```php
116116
<?php

core/fosuser-bundle.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ api_platform:
4646
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).
4747
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).
4848
You need to use serialization groups to hide some properties like `plainPassword` (only in read) and `password`. The properties
49-
shown are handled with [`normalization_context`](serialization.md#normalization), while the properties
50-
you can modify are handled with [`denormalization_context`](serialization.md#denormalization).
49+
shown are handled with [`normalizationContext`](serialization.md#normalization), while the properties
50+
you can modify are handled with [`denormalizationContext`](serialization.md#denormalization).
5151

5252
Create your User entity with serialization groups:
5353

core/graphql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ You may want to restrict some resource's attributes to your GraphQL clients.
12251225

12261226
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.
12271227

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

12301230
Note that:
12311231

core/openapi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,12 @@ This will produce the following Swagger documentation:
259259
}
260260
```
261261

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

264264
## Changing the Name of a Definition
265265

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

270270
```php

core/operations.md

Lines changed: 82 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,17 @@ Implementing [the standard `PUT` behavior](https://httpwg.org/specs/rfc7231.html
5454
If no operation is specified, all default CRUD operations are automatically registered. It is also possible - and recommended
5555
for large projects - to define operations explicitly.
5656

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

6160
Operations can be configured using annotations, XML or YAML. In the following examples, we enable only the built-in operation
62-
for the `GET` method for both `collectionOperations` and `itemOperations` to create a readonly endpoint.
63-
64-
`itemOperations` and `collectionOperations` are arrays containing a list of operations. Each operation is defined by a key
65-
corresponding to the name of the operation that can be anything you want and an array of properties as value. If an
66-
empty list of operations is provided, all operations are disabled.
61+
for the `GET` method for both `collection` and `item` to create a readonly endpoint.
6762

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

66+
Note: The `#[GetCollection]` attribute is an alias for `#[Get(collection: true)]`
67+
7168
[codeSelector]
7269

7370
```php
@@ -115,6 +112,7 @@ App\Entity\Book:
115112

116113
[/codeSelector]
117114

115+
118116
The previous example can also be written with an explicit method definition:
119117

120118
[codeSelector]
@@ -189,7 +187,7 @@ use ApiPlatform\Metadata\ApiResource;
189187
read: false,
190188
output: false
191189
)]
192-
#[GetCollection]
190+
#[GetCollection]
193191
class Book
194192
{
195193
// ...
@@ -319,13 +317,11 @@ App\Entity\Book:
319317

320318
[/codeSelector]
321319

322-
In all these examples, the `method` attribute is omitted because it matches the operation name.
323-
324320
## Prefixing All Routes of All Operations
325321

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

330326
[codeSelector]
331327

@@ -363,7 +359,80 @@ App\Entity\Book:
363359

364360
[/codeSelector]
365361

366-
Alternatively, the more verbose attribute syntax can be used: `#[ApiResource(routePrefix: '/library')]`.
362+
API Platform will automatically map this `post_publication` operation to the route `book_post_publication`. Let's create a custom action
363+
and its related route using annotations:
364+
365+
```php
366+
<?php
367+
// api/src/Controller/CreateBookPublication.php
368+
369+
namespace App\Controller;
370+
371+
use App\Entity\Book;
372+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
373+
use Symfony\Component\HttpKernel\Attribute\AsController;
374+
use Symfony\Component\Routing\Annotation\Route;
375+
376+
#[AsController]
377+
class CreateBookPublication extends AbstractController
378+
{
379+
public function __construct(
380+
private BookPublishingHandler $bookPublishingHandler
381+
) {}
382+
383+
#[Route(
384+
path: '/books/{id}/publication',
385+
name: 'book_post_publication',
386+
defaults: [
387+
'_api_resource_class' => Book::class,
388+
'_api_operation_name' => '_api_/books/{id}/publication_post',
389+
],
390+
methods: ['POST'],
391+
)]
392+
public function __invoke(Book $book): Book
393+
{
394+
$this->bookPublishingHandler->handle($book);
395+
396+
return $book;
397+
}
398+
}
399+
```
400+
401+
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.
402+
403+
Alternatively, you can also use a traditional Symfony controller and YAML or XML route declarations. The following example does
404+
the exact same thing as the previous example:
405+
406+
```php
407+
<?php
408+
// api/src/Controller/BookController.php
409+
410+
namespace App\Controller;
411+
412+
use App\Entity\Book;
413+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
414+
use Symfony\Component\HttpKernel\Attribute\AsController;
415+
416+
#[AsController]
417+
class BookController extends AbstractController
418+
{
419+
public function createPublication(Book $book, BookPublishingHandler $bookPublishingHandler): Book
420+
{
421+
return $bookPublishingHandler->handle($book);
422+
}
423+
}
424+
```
425+
426+
```yaml
427+
# api/config/routes.yaml
428+
book_post_publication:
429+
path: /books/{id}/publication
430+
methods: ['POST']
431+
defaults:
432+
_controller: App\Controller\BookController::createPublication
433+
_api_resource_class: App\Entity\Book
434+
_api_operation_name: post_publication
435+
```
367436
368437
## Expose a Model Without Any Routes
369438
@@ -502,7 +571,6 @@ Then, remove the route from the decorator:
502571
```php
503572
<?php
504573
// src/OpenApi/OpenApiFactory.php
505-
506574
namespace App\OpenApi;
507575

508576
use ApiPlatform\Core\OpenApi\Factory\OpenApiFactoryInterface;

core/pagination.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ class Book
309309

310310
## Cursor-Based Pagination
311311

312-
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.
312+
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.
313313
Note that for now you have to declare a `RangeFilter` and an `OrderFilter` on the property used for the cursor-based pagination.
314314

315315
The following configuration also works on a specific operation:

core/performance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ final class UserResourcesSubscriber implements EventSubscriberInterface
8888

8989
## Setting Custom HTTP Cache Headers
9090

91-
The `cache_headers` attribute can be used to set custom HTTP cache headers:
91+
The `cacheHeaders` attribute can be used to set custom HTTP cache headers:
9292

9393
```php
9494
use ApiPlatform\Metadata\ApiResource;

core/security.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,14 @@ class BookVoter extends Voter
282282
}
283283
```
284284

285-
*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.)*
285+
*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.)*
286286

287287
*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.*
288288

289289
## Configuring the Access Control Error Message
290290

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

294294
For example:
295295

core/serialization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ App\Entity\Person:
411411

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

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

416416
[codeSelector]
417417

0 commit comments

Comments
 (0)