mirror of
https://github.com/ambieco/scribe.git
synced 2026-04-24 10:44:55 +08:00
Adds the ability to declare 'authenticated' in controller doc block
This commit is contained in:
@@ -94,9 +94,9 @@ They will be included in the generated documentation text and example requests.
|
||||
|
||||
**Result:**
|
||||
|
||||

|
||||

|
||||
|
||||

|
||||

|
||||
|
||||
### Example parameters
|
||||
For each parameter in your request, this package will generate a random value to be used in the example requests. If you'd like to specify an example value, you can do so by adding `Example: your-example` to the end of your description. For instance:
|
||||
@@ -114,11 +114,11 @@ For each parameter in your request, this package will generate a random value to
|
||||
|
||||
You can also exclude a particular parameter from the generated examples (for all languages) by annotating it with `No-example`. For instance:
|
||||
```php
|
||||
/**
|
||||
* @queryParam location_id required The id of the location. Example: 1
|
||||
* @queryParam user_id required The id of the user. No-example
|
||||
* @queryParam page required The page number. Example: 4
|
||||
*/
|
||||
/**
|
||||
* @queryParam location_id required The id of the location. Example: 1
|
||||
* @queryParam user_id required The id of the user. No-example
|
||||
* @queryParam page required The page number. Example: 4
|
||||
*/
|
||||
```
|
||||
Outputs:
|
||||
```bash
|
||||
@@ -151,6 +151,41 @@ public function createPost(MyRequest $request)
|
||||
## Indicating authentication status
|
||||
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.
|
||||
|
||||
Just like `@group` annotation, you can also specify an `@authenticated` on a single method to override the authenticated status defined at the controller level.
|
||||
|
||||
```php
|
||||
/**
|
||||
* @authenticated
|
||||
*
|
||||
* APIs for managing users
|
||||
*/
|
||||
class UserController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Create a user
|
||||
*
|
||||
* [Insert optional longer description of the API endpoint here.]
|
||||
*
|
||||
*/
|
||||
public function createUser()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group Account management
|
||||
*
|
||||
*/
|
||||
public function changePassword()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Now all the methods under this controller will have "Requires authentication" badge enabled.
|
||||
|
||||
## Providing an example response
|
||||
You can provide an example response for a route. This will be displayed in the examples section. There are several ways of doing this.
|
||||
|
||||
|
||||
@@ -17,15 +17,16 @@ class GetFromDocBlocks extends Strategy
|
||||
$docBlocks = RouteDocBlocker::getDocBlocksFromRoute($route);
|
||||
/** @var DocBlock $methodDocBlock */
|
||||
$methodDocBlock = $docBlocks['method'];
|
||||
$classDocBlock = $docBlocks['class'];
|
||||
|
||||
list($routeGroupName, $routeGroupDescription, $routeTitle) = $this->getRouteGroupDescriptionAndTitle($methodDocBlock, $docBlocks['class']);
|
||||
list($routeGroupName, $routeGroupDescription, $routeTitle) = $this->getRouteGroupDescriptionAndTitle($methodDocBlock, $classDocBlock);
|
||||
|
||||
return [
|
||||
'groupName' => $routeGroupName,
|
||||
'groupDescription' => $routeGroupDescription,
|
||||
'title' => $routeTitle ?: $methodDocBlock->getShortDescription(),
|
||||
'description' => $methodDocBlock->getLongDescription()->getContents(),
|
||||
'authenticated' => $this->getAuthStatusFromDocBlock($methodDocBlock->getTags()),
|
||||
'authenticated' => $this->getAuthStatusFromDocBlock($classDocBlock->getTags())?:$this->getAuthStatusFromDocBlock($methodDocBlock->getTags()),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -48,7 +49,7 @@ class GetFromDocBlocks extends Strategy
|
||||
* @param DocBlock $methodDocBlock
|
||||
* @param DocBlock $controllerDocBlock
|
||||
*
|
||||
* @return array The route group name, the group description, ad the route title
|
||||
* @return array The route group name, the group description, and the route title
|
||||
*/
|
||||
protected function getRouteGroupDescriptionAndTitle(DocBlock $methodDocBlock, DocBlock $controllerDocBlock)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user