From e0afdc1ce73b24babcddc6b54f7b32632b46f285 Mon Sep 17 00:00:00 2001 From: Rawa Hamid Date: Tue, 11 Oct 2022 10:22:19 +0300 Subject: [PATCH 01/14] Add request custom methods --- src/LaravelRequestDocs.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/LaravelRequestDocs.php b/src/LaravelRequestDocs.php index 60c8d34..41f7563 100644 --- a/src/LaravelRequestDocs.php +++ b/src/LaravelRequestDocs.php @@ -119,6 +119,7 @@ public function appendRequestRules(array $controllersInfo) $reflectionMethod = new ReflectionMethod($controller, $method); $params = $reflectionMethod->getParameters(); $customRules = $this->customParamsDocComment($reflectionMethod->getDocComment()); + $controllersInfo[$index]['rules'] = []; foreach ($params as $param) { if (!$param->getType()) { @@ -133,18 +134,16 @@ public function appendRequestRules(array $controllersInfo) //throw $th; } - if ($requestClass && method_exists($requestClass, 'rules')) { - try { - $controllersInfo[$index]['rules'] = $this->flattenRules($requestClass->rules()); - } catch (Throwable $e) { - // disabled. This only works when the rules are defined as 'required|integer' and that too in single line - // doesn't work well when the same rule is defined as array ['required', 'integer'] or in multiple lines such as - // If your rules are not populated using this library, then fix your rule to only throw validation errors and not throw exceptions - // such as 404, 500 inside the request class. - $controllersInfo[$index]['rules'] = $this->rulesByRegex($requestClassName); + foreach (config('request-docs.request_methods') as $rquestMethod) { + if ($requestClass && method_exists($requestClass, $rquestMethod)) { + try { + $controllersInfo[$index]['rules'] = array_merge($controllersInfo[$index]['rules'], $this->flattenRules($requestClass->$rquestMethod())); - if (config('request-docs.debug')) { - throw $e; + } catch (Throwable $e) { + $controllersInfo[$index]['rules'] = array_merge($controllersInfo[$index]['rules'], $this->rulesByRegex($requestClassName, $rquestMethod)); + if (config('request-docs.debug')) { + throw $e; + } } } } @@ -211,9 +210,9 @@ public function flattenRules($mixedRules) return $rules; } - public function rulesByRegex($requestClassName) + public function rulesByRegex($requestClassName, $methodName) { - $data = new ReflectionMethod($requestClassName, 'rules'); + $data = new ReflectionMethod($requestClassName, $methodName); $lines = file($data->getFileName()); $rules = []; From e3b21099a3bb06e53c6233451a1ff1af58d16cc6 Mon Sep 17 00:00:00 2001 From: Rawa Hamid Date: Tue, 11 Oct 2022 10:23:10 +0300 Subject: [PATCH 02/14] Update request-docs.php --- config/request-docs.php | 60 ++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/config/request-docs.php b/config/request-docs.php index 2fe782d..9e7d023 100644 --- a/config/request-docs.php +++ b/config/request-docs.php @@ -1,20 +1,21 @@ false, - 'document_name' => 'LRD', + // change it to true will make lrd to throw exception if rules in request class need to be changed + // keep it false + 'debug' => false, + 'document_name' => 'Fast Serve', /* * Route where request docs will be served from * localhost:8080/request-docs */ - 'url' => 'request-docs', + 'url' => 'api-docs', 'middlewares' => [ //Example // \App\Http\Middleware\NotFoundWhenProduction::class, ], + /** * Path to to static HTML if using command line. */ @@ -23,32 +24,41 @@ /** * Sorting route by and there is two types default(route methods), route_names. */ - 'sort_by' => 'default', + 'sort_by' => 'route_names', //Use only routes where ->uri start with next string Using Str::startWith( . e.g. - /api/mobile 'only_route_uri_start_with' => '', 'hide_matching' => [ - "#^telescope#", - "#^docs#", - "#^request-docs#", + '#^telescope#', + '#^docs#', + '#^request-docs#', + '#^api-docs#', + '#^sanctum#', + '#^_ignition#', + ], + + 'request_methods' => [ + 'rules', + 'onCreate', + 'onUpdate', ], - "open_api" => [ + 'open_api' => [ // default version that this library provides - "version" => "3.0.0", + 'version' => '3.0.0', // changeable - "document_version" => "1.0.0", + 'document_version' => '1.0.0', // license that you want to display - "license" => "Apache 2.0", - "license_url" => "https://www.apache.org/licenses/LICENSE-2.0.html", - "server_url" => env('APP_URL', 'http://localhost'), + 'license' => 'Apache 2.0', + 'license_url' => 'https://www.apache.org/licenses/LICENSE-2.0.html', + 'server_url' => env('APP_URL', 'http://localhost'), // for now putting default responses for all. This can be changed later based on specific needs - "responses" => [ + 'responses' => [ '200' => [ 'description' => 'Successful operation', - 'content' => [ + 'content' => [ 'application/json' => [ 'schema' => [ 'type' => 'object', @@ -58,7 +68,7 @@ ], '400' => [ 'description' => 'Bad Request', - 'content' => [ + 'content' => [ 'application/json' => [ 'schema' => [ 'type' => 'object', @@ -68,7 +78,7 @@ ], '401' => [ 'description' => 'Unauthorized', - 'content' => [ + 'content' => [ 'application/json' => [ 'schema' => [ 'type' => 'object', @@ -78,7 +88,7 @@ ], '403' => [ 'description' => 'Forbidden', - 'content' => [ + 'content' => [ 'application/json' => [ 'schema' => [ 'type' => 'object', @@ -88,7 +98,7 @@ ], '404' => [ 'description' => 'Not Found', - 'content' => [ + 'content' => [ 'application/json' => [ 'schema' => [ 'type' => 'object', @@ -98,7 +108,7 @@ ], '422' => [ 'description' => 'Unprocessable Entity', - 'content' => [ + 'content' => [ 'application/json' => [ 'schema' => [ 'type' => 'object', @@ -108,7 +118,7 @@ ], '500' => [ 'description' => 'Internal Server Error', - 'content' => [ + 'content' => [ 'application/json' => [ 'schema' => [ 'type' => 'object', @@ -118,7 +128,7 @@ ], 'default' => [ 'description' => 'Unexpected error', - 'content' => [ + 'content' => [ 'application/json' => [ 'schema' => [ 'type' => 'object', @@ -127,5 +137,5 @@ ], ], ], - ] + ], ]; From 4b821bfbb4b103d85e46e7fad4afafe041a2c0c4 Mon Sep 17 00:00:00 2001 From: Rawa Hamid Date: Tue, 11 Oct 2022 10:38:10 +0300 Subject: [PATCH 03/14] Spell check done --- src/LaravelRequestDocs.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/LaravelRequestDocs.php b/src/LaravelRequestDocs.php index 41f7563..c469530 100644 --- a/src/LaravelRequestDocs.php +++ b/src/LaravelRequestDocs.php @@ -134,13 +134,13 @@ public function appendRequestRules(array $controllersInfo) //throw $th; } - foreach (config('request-docs.request_methods') as $rquestMethod) { - if ($requestClass && method_exists($requestClass, $rquestMethod)) { + foreach (config('request-docs.request_methods') as $requestMethod) { + if ($requestClass && method_exists($requestClass, $requestMethod)) { try { - $controllersInfo[$index]['rules'] = array_merge($controllersInfo[$index]['rules'], $this->flattenRules($requestClass->$rquestMethod())); + $controllersInfo[$index]['rules'] = array_merge($controllersInfo[$index]['rules'], $this->flattenRules($requestClass->$requestMethod())); } catch (Throwable $e) { - $controllersInfo[$index]['rules'] = array_merge($controllersInfo[$index]['rules'], $this->rulesByRegex($requestClassName, $rquestMethod)); + $controllersInfo[$index]['rules'] = array_merge($controllersInfo[$index]['rules'], $this->rulesByRegex($requestClassName, $requestMethod)); if (config('request-docs.debug')) { throw $e; } From 22d0b10b2e32b9c9182da0162f1d25203569a1d5 Mon Sep 17 00:00:00 2001 From: Rawa Hamid Date: Tue, 11 Oct 2022 10:38:42 +0300 Subject: [PATCH 04/14] Update request-docs.php --- config/request-docs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/request-docs.php b/config/request-docs.php index 9e7d023..4e0675a 100644 --- a/config/request-docs.php +++ b/config/request-docs.php @@ -4,7 +4,7 @@ // change it to true will make lrd to throw exception if rules in request class need to be changed // keep it false 'debug' => false, - 'document_name' => 'Fast Serve', + 'document_name' => 'LRD', /* * Route where request docs will be served from From 0f8469e72677a2b1bfde33c0f35dfe69acfeaaed Mon Sep 17 00:00:00 2001 From: brel Date: Sat, 15 Oct 2022 00:23:39 +0300 Subject: [PATCH 05/14] add mb-5 style to route list in left sidebar --- resources/views/index.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index a4b8ba9..32117c9 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -130,7 +130,7 @@ class="my-prism-editor"

Routes List


- +
@foreach ($docs as $index => $doc) From 648bbd6b5c8d38a4d1207a72891ef74fb97c4796 Mon Sep 17 00:00:00 2001 From: brel Date: Sat, 15 Oct 2022 01:49:26 +0300 Subject: [PATCH 06/14] some GUI changes --- resources/views/index.blade.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index 32117c9..37c40d8 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -245,12 +245,15 @@ class="inline-flex text-xs"
-

LRD Docs

- {!! $doc['docBlock'] !!} +

Description

+
+ {!! $doc['docBlock'] !!}
-
@if (!empty($doc['rules'])) - +
+

Attributes

+
+
@@ -333,6 +336,7 @@ class="inline-flex text-xs" @endforeach
No.
+ @endif