Skip to content

Document requirements #312

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 3 commits into from
Oct 10, 2017
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
18 changes: 14 additions & 4 deletions core/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ just by specifying the enabled HTTP method.
The URL, the HTTP method and the Hydra context passed to documentation generators of operations is easy to configure.

In the next example, both `GET` and `PUT` operations are registered with custom URLs. Those will override the default generated
URLs. In addition to that, we replace the Hydra context for the `PUT` operation.
URLs. In addition to that, we replace the Hydra context for the `PUT` operation, and require the `id` parameter to be an integer.

<configurations>

Expand All @@ -128,8 +128,8 @@ use ApiPlatform\Core\Annotation\ApiResource;

/**
* @ApiResource(itemOperations={
* "get"={"method"="GET", "path"="/grimoire/{id}"},
* "put"={"method"="PUT", "path"="/grimoire/{id}/update", "hydra_context"={"foo"="bar"},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is that kind of trailing comma really supported?

Copy link
Member

Choose a reason for hiding this comment

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

why not :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right it's just an array after all...

* "get"={"method"="GET", "path"="/grimoire/{id}", "requirements"={"id"="\d+"}},
* "put"={"method"="PUT", "path"="/grimoire/{id}/update", "hydra_context"={"foo"="bar"}},
* })
*/
class Book
Expand All @@ -146,10 +146,14 @@ AppBundle\Entity\Book:
get:
method: 'GET'
path: '/grimoire/{id}'
requirements:
id: '\d+'
put:
method: 'PUT'
path: '/grimoire/{id}/update'
hydra_context: { foo: 'bar' }
requirements:
id: '\d+'
```
```xml
Expand All @@ -165,13 +169,19 @@ AppBundle\Entity\Book:
<itemOperation name="get">
<attribute name="method">GET</attribute>
<attribute name="path">/grimoire/{id}</attribute>
<attribute name="requirements">
<attribute name="id">\d+</attribute>
</attribute>
</itemOperation>
<itemOperation name="put">
<attribute name="method">PUT</attribute>
<attribute name="path">/grimoire/{id}/update</attribute>
<attribute name="hydra_context">
<attribute name="foo">bar</attribute>
</attribute>
<attribute name="requirements">
<attribute name="id">\d+</attribute>
</attribute>
</itemOperation>
</itemOperations>
</resource>
Expand Down Expand Up @@ -486,7 +496,7 @@ In this case, the entity will pass through [all built-in event listeners](events
automatically validated, persisted and serialized in JSON-LD. Then the Symfony kernel will send the resulting document to
the client.

Alternatively, you can also use standard Symfony controller and YAML or XML route declarations. The following example do
Alternatively, you can also use standard Symfony controller and YAML or XML route declarations. The following example does
exactly the same thing than the previous example in a more Symfony-like fashion:

```php
Expand Down