|
@@ -3,7 +3,7 @@ You can use plugins to alter how the Generator fetches data about your routes. F
|
|
|
|
|
|
## The stages of route processing
|
|
## The stages of route processing
|
|
Route processing is performed in four stages:
|
|
Route processing is performed in four stages:
|
|
-- metadata (this covers route title, route description, route group name, route group description, and authentication status)
|
|
|
|
|
|
+- metadata (this covers route `title`, route `description`, route `groupName`, route `groupDescription`, and authentication status (`authenticated`))
|
|
- bodyParameters
|
|
- bodyParameters
|
|
- queryParameters
|
|
- queryParameters
|
|
- responses
|
|
- responses
|
|
@@ -18,7 +18,7 @@ The `__invoke` method of the strategy is where you perform your actions and retu
|
|
- the controller class handling the route (`\ReflectionClass`)
|
|
- the controller class handling the route (`\ReflectionClass`)
|
|
- the controller method (`\ReflectionMethod $method`)
|
|
- the controller method (`\ReflectionMethod $method`)
|
|
- the rules specified in the apidoc.php config file for the group this route belongs to, under the `apply` section (array)
|
|
- the rules specified in the apidoc.php config file for the group this route belongs to, under the `apply` section (array)
|
|
- - the context. This contains all data for the route that has been parsed thus far in the previous stages.
|
|
|
|
|
|
+ - the context. This contains all data for the route that has been parsed thus far in the previous stages. This means, by the `responses` stage, the context will contain the following keys: `metadata`, `bodyParameters` and `queryParameters`.
|
|
|
|
|
|
Here's what your strategy in our example would look like:
|
|
Here's what your strategy in our example would look like:
|
|
|
|
|
|
@@ -53,10 +53,10 @@ The last thing to do is to register the strategy. Strategies are registered in a
|
|
\Mpociot\ApiDoc\Strategies\Metadata\GetFromDocBlocks::class,
|
|
\Mpociot\ApiDoc\Strategies\Metadata\GetFromDocBlocks::class,
|
|
],
|
|
],
|
|
'bodyParameters' => [
|
|
'bodyParameters' => [
|
|
- \Mpociot\ApiDoc\Strategies\BodyParameters\GetFromDocBlocks::class,
|
|
|
|
|
|
+ \Mpociot\ApiDoc\Strategies\BodyParameters\GetFromBodyParamTag::class,
|
|
],
|
|
],
|
|
'queryParameters' => [
|
|
'queryParameters' => [
|
|
- \Mpociot\ApiDoc\Strategies\QueryParameters\GetFromDocBlocks::class,
|
|
|
|
|
|
+ \Mpociot\ApiDoc\Strategies\QueryParameters\GetFromQueryParamTag::class,
|
|
],
|
|
],
|
|
'responses' => [
|
|
'responses' => [
|
|
\Mpociot\ApiDoc\Strategies\Responses\UseResponseTag::class,
|
|
\Mpociot\ApiDoc\Strategies\Responses\UseResponseTag::class,
|
|
@@ -73,7 +73,7 @@ You can add, replace or remove strategies from here. In our case, we're adding o
|
|
```php
|
|
```php
|
|
|
|
|
|
'bodyParameters' => [
|
|
'bodyParameters' => [
|
|
- \Mpociot\ApiDoc\Strategies\BodyParameters\GetFromDocBlocks::class,
|
|
|
|
|
|
+ \Mpociot\ApiDoc\Strategies\BodyParameters\GetFromBodyParamTag::class,
|
|
AddOrganizationIdBodyParameter::class,
|
|
AddOrganizationIdBodyParameter::class,
|
|
],
|
|
],
|
|
```
|
|
```
|
|
@@ -106,3 +106,38 @@ public function __invoke(Route $route, \ReflectionClass $controller, \Reflection
|
|
```
|
|
```
|
|
|
|
|
|
The strategy class also has access to the current apidoc configuration via its config property. For instance, you can retrieve the deafult group with `$this->config->get('default_group')`.
|
|
The strategy class also has access to the current apidoc configuration via its config property. For instance, you can retrieve the deafult group with `$this->config->get('default_group')`.
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+## Utilities
|
|
|
|
+You have access to a number of tools when developing strategies. They include:
|
|
|
|
+
|
|
|
|
+- The `RouteDocBlocker` class (in the `\Mpociot\ApiDoc\Tools` namespace) has a single public static method, `getDocBlocksFromRoute(Route $route)`. It allows you to retrieve the docblocks for a given route. It returns an array of with two keys: `method` and `class` containing the docblocks for the method and controller handling the route respectively. Both are instances of `\Mpociot\Reflection\DocBlock`.
|
|
|
|
+
|
|
|
|
+- The `ParamsHelper` trait (in the `\Mpociot\ApiDoc\Tools` namespace) can be included in your strategies. It contains a number of useful methods for working with parameters, including type casting and generating dummy values.
|
|
|
|
+
|
|
|
|
+## API
|
|
|
|
+Each strategy class must implement the __invoke method with the parameters as described above. This method must return the needed data for the intended stage, or `null` to indicate failure.
|
|
|
|
+- In the `metadata` stage, strategies should return an array. These are the expected keys (you may omit some, or all):
|
|
|
|
+
|
|
|
|
+```
|
|
|
|
+'groupName'
|
|
|
|
+'groupDescription'
|
|
|
|
+'title'
|
|
|
|
+'description'
|
|
|
|
+'authenticated' // boolean
|
|
|
|
+```
|
|
|
|
+
|
|
|
|
+- In the `bodyParameters` and `queryParameters` stages, you can return an array with arbitrary keys. These keys will serve as the names of your parameters. Array keys can be indicated with Laravel's dot notation. The value of each key should be an array with the following keys:
|
|
|
|
+
|
|
|
|
+```
|
|
|
|
+'type', // Only used in bodyParameters
|
|
|
|
+'description',
|
|
|
|
+'required', // boolean
|
|
|
|
+'value', // An example value for the parameter
|
|
|
|
+```
|
|
|
|
+- In the `responses` stage, your strategy should return an array containing the responses for different status codes. Each key in the array should be a HTTP status code, and each value should be an array with two keys:
|
|
|
|
+
|
|
|
|
+```
|
|
|
|
+status // The same status code
|
|
|
|
+content // The response content as a string
|
|
|
|
+```
|