Skip to content

Commit 3fab289

Browse files
committed
Update readme with description of multiple response/responsefile tags support
1 parent 239d56d commit 3fab289

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,24 @@ public function show($id)
259259
}
260260
```
261261

262+
Moreover, you can define multiple `@response` tags as well as the HTTP status code related to a particular response (if no status code set, `200` will be returned):
263+
```php
264+
/**
265+
* @response {
266+
* "id": 4,
267+
* "name": "Jessica Jones",
268+
* "roles": ["admin"]
269+
* }
270+
* @response 404 {
271+
* "message": "No query results for model [\App\User]"
272+
* }
273+
*/
274+
public function show($id)
275+
{
276+
return User::findOrFail($id);
277+
}
278+
```
279+
262280
#### @transformer, @transformerCollection, and @transformerModel
263281
You can define the transformer that is used for the result of the route using the `@transformer` tag (or `@transformerCollection` if the route returns a list). The package will attempt to generate an instance of the model to be transformed using the following steps, stopping at the first successful one:
264282

@@ -327,6 +345,18 @@ public function getUser(int $id)
327345
```
328346
The package will parse this response and display in the examples for this route.
329347

348+
Similarly to `@response` tag, you can provide multiple `@responseFile` tags along with the HTTP status code of the response:
349+
```php
350+
/**
351+
* @responseFile responses/users.get.json
352+
* @responseFile 404 responses/model.not.found.json
353+
*/
354+
public function getUser(int $id)
355+
{
356+
// ...
357+
}
358+
```
359+
330360
#### Generating responses automatically
331361
If you don't specify an example response using any of the above means, this package will attempt to get a sample response by making a request to the route (a "response call"). A few things to note about response calls:
332362
- They are done within a database transaction and changes are rolled back afterwards.

0 commit comments

Comments
 (0)