@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | /** |
| 29 | 29 | * @param Route $route |
| 30 | 30 | * |
| 31 | - * @return mixed |
|
| 31 | + * @return string |
|
| 32 | 32 | */ |
| 33 | 33 | public function getUri(Route $route) |
| 34 | 34 | { |
@@ -47,7 +47,6 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * @param \Illuminate\Routing\Route $route |
| 50 | - * @param array $apply Rules to apply when generating documentation for this route |
|
| 51 | 50 | * |
| 52 | 51 | * @return array |
| 53 | 52 | */ |
@@ -300,6 +299,9 @@ discard block |
||
| 300 | 299 | return config('apidoc.default_group', 'general'); |
| 301 | 300 | } |
| 302 | 301 | |
| 302 | + /** |
|
| 303 | + * @return string |
|
| 304 | + */ |
|
| 303 | 305 | private function normalizeParameterType($type) |
| 304 | 306 | { |
| 305 | 307 | $typeMap = [ |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $generator = new Generator(config('apidoc.faker_seed')); |
| 64 | 64 | $parsedRoutes = $this->processRoutes($generator, $routes); |
| 65 | 65 | $parsedRoutes = collect($parsedRoutes)->groupBy('group') |
| 66 | - ->sortBy(static function ($group) { |
|
| 66 | + ->sortBy(static function($group) { |
|
| 67 | 67 | /* @var $group Collection */ |
| 68 | 68 | return $group->first()['group']; |
| 69 | 69 | }, SORT_NATURAL); |
@@ -79,19 +79,19 @@ discard block |
||
| 79 | 79 | private function writeMarkdown($parsedRoutes) |
| 80 | 80 | { |
| 81 | 81 | $outputPath = config('apidoc.output'); |
| 82 | - $targetFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'index.md'; |
|
| 83 | - $compareFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'.compare.md'; |
|
| 84 | - $prependFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'prepend.md'; |
|
| 85 | - $appendFile = $outputPath.DIRECTORY_SEPARATOR.'source'.DIRECTORY_SEPARATOR.'append.md'; |
|
| 82 | + $targetFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'index.md'; |
|
| 83 | + $compareFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . '.compare.md'; |
|
| 84 | + $prependFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'prepend.md'; |
|
| 85 | + $appendFile = $outputPath . DIRECTORY_SEPARATOR . 'source' . DIRECTORY_SEPARATOR . 'append.md'; |
|
| 86 | 86 | |
| 87 | 87 | $infoText = view('apidoc::partials.info') |
| 88 | 88 | ->with('outputPath', ltrim($outputPath, 'public/')) |
| 89 | 89 | ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection()); |
| 90 | 90 | |
| 91 | 91 | $settings = ['languages' => config('apidoc.example_languages')]; |
| 92 | - $parsedRouteOutput = $parsedRoutes->map(function ($routeGroup) use ($settings) { |
|
| 93 | - return $routeGroup->map(function ($route) use ($settings) { |
|
| 94 | - if (count($route['cleanBodyParameters']) && ! isset($route['headers']['Content-Type'])) { |
|
| 92 | + $parsedRouteOutput = $parsedRoutes->map(function($routeGroup) use ($settings) { |
|
| 93 | + return $routeGroup->map(function($route) use ($settings) { |
|
| 94 | + if (count($route['cleanBodyParameters']) && !isset($route['headers']['Content-Type'])) { |
|
| 95 | 95 | $route['headers']['Content-Type'] = 'application/json'; |
| 96 | 96 | } |
| 97 | 97 | $route['output'] = (string) view('apidoc::partials.route') |
@@ -117,16 +117,16 @@ discard block |
||
| 117 | 117 | $frontmatter = trim($generatedFrontmatter[1], "\n"); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - $parsedRouteOutput->transform(function ($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
| 121 | - return $routeGroup->transform(function ($route) use ($generatedDocumentation, $compareDocumentation) { |
|
| 122 | - if (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
| 123 | - $routeDocumentationChanged = (preg_match('/<!-- START_'.$route['id'].' -->(.*)<!-- END_'.$route['id'].' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
| 120 | + $parsedRouteOutput->transform(function($routeGroup) use ($generatedDocumentation, $compareDocumentation) { |
|
| 121 | + return $routeGroup->transform(function($route) use ($generatedDocumentation, $compareDocumentation) { |
|
| 122 | + if (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $generatedDocumentation, $existingRouteDoc)) { |
|
| 123 | + $routeDocumentationChanged = (preg_match('/<!-- START_' . $route['id'] . ' -->(.*)<!-- END_' . $route['id'] . ' -->/is', $compareDocumentation, $lastDocWeGeneratedForThisRoute) && $lastDocWeGeneratedForThisRoute[1] !== $existingRouteDoc[1]); |
|
| 124 | 124 | if ($routeDocumentationChanged === false || $this->option('force')) { |
| 125 | 125 | if ($routeDocumentationChanged) { |
| 126 | - $this->warn('Discarded manual changes for route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
| 126 | + $this->warn('Discarded manual changes for route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
| 127 | 127 | } |
| 128 | 128 | } else { |
| 129 | - $this->warn('Skipping modified route ['.implode(',', $route['methods']).'] '.$route['uri']); |
|
| 129 | + $this->warn('Skipping modified route [' . implode(',', $route['methods']) . '] ' . $route['uri']); |
|
| 130 | 130 | $route['modified_output'] = $existingRouteDoc[0]; |
| 131 | 131 | } |
| 132 | 132 | } |
@@ -137,9 +137,9 @@ discard block |
||
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | $prependFileContents = file_exists($prependFile) |
| 140 | - ? file_get_contents($prependFile)."\n" : ''; |
|
| 140 | + ? file_get_contents($prependFile) . "\n" : ''; |
|
| 141 | 141 | $appendFileContents = file_exists($appendFile) |
| 142 | - ? "\n".file_get_contents($appendFile) : ''; |
|
| 142 | + ? "\n" . file_get_contents($appendFile) : ''; |
|
| 143 | 143 | |
| 144 | 144 | $documentarian = new Documentarian(); |
| 145 | 145 | |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | ->with('showPostmanCollectionButton', $this->shouldGeneratePostmanCollection()) |
| 154 | 154 | ->with('parsedRoutes', $parsedRouteOutput); |
| 155 | 155 | |
| 156 | - if (! is_dir($outputPath)) { |
|
| 156 | + if (!is_dir($outputPath)) { |
|
| 157 | 157 | $documentarian->create($outputPath); |
| 158 | 158 | } |
| 159 | 159 | |
@@ -173,24 +173,24 @@ discard block |
||
| 173 | 173 | |
| 174 | 174 | file_put_contents($compareFile, $compareMarkdown); |
| 175 | 175 | |
| 176 | - $this->info('Wrote index.md to: '.$outputPath); |
|
| 176 | + $this->info('Wrote index.md to: ' . $outputPath); |
|
| 177 | 177 | |
| 178 | 178 | $this->info('Generating API HTML code'); |
| 179 | 179 | |
| 180 | 180 | $documentarian->generate($outputPath); |
| 181 | 181 | |
| 182 | - $this->info('Wrote HTML documentation to: '.$outputPath.'/index.html'); |
|
| 182 | + $this->info('Wrote HTML documentation to: ' . $outputPath . '/index.html'); |
|
| 183 | 183 | |
| 184 | 184 | if ($this->shouldGeneratePostmanCollection()) { |
| 185 | 185 | $this->info('Generating Postman collection'); |
| 186 | 186 | |
| 187 | - file_put_contents($outputPath.DIRECTORY_SEPARATOR.'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
| 187 | + file_put_contents($outputPath . DIRECTORY_SEPARATOR . 'collection.json', $this->generatePostmanCollection($parsedRoutes)); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | if ($logo = config('apidoc.logo')) { |
| 191 | 191 | copy( |
| 192 | 192 | $logo, |
| 193 | - $outputPath.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'logo.png' |
|
| 193 | + $outputPath . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'logo.png' |
|
| 194 | 194 | ); |
| 195 | 195 | } |
| 196 | 196 | } |
@@ -209,9 +209,9 @@ discard block |
||
| 209 | 209 | /** @var Route $route */ |
| 210 | 210 | if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) { |
| 211 | 211 | $parsedRoutes[] = $generator->processRoute($route, $routeItem['apply']); |
| 212 | - $this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
| 212 | + $this->info('Processed route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
| 213 | 213 | } else { |
| 214 | - $this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route)); |
|
| 214 | + $this->warn('Skipping route: [' . implode(',', $generator->getMethods($route)) . '] ' . $generator->getUri($route)); |
|
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | */ |
| 226 | 226 | private function isValidRoute(Route $route) |
| 227 | 227 | { |
| 228 | - return ! is_callable($route->getAction()['uses']) && ! is_null($route->getAction()['uses']); |
|
| 228 | + return !is_callable($route->getAction()['uses']) && !is_null($route->getAction()['uses']); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | [$class, $method] = explode('@', $route); |
| 241 | 241 | $reflection = new ReflectionClass($class); |
| 242 | 242 | |
| 243 | - if (! $reflection->hasMethod($method)) { |
|
| 243 | + if (!$reflection->hasMethod($method)) { |
|
| 244 | 244 | return false; |
| 245 | 245 | } |
| 246 | 246 | |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | $phpdoc = new DocBlock($comment); |
| 251 | 251 | |
| 252 | 252 | return collect($phpdoc->getTags()) |
| 253 | - ->filter(function ($tag) use ($route) { |
|
| 253 | + ->filter(function($tag) use ($route) { |
|
| 254 | 254 | return $tag->getName() === 'hideFromAPIDocumentation'; |
| 255 | 255 | }) |
| 256 | 256 | ->isEmpty(); |