shalvah 4 tahun lalu
induk
melakukan
f2ef93d982

+ 1 - 1
config/scribe.php

@@ -35,7 +35,7 @@ return [
                 /*
                  * Match only routes whose paths match this pattern (use * as a wildcard to match any characters). Example: 'users/*'.
                  */
-                'prefixes' => ['*'],
+                'prefixes' => ['api/*'],
 
                 /*
                  * [Dingo router only] Match only routes registered under this version. Wildcards are not supported.

+ 1 - 1
resources/views/partials/example-requests/python.blade.php

@@ -11,7 +11,7 @@ url = '{{ rtrim($baseUrl, '/') }}/{{ $endpoint->boundUri }}'
 files = {
 @foreach($endpoint->fileParameters as $parameter => $value)
 @foreach(u::getParameterNamesAndValuesForFormData($parameter, $value) as $key => $file)
-  '{!! $key !!}': open('{!! $file->path() !!}', 'rb')@if(!($loop->last)),
+  '{!! $key !!}': open('{!! $file->path() !!}', 'rb')@if(!($loop->parent->last)),
 @endif
 @endforeach
 @endforeach

+ 3 - 3
resources/views/themes/default/index.blade.php

@@ -15,9 +15,9 @@
     <link rel="stylesheet" href="css/theme-default.print.css" media="print">
     <script src="{{ u::getVersionedAsset('js/theme-default.js') }}"></script>
 
-    <link rel="stylesheet" href="css/highlight-darcula.css">
-    <script src="js/highlight.pack.js"></script>
-    <script>hljs.initHighlightingOnLoad();</script>
+    <link href="https://unpkg.com/prismjs@v1.x/themes/prism-twilight.css" rel="stylesheet" />
+    <script src="https://unpkg.com/prismjs@v1.x/components/prism-core.min.js"></script>
+    <script src="https://unpkg.com/prismjs@v1.x/plugins/autoloader/prism-autoloader.min.js"></script>
 
 @if($isInteractive)
     <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js"></script>

+ 5 - 14
src/Commands/GenerateDocumentation.php

@@ -34,23 +34,14 @@ class GenerateDocumentation extends Command
 
     protected $description = 'Generate API documentation from your Laravel/Dingo routes.';
 
-    /**
-     * @var DocumentationConfig
-     */
-    private $docConfig;
+    private DocumentationConfig $docConfig;
 
-    public static $camelDir = ".scribe/endpoints";
-    public static $cacheDir = ".scribe/endpoints.cache";
+    public static string $camelDir = ".scribe/endpoints";
+    public static string $cacheDir = ".scribe/endpoints.cache";
 
-    /**
-     * @var bool
-     */
-    private $shouldExtract;
+    private bool $shouldExtract;
 
-    /**
-     * @var bool
-     */
-    private $forcing;
+    private bool $forcing;
 
     public function handle(RouteMatcherInterface $routeMatcher): void
     {

+ 3 - 9
src/Extracting/Extractor.php

@@ -17,19 +17,13 @@ use Knuckles\Scribe\Tools\DocumentationConfig;
 
 class Extractor
 {
-    /**
-     * @var DocumentationConfig
-     */
-    private $config;
+    private DocumentationConfig $config;
 
     use ParamHelpers;
 
-    /**
-     * @var Route|null
-     */
-    private static $routeBeingProcessed = null;
+    private static ?Route $routeBeingProcessed = null;
 
-    private static $defaultStrategies = [
+    private static array $defaultStrategies = [
         'metadata' => [
             \Knuckles\Scribe\Extracting\Strategies\Metadata\GetFromDocBlocks::class,
         ],

+ 18 - 13
src/Matching/RouteMatcher.php

@@ -9,14 +9,14 @@ use Illuminate\Support\Str;
 
 class RouteMatcher implements RouteMatcherInterface
 {
-    public function getRoutes(array $routeRules = [], string $router = 'laravel')
+    public function getRoutes(array $routeRules = [], string $router = 'laravel'): array
     {
         $usingDingoRouter = strtolower($router) == 'dingo';
 
         return $this->getRoutesToBeDocumented($routeRules, $usingDingoRouter);
     }
 
-    private function getRoutesToBeDocumented(array $routeRules, bool $usingDingoRouter = false)
+    private function getRoutesToBeDocumented(array $routeRules, bool $usingDingoRouter = false): array
     {
         $allRoutes = $this->getAllRoutes($usingDingoRouter);
 
@@ -59,20 +59,25 @@ class RouteMatcher implements RouteMatcherInterface
             })->toArray();
     }
 
-    private function shouldIncludeRoute(Route $route, array $routeRule, array $mustIncludes, bool $usingDingoRouter)
+    private function shouldIncludeRoute(Route $route, array $routeRule, array $mustIncludes, bool $usingDingoRouter): bool
     {
-        $matchesVersion = $usingDingoRouter
-            ? ! empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? []))
-            : true;
-
-        return Str::is($mustIncludes, $route->getName())
-            || Str::is($mustIncludes, $route->uri())
-            || (Str::is($routeRule['match']['domains'] ?? [], $route->getDomain())
-            && Str::is($routeRule['match']['prefixes'] ?? [], $route->uri())
-            && $matchesVersion);
+        if (Str::is($mustIncludes, $route->getName()) || Str::is($mustIncludes, $route->uri())) {
+            return true;
+        }
+
+        $matchesVersion = true;
+        if ($usingDingoRouter) {
+            $matchesVersion = !empty(array_intersect($route->versions(), $routeRule['match']['versions'] ?? []));
+        }
+
+        $domainsToMatch = $routeRule['match']['domains'] ?? [];
+        $pathsToMatch = $routeRule['match']['prefixes'] ?? [];
+
+        return Str::is($domainsToMatch, $route->getDomain()) && Str::is($pathsToMatch, $route->uri())
+            && $matchesVersion;
     }
 
-    private function shouldExcludeRoute(Route $route, array $routeRule)
+    private function shouldExcludeRoute(Route $route, array $routeRule): bool
     {
         $excludes = $routeRule['exclude'] ?? [];
 

+ 1 - 1
src/Matching/RouteMatcherInterface.php

@@ -12,5 +12,5 @@ interface RouteMatcherInterface
      *
      * @return MatchedRoute[]
      */
-    public function getRoutes(array $routeRules = [], string $router = 'laravel');
+    public function getRoutes(array $routeRules = [], string $router = 'laravel'): array;
 }

+ 6 - 30
src/Writing/Writer.php

@@ -10,47 +10,23 @@ use Symfony\Component\Yaml\Yaml;
 
 class Writer
 {
-    /**
-     * @var DocumentationConfig
-     */
-    private $config;
+    private DocumentationConfig $config;
 
-    /**
-     * @var string
-     */
-    private $baseUrl;
+    private string $baseUrl;
 
-    /**
-     * @var bool
-     */
-    private $shouldOverwrite;
+    private bool $isStatic;
 
-    /**
-     * @var bool
-     */
-    private $isStatic;
+    private string $markdownOutputPath = '.scribe';
 
-    /**
-     * @var string
-     */
-    private $markdownOutputPath = '.scribe';
+    private string $staticTypeOutputPath;
 
-    /**
-     * @var string
-     */
-    private $staticTypeOutputPath;
-
-    /**
-     * @var string
-     */
-    private $laravelTypeOutputPath = 'resources/views/scribe';
+    private string $laravelTypeOutputPath = 'resources/views/scribe';
 
     public function __construct(DocumentationConfig $config = null, bool $shouldOverwrite = false)
     {
         // If no config is injected, pull from global. Makes testing easier.
         $this->config = $config ?: new DocumentationConfig(config('scribe'));
         $this->baseUrl = $this->config->get('base_url') ?? config('app.url');
-        $this->shouldOverwrite = $shouldOverwrite;
 
         $this->isStatic = $this->config->get('type') === 'static';
         $this->staticTypeOutputPath = rtrim($this->config->get('static.output_path', 'public/docs'), '/');