You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+31-1Lines changed: 31 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -259,6 +259,24 @@ public function show($id)
259
259
}
260
260
```
261
261
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
+
262
280
#### @transformer, @transformerCollection, and @transformerModel
263
281
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:
For large reponse bodies, you may want to use a dump of an actual response. You can put this response in a file (as a JSON string) within your Laravel storage directory and link to it. For instance, we can put this response in a file named `users.get.json` in `storage/responses`:
329
+
For large response bodies, you may want to use a dump of an actual response. You can put this response in a file (as a JSON string) within your Laravel storage directory and link to it. For instance, we can put this response in a file named `users.get.json` in `storage/responses`:
312
330
313
331
```
314
332
{"id":5,"name":"Jessica Jones","gender":"female"}
@@ -327,6 +345,18 @@ public function getUser(int $id)
327
345
```
328
346
The package will parse this response and display in the examples for this route.
329
347
348
+
Similarly to `@response` tag, you can provide multiple `@responseFile` tags along with the HTTP status code of the response:
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:
332
362
- They are done within a database transaction and changes are rolled back afterwards.
0 commit comments