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
+13-4Lines changed: 13 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -200,8 +200,7 @@ They will be included in the generated documentation text and example requests.
200
200
You can use the `@authenticated` annotation on a method to indicate if the endpoint is authenticated. A "Requires authentication" badge will be added to that route in the generated documentation.
201
201
202
202
### Providing an example response
203
-
You can provide an example response for a route. This will be disaplyed in the examples section. There are several ways of doing this.
204
-
203
+
You can provide an example response for a route. This will be displayed in the examples section. There are several ways of doing this.
205
204
206
205
#### @response
207
206
You can provide an example response for a route by using the `@response` annotation with valid JSON:
@@ -223,7 +222,7 @@ public function show($id)
223
222
#### @transformer, @transformerCollection, and @transformerModel
224
223
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:
225
224
226
-
1. Check if there is a `@transformerModel` tag to define the model being transformed. If there is none, use the class of the first parameter to the method.
225
+
1. Check if there is a `@transformerModel` tag to define the model being transformed. If there is none, use the class of the first parameter to the transformer's `transform()`method.
227
226
2. Get an instance of the model from the Eloquent model factory
228
227
2. If the parameter is an Eloquent model, load the first from the database.
229
228
3. Create an instance using `new`.
@@ -261,7 +260,17 @@ public function showUser(int $id)
261
260
```
262
261
For the first route above, this package will generate a set of two users then pass it through the transformer. For the last two, it will generate a single user and then pass it through the transformer.
263
262
264
-
#### Postman collections
263
+
#### Gnerating responses automatically
264
+
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:
265
+
- They are done within a database transaction and changes are rolled back afterwards.
266
+
- The configuration for response calls is located in the `config/apidoc.php`. They are configured within the `['apply']['response_calls']` section for each route group, allowing you to apply different settings for different sets of routes.
267
+
- By default, response calls are only made for GET routes, but you can configure this. Set the `methods` key to an array of methods or '*' to mean all methods. Leave it as an empty array to turn off response calls for that route group.
268
+
- Parameters in URLs (example: `/users/{user}`, `/orders/{id?}`) will be replaced with '1' by default. You can configure this, however.Put the parameter names (including curly braces and question marks) as the keys and their replacements as the values in the `bindings` key.
269
+
- You can configure environment variables (this is useful so you can prevent external services like notifications from being triggered). By default the APP_ENV is set to 'documentation'. You can add more variables in the `env` key.
270
+
- You can also configure what headers, query parameters and body parameters should be sent when making the request (the `headers`, `query`, and `body` keys respectively).
271
+
272
+
273
+
### Postman collections
265
274
266
275
The generator automatically creates a Postman collection file, which you can import to use within your [Postman app](https://www.getpostman.com/apps) for even simpler API testing and usage.
0 commit comments