Skip to content

Commit 30ca099

Browse files
authored
Merge pull request #2 from mpociot/master
Update from base
2 parents 3e21c5f + af9da31 commit 30ca099

File tree

12 files changed

+96
-74
lines changed

12 files changed

+96
-74
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ composer.lock
33
.php_cs.cache
44
/vendor/
55
/public
6+
.idea/
7+
coverage.xml
8+
results.xml

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ before_script:
1010
- travis_retry composer install --prefer-dist --no-interaction
1111

1212
script:
13-
- vendor/bin/phpunit --coverage-clover=coverage.xml
13+
- composer test-ci
1414

1515
before_install:
1616
- pip install --user codecov
1717

1818
after_success:
19-
- codecov
19+
- codecov

CHANGELOG.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). If you make a pull request to this project, please update this changelog.
6+
7+
## Unreleased
8+
### Added
9+
10+
### Changed
11+
12+
### Fixed
13+
14+
### Removed
15+
16+
## [2.1.2] - 10th September, 2018
17+
### Fixed
18+
- Set correct HTTP method when parsing FormRequest (https://github.com/mpociot/laravel-apidoc-generator/pull/314)
19+
20+
## [2.1.1] - 10th September, 2018
21+
### Fixed
22+
- Print the correct file path of generated documentation (https://github.com/mpociot/laravel-apidoc-generator/pull/311)
23+
- Removed any extra slashes in URLs displayed in code samples (https://github.com/mpociot/laravel-apidoc-generator/pull/310)
24+
- Response calls are now also made for only GET in DIngo Router (https://github.com/mpociot/laravel-apidoc-generator/pull/309)
25+
- HEAD routes are no longer automatically generated for GET routes in DIngo Router (https://github.com/mpociot/laravel-apidoc-generator/pull/309)
26+
27+
## [2.1.0] - 9th September, 2018
28+
### Added
29+
- Added support for multiple route domains (https://github.com/mpociot/laravel-apidoc-generator/pull/255)
30+
- Added support for descriptions in custom validation rules (https://github.com/mpociot/laravel-apidoc-generator/pull/208)
31+
- Added support for multiple route prefixes (https://github.com/mpociot/laravel-apidoc-generator/pull/203)
32+
- Added support for formatting and `<aside>` tags (https://github.com/mpociot/laravel-apidoc-generator/pull/261)
33+
- Support for Laravel 5.5 auto-discovery (https://github.com/mpociot/laravel-apidoc-generator/pull/217)
34+
35+
### Changed
36+
- Response calls are now only made when route is GET (https://github.com/mpociot/laravel-apidoc-generator/pull/279)
37+
- Validator factory is now passed to `FormRequest::validator` method (https://github.com/mpociot/laravel-apidoc-generator/pull/236)
38+
- Bind optional model parameters in routes (https://github.com/mpociot/laravel-apidoc-generator/pull/297/)
39+
- HEAD routes are no longer automatically generated for GET routes (https://github.com/mpociot/laravel-apidoc-generator/pull/180)
40+
- `actAsUserId` option is no longer cast to an int (https://github.com/mpociot/laravel-apidoc-generator/pull/257)
41+
42+
### Fixed
43+
- `useMiddleware` option is now actually used (https://github.com/mpociot/laravel-apidoc-generator/pull/297/)
44+
- Changes to the info vendor view are now persisted (https://github.com/mpociot/laravel-apidoc-generator/pull/120)
45+
- Fixed memory leak issues (https://github.com/mpociot/laravel-apidoc-generator/pull/256)
46+
- Fixed issues with validating array parameters (https://github.com/mpociot/laravel-apidoc-generator/pull/299)
47+
- `@response` tag now parses content correctly as JSON (https://github.com/mpociot/laravel-apidoc-generator/pull/271)
48+
49+
### Removed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ If the project maintainer has any additional requirements, you will find them li
4444

4545
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
4646

47-
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
47+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. Add your changes to the `CHANGELOG.md` under the "Unreleased" section.
4848

4949
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
5050

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ Automatically generate your API documentation from your existing Laravel routes.
44

55
`php artisan api:gen --routePrefix="settings/api/*"`
66

7-
![image](http://img.shields.io/packagist/v/mpociot/laravel-apidoc-generator.svg?style=flat)
8-
![image](http://img.shields.io/packagist/l/mpociot/laravel-apidoc-generator.svg?style=flat)
7+
[![Latest Stable Version](https://poser.pugx.org/mpociot/laravel-apidoc-generator/v/stable)](https://packagist.org/packages/mpociot/laravel-apidoc-generator)[![Total Downloads](https://poser.pugx.org/mpociot/laravel-apidoc-generator/downloads)](https://packagist.org/packages/mpociot/laravel-apidoc-generator)
8+
[![License](https://poser.pugx.org/mpociot/laravel-apidoc-generator/license)](https://packagist.org/packages/mpociot/laravel-apidoc-generator)
99
[![codecov.io](https://codecov.io/github/mpociot/laravel-apidoc-generator/coverage.svg?branch=master)](https://codecov.io/github/mpociot/laravel-apidoc-generator?branch=master)
1010
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mpociot/laravel-apidoc-generator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mpociot/laravel-apidoc-generator/?branch=master)
1111
[![Build Status](https://travis-ci.org/mpociot/laravel-apidoc-generator.svg?branch=master)](https://travis-ci.org/mpociot/laravel-apidoc-generator)
1212
[![StyleCI](https://styleci.io/repos/57999295/shield?style=flat)](https://styleci.io/repos/57999295)
13-
[![Dependency Status](https://www.versioneye.com/php/mpociot:laravel-apidoc-generator/dev-master/badge?style=flat)](https://www.versioneye.com/php/mpociot:laravel-apidoc-generator/dev-master)
1413

1514

1615
## Installation
@@ -61,8 +60,9 @@ Route::group(array('prefix' => 'api/v1', 'middleware' => []), function () {
6160
Option | Description
6261
--------- | -------
6362
`output` | The output path used for the generated documentation. Default: `public/docs`
64-
`routePrefix` | The route prefix to use for generation - `*` can be used as a wildcard
65-
`routes` | The route names to use for generation - Required if no routePrefix is provided
63+
`routePrefix` | The route prefix(es) to use for generation. `*` can be used as a wildcard. Multiple route prefixes can be specified by separating them with a comma (for instance `/v1,/v2`)
64+
`routeDomain` | The route domain(s) to use for generation. `*` can be used as a wildcard. Multiple route domains can be specified by separating them with a comma
65+
`routes` | The route names to use for generation - Required if no routePrefix or routeDomain is provided
6666
`middleware` | The middlewares to use for generation
6767
`noResponseCalls` | Disable API response calls
6868
`noPostmanCollection` | Disable Postman collection creation
@@ -92,7 +92,7 @@ This package uses these resources to generate the API documentation:
9292

9393
This package uses the HTTP controller doc blocks to create a table of contents and show descriptions for your API methods.
9494

95-
Using `@resource` in a doc block prior to each controller is useful as it creates a Group within the API documentation for all methods defined in that controller (rather than listing every method in a single list for all your controllers), but using `@resource` is not required. The short description after the `@resource` should be unique to allow anchor tags to navigate to this section. A longer description can be included below.
95+
Using `@resource` in a doc block prior to each controller is useful as it creates a Group within the API documentation for all methods defined in that controller (rather than listing every method in a single list for all your controllers), but using `@resource` is not required. The short description after the `@resource` should be unique to allow anchor tags to navigate to this section. A longer description can be included below. Custom formatting and `<aside>` tags are also supported. (see the [Documentarian docs](http://marcelpociot.de/documentarian/installation/markdown_syntax))
9696

9797
Above each method within the controller you wish to include in your API documentation you should have a doc block. This should include a unique short description as the first entry. An optional second entry can be added with further information. Both descriptions will appear in the API documentation in a different format as shown below.
9898

@@ -176,13 +176,14 @@ public function transformerCollectionTag()
176176
The @transformermodel tag is needed for PHP 5.* to get the model. For PHP 7 is it optional to specify the model that is used for the transformer.
177177

178178
#### @response
179-
If you expliciet want to specify the result of a function you can set it in the docblock
179+
If you explicitly want to specify the result of a function you can set it in the docblock as JSON, using the `@response` annotation:
180180

181181
```php
182182
/**
183183
* @response {
184-
* data: [],
185-
*}
184+
* "token": "eyJ0eXAi…",
185+
* "roles": ["admin"]
186+
* }
186187
*/
187188
public function responseTag()
188189
{

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
"Mpociot\\ApiDoc\\Tests\\": "tests/"
3939
}
4040
},
41+
"scripts": {
42+
"test-ci": "phpunit --coverage-clover=coverage.xml"
43+
},
4144
"extra": {
4245
"laravel": {
4346
"providers": [

src/Mpociot/ApiDoc/Commands/GenerateDocumentation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private function writeMarkdown($parsedRoutes)
197197

198198
$documentarian->generate($outputPath);
199199

200-
$this->info('Wrote HTML documentation to: '.$outputPath.'/public/index.html');
200+
$this->info('Wrote HTML documentation to: '.$outputPath.'/index.html');
201201

202202
if ($this->option('noPostmanCollection') !== true) {
203203
$this->info('Generating Postman collection');
@@ -311,10 +311,10 @@ private function processDingoRoutes(AbstractGenerator $generator, $allowedRoutes
311311
|| in_array($middleware, $route->middleware())
312312
) {
313313
if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) {
314-
$parsedRoutes[] = $generator->processRoute($route, $bindings, $this->option('header'), $withResponse);
315-
$this->info('Processed route: ['.implode(',', $route->getMethods()).'] '.$route->uri());
314+
$parsedRoutes[] = $generator->processRoute($route, $bindings, $this->option('header'), $withResponse && in_array('GET', $generator->getMethods($route)));
315+
$this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$route->uri());
316316
} else {
317-
$this->warn('Skipping route: ['.implode(',', $route->getMethods()).'] '.$route->uri());
317+
$this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$route->uri());
318318
}
319319
}
320320
}

src/Mpociot/ApiDoc/Commands/UpdateDocumentation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ public function handle()
5353

5454
$documentarian->generate($outputPath);
5555

56-
$this->info('Wrote HTML documentation to: '.$outputPath.'/public/index.html');
56+
$this->info('Wrote HTML documentation to: '.$outputPath.'/index.html');
5757
}
5858
}

src/Mpociot/ApiDoc/Generators/AbstractGenerator.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Support\Facades\Validator;
1212
use Illuminate\Foundation\Http\FormRequest;
1313
use Mpociot\ApiDoc\Parsers\RuleDescriptionParser as Description;
14+
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
1415

1516
abstract class AbstractGenerator
1617
{
@@ -86,18 +87,17 @@ protected function getDocblockResponse($tags)
8687
*/
8788
protected function getParameters($routeData, $routeAction, $bindings)
8889
{
89-
$rules = $this->simplifyRules($this->getRouteRules($routeAction['uses'], $bindings));
90+
$rules = $this->simplifyRules($this->getRouteRules($routeData['methods'], $routeAction['uses'], $bindings));
9091

91-
foreach ($rules as $attribute => $rules) {
92+
foreach ($rules as $attribute => $ruleset) {
9293
$attributeData = [
9394
'required' => false,
9495
'type' => null,
9596
'default' => '',
9697
'value' => '',
9798
'description' => [],
9899
];
99-
100-
foreach ($rules as $ruleName => $rule) {
100+
foreach ($ruleset as $rule) {
101101
$this->parseRule($rule, $attribute, $attributeData, $routeData['id']);
102102
}
103103
$routeData['parameters'][$attribute] = $attributeData;
@@ -220,14 +220,15 @@ protected function getRouteGroup($route)
220220
}
221221

222222
/**
223-
* @param $route
223+
* @param array $routeMethods
224+
* @param string $routeAction
224225
* @param array $bindings
225226
*
226227
* @return array
227228
*/
228-
protected function getRouteRules($route, $bindings)
229+
protected function getRouteRules(array $routeMethods, $routeAction, $bindings)
229230
{
230-
list($class, $method) = explode('@', $route);
231+
list($class, $method) = explode('@', $routeAction);
231232
$reflection = new ReflectionClass($class);
232233
$reflectionMethod = $reflection->getMethod($method);
233234

@@ -237,15 +238,21 @@ protected function getRouteRules($route, $bindings)
237238
$className = $parameterType->name;
238239

239240
if (is_subclass_of($className, FormRequest::class)) {
240-
$parameterReflection = new $className;
241+
/** @var FormRequest $formRequest */
242+
$formRequest = new $className;
241243
// Add route parameter bindings
242-
$parameterReflection->query->add($bindings);
243-
$parameterReflection->request->add($bindings);
244+
$formRequest->setContainer(app());
245+
$formRequest->request->add($bindings);
246+
$formRequest->query->add($bindings);
247+
$formRequest->setMethod($routeMethods[0]);
248+
249+
if (method_exists($formRequest, 'validator')) {
250+
$factory = app(ValidationFactory::class);
244251

245-
if (method_exists($parameterReflection, 'validator')) {
246-
return $parameterReflection->validator()->getRules();
252+
return call_user_func_array([$formRequest, 'validator'], [$factory])
253+
->getRules();
247254
} else {
248-
return $parameterReflection->rules();
255+
return call_user_func_array([$formRequest, 'rules'], []);
249256
}
250257
}
251258
}

src/Mpociot/ApiDoc/Generators/LaravelGenerator.php

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
use Mpociot\Reflection\DocBlock\Tag;
1111
use Illuminate\Support\Facades\Request;
1212
use League\Fractal\Resource\Collection;
13-
use Illuminate\Foundation\Http\FormRequest;
14-
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
1513

1614
class LaravelGenerator extends AbstractGenerator
1715
{
@@ -253,43 +251,4 @@ protected function getTransformerResponse($tags)
253251
return;
254252
}
255253
}
256-
257-
/**
258-
* @param string $route
259-
* @param array $bindings
260-
*
261-
* @return array
262-
*/
263-
protected function getRouteRules($route, $bindings)
264-
{
265-
list($class, $method) = explode('@', $route);
266-
$reflection = new ReflectionClass($class);
267-
$reflectionMethod = $reflection->getMethod($method);
268-
269-
foreach ($reflectionMethod->getParameters() as $parameter) {
270-
$parameterType = $parameter->getClass();
271-
if (! is_null($parameterType) && class_exists($parameterType->name)) {
272-
$className = $parameterType->name;
273-
274-
if (is_subclass_of($className, FormRequest::class)) {
275-
$parameterReflection = new $className;
276-
$parameterReflection->setContainer(app());
277-
// Add route parameter bindings
278-
$parameterReflection->query->add($bindings);
279-
$parameterReflection->request->add($bindings);
280-
281-
if (method_exists($parameterReflection, 'validator')) {
282-
$factory = app()->make(ValidationFactory::class);
283-
284-
return app()->call([$parameterReflection, 'validator'], [$factory])
285-
->getRules();
286-
} else {
287-
return app()->call([$parameterReflection, 'rules']);
288-
}
289-
}
290-
}
291-
}
292-
293-
return [];
294-
}
295254
}

0 commit comments

Comments
 (0)