Skip to content

feat(doc): use snake case names on operation sub options #1536

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
Jul 20, 2022
Merged
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
83 changes: 83 additions & 0 deletions core/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,89 @@ App\Entity\Book:

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

When specifying sub options, you must always use snake case as demonstrated below with the `denormalization_context` option on the `put` operation:

[codeSelector]

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

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;

#[ApiResource(
itemOperations: [
'get',
'put' => [
'denormalization_context' => [
'groups' => ['item:put'],
'swagger_definition_name' => 'put',
],
],
'delete',
],
],
denormalizationContext: [
'groups' => ['item:post'],
'swagger_definition_name' => 'post',
],
)]
class Book
{
//...
}
```

```yaml
# api/config/api_platform/resources.yaml
App\Entity\Book:
itemOperations:
get: ~
put:
denormalization_context:
groups: ['item:put']
swagger_definition_name: 'put',
delete: ~
denormalizationContext:
groups: ['item:post']
swagger_definition_name: 'post'
```

```xml
<?xml version="1.0" encoding="UTF-8" ?>
<!-- api/config/api_platform/resources.xml -->

<resources xmlns="https://api-platform.com/schema/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata
https://api-platform.com/schema/metadata/metadata-2.0.xsd">
<resource class="App\Entity\Book">
<itemOperations>
<itemOperation name="get" />
<itemOperation name="put">
<attribute name="denormalization_context">
<attribute name="groups">
<attribute>item:put</attribute>
</attribute>
<attribute name="swagger_definition_name">put</attribute>
</attribute>
</itemOperation>
<itemOperation name="delete" />
</itemOperations>
<denormalizationContext>
<attribute name="groups">
<attribute>item:post</attribute>
</attribute>
<attribute name="swagger_definition_name">post</attribute>
</denormalizationContext>
</resource>
</resources>
```

[/codeSelector]

## 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
Expand Down