Skip to content

Commit adfc957

Browse files
Merge pull request rakutentech#62 from rakutentech/feature/ui
Fixes rakutentech#3
2 parents eb12f27 + 5cedb5d commit adfc957

File tree

10 files changed

+251
-32
lines changed

10 files changed

+251
-32
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,5 @@ Fixing lints
138138
- v1.15 Adds Filter and fall back to regexp upon Exception
139139
- v1.17 Donot restrict to FormRequest
140140
- v1.18 Fix where prism had fixed height. Allow text area resize.
141+
- v1.18 Updated UI and pushed unit tests
141142

resources/views/index.blade.php

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@
100100
</nav>
101101
<div id="app" v-cloak class="w-full flex lg:pt-10">
102102
<aside class="text-sm ml-1.5 text-grey-darkest break-all bg-gray-200 pl-2 h-screen sticky top-1 overflow-auto">
103+
<section class="pt-5 pl-2 pr-2 pb-5 border mb-10 rounded bg-white shadow">
104+
<div class="font-sans">
105+
<h2 class="text-sm break-normal text-black break-normal font-sans pb-1 pt-1 text-black">
106+
Filter
107+
</h2>
108+
<p class="text-xs pb-2 font-medium text-gray-500">Hide non matching</code></p>
109+
<input type="text" v-model="filterTerm" @input="filterDocs" class="w-full p-2 border-2 border-gray-300 rounded" placeholder="/api/search">
110+
</div>
111+
</section>
112+
<section class="pt-5 pl-2 pr-2 pb-5 border mb-10 rounded bg-white shadow">
113+
<div class="font-sans">
114+
<h2 class="text-sm break-normal text-black break-normal font-sans pb-1 pt-1 text-black">
115+
Edit Request Headers
116+
</h2>
117+
<p class="text-xs pb-2 font-medium text-gray-500">Default headers sent on every request. Format <code>Key:Value</code></p>
118+
<prism-editor
119+
class="my-prism-editor"
120+
style="max-width:100%;min-height:100px;background:#2d2d2d;color: #ccc;resize:both" v-model="requestHeaders" :highlight="highlighter" line-numbers></prism-editor>
121+
</div>
122+
</section>
103123
<h1 class="font-medium mx-3 mt-3" style="width: max-content;min-width:350px;">Routes List</h1>
104124
<hr class="border-b border-gray-300">
105125
<table class="table-fixed text-sm mt-5" style="width: max-content">
@@ -153,36 +173,6 @@ class="inline-flex text-xs"
153173
</aside>
154174
<br><br>
155175
<div class="ml-6 mr-6 pl-2 w-2/3 p-2" style="width: 100%">
156-
<h1 class="pl-2 pr-2 break-normal text-black break-normal font-sans text-black font-medium">
157-
Search・Sort settings
158-
</h1>
159-
<hr class="border-b border-gray-300">
160-
<br>
161-
<section class="pt-5 pl-2 pr-2 pb-5 border mb-10 rounded bg-white shadow">
162-
<div class="font-sans">
163-
<h2 class="text-sm break-normal text-black break-normal font-sans pb-1 pt-1 text-black">
164-
Filter
165-
</h2>
166-
<p class="text-xs pb-2 font-medium text-gray-500">Hide non matching</code></p>
167-
<input type="text" v-model="filterTerm" @input="filterDocs" class="w-full p-2 border-2 border-gray-300 rounded" placeholder="/api/search">
168-
</div>
169-
</section>
170-
<h1 class="pl-2 pr-2 break-normal text-black break-normal font-sans text-black font-medium">
171-
Request Settings (editable)
172-
</h1>
173-
<hr class="border-b border-gray-300">
174-
<br>
175-
<section class="pt-5 pl-2 pr-2 pb-5 border mb-10 rounded bg-white shadow">
176-
<div class="font-sans">
177-
<h2 class="text-sm break-normal text-black break-normal font-sans pb-1 pt-1 text-black">
178-
Append Request Headers
179-
</h2>
180-
<p class="text-xs pb-2 font-medium text-gray-500">Default headers sent on every request. Format <code>Key:Value</code></p>
181-
<prism-editor
182-
class="my-prism-editor"
183-
style="min-height:100px;background:#2d2d2d;color: #ccc;resize:both" v-model="requestHeaders" :highlight="highlighter" line-numbers></prism-editor>
184-
</div>
185-
</section>
186176
<h1 class="pl-2 pr-2 break-normal text-black break-normal font-sans text-black font-medium">
187177
Routes List
188178
</h1>

src/LaravelRequestDocs.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,15 @@ public function getControllersInfo(): array
8686
}
8787
}
8888

89+
$middlewares = [];
90+
if (!empty($route->action['middleware'])) {
91+
$middlewares = !is_array($route->action['middleware']) ? [$route->action['middleware']] : $route->action['middleware'];
92+
}
93+
8994
$controllersInfo[] = [
9095
'uri' => $route->uri,
9196
'methods' => $route->methods,
92-
'middlewares' => !is_array($route->action['middleware']) ? [$route->action['middleware']] : $route->action['middleware'],
97+
'middlewares' => $middlewares,
9398
'controller' => $controllerName,
9499
'controller_full_path' => $controllerFullPath,
95100
'method' => $method,

tests/LRDTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Rakutentech\LaravelRequestDocs\Tests;
4+
use Route;
5+
6+
class LRDTest extends TestCase
7+
{
8+
public function testDocsCount()
9+
{
10+
$docs = $this->lrd->getDocs();
11+
$routes = collect(Route::getRoutes());
12+
13+
$this->assertSame($routes->count(), count($docs));
14+
}
15+
16+
public function testDocsCanFetchAllMethods()
17+
{
18+
$docs = $this->lrd->getDocs();
19+
$methods = [];
20+
foreach ($docs as $doc) {
21+
$methods = array_merge($methods, $doc['methods']);
22+
}
23+
$methods = array_unique($methods);
24+
sort($methods);
25+
$this->assertSame(['DELETE', 'GET', 'HEAD', 'POST', 'PUT'], $methods);
26+
}
27+
28+
public function testDocsCanFetchInfo()
29+
{
30+
$docs = $this->lrd->getDocs();
31+
foreach ($docs as $doc) {
32+
$this->assertNotEmpty($doc['rules']);
33+
$this->assertNotEmpty($doc['methods']);
34+
// $this->assertNotEmpty($doc['middlewares']); //todo: add middlewares to test
35+
$this->assertNotEmpty($doc['controller']);
36+
$this->assertNotEmpty($doc['controller_full_path']);
37+
$this->assertNotEmpty($doc['method']);
38+
$this->assertNotEmpty($doc['httpMethod']);
39+
$this->assertNotEmpty($doc['rules']);
40+
}
41+
}
42+
}

tests/TestCase.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22

33
namespace Rakutentech\LaravelRequestDocs\Tests;
44

5-
use Illuminate\Database\Eloquent\Factories\Factory;
65
use Orchestra\Testbench\TestCase as Orchestra;
76
use Rakutentech\LaravelRequestDocs\LaravelRequestDocsServiceProvider;
7+
use Rakutentech\LaravelRequestDocs\LaravelRequestDocs;
8+
use Illuminate\Support\Facades\Route;
9+
use Rakutentech\LaravelRequestDocs\Tests\TestControllers;
810

911
class TestCase extends Orchestra
1012
{
13+
protected LaravelRequestDocs $lrd;
1114
public function setUp(): void
1215
{
1316
parent::setUp();
17+
$this->lrd = new LaravelRequestDocs();
18+
$this->registerRoutes();
1419
}
1520

1621
protected function getPackageProviders($app)
@@ -24,4 +29,12 @@ public function getEnvironmentSetUp($app)
2429
{
2530
config()->set('database.default', 'testing');
2631
}
32+
33+
public function registerRoutes() {
34+
Route::get('/', [TestControllers\WelcomeController::class, 'index']);
35+
Route::get('welcome', [TestControllers\WelcomeController::class, 'index']);
36+
Route::post('welcome', [TestControllers\WelcomeController::class, 'store']);
37+
Route::put('welcome', [TestControllers\WelcomeController::class, 'edit']);
38+
Route::delete('welcome', [TestControllers\WelcomeController::class, 'destroy']);
39+
}
2740
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Rakutentech\LaravelRequestDocs\Tests\TestControllers;
4+
5+
use Rakutentech\LaravelRequestDocs\Tests\TestRequests\WelcomeIndexRequest;
6+
use Rakutentech\LaravelRequestDocs\Tests\TestRequests\WelcomeEditRequest;
7+
use Rakutentech\LaravelRequestDocs\Tests\TestRequests\WelcomeStoreRequest;
8+
use Rakutentech\LaravelRequestDocs\Tests\TestRequests\WelcomeDeleteRequest;
9+
10+
class WelcomeController
11+
{
12+
public function index(WelcomeIndexRequest $request)
13+
{
14+
return 1;
15+
}
16+
17+
public function edit(WelcomeEditRequest $request)
18+
{
19+
return 1;
20+
}
21+
22+
public function store(WelcomeStoreRequest $request)
23+
{
24+
return 1;
25+
}
26+
27+
public function destroy(WelcomeDeleteRequest $request)
28+
{
29+
return 1;
30+
}
31+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Rakutentech\LaravelRequestDocs\Tests\TestRequests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
7+
class WelcomeDeleteRequest extends FormRequest
8+
{
9+
/**
10+
* Determine if the user is authorized to make this request.
11+
*
12+
* @return bool
13+
*/
14+
public function authorize()
15+
{
16+
return true;
17+
}
18+
19+
protected function prepareForValidation()
20+
{
21+
}
22+
23+
/**
24+
* Get the validation rules that apply to the request.
25+
*
26+
* @return array
27+
*/
28+
public function rules()
29+
{
30+
return [
31+
'message_param' => 'nullable|string',
32+
];
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Rakutentech\LaravelRequestDocs\Tests\TestRequests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
7+
class WelcomeEditRequest extends FormRequest
8+
{
9+
/**
10+
* Determine if the user is authorized to make this request.
11+
*
12+
* @return bool
13+
*/
14+
public function authorize()
15+
{
16+
return true;
17+
}
18+
19+
protected function prepareForValidation()
20+
{
21+
}
22+
23+
/**
24+
* Get the validation rules that apply to the request.
25+
*
26+
* @return array
27+
*/
28+
public function rules()
29+
{
30+
return [
31+
'message_param' => 'nullable|string',
32+
];
33+
}
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Rakutentech\LaravelRequestDocs\Tests\TestRequests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
7+
class WelcomeIndexRequest extends FormRequest
8+
{
9+
/**
10+
* Determine if the user is authorized to make this request.
11+
*
12+
* @return bool
13+
*/
14+
public function authorize()
15+
{
16+
return true;
17+
}
18+
19+
protected function prepareForValidation()
20+
{
21+
}
22+
23+
/**
24+
* Get the validation rules that apply to the request.
25+
*
26+
* @return array
27+
*/
28+
public function rules()
29+
{
30+
return [
31+
'page' => 'nullable|integer|min:1',
32+
'per_page' => 'nullable|integer|min:1|max:100',
33+
];
34+
}
35+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Rakutentech\LaravelRequestDocs\Tests\TestRequests;
4+
5+
use Illuminate\Foundation\Http\FormRequest;
6+
7+
class WelcomeStoreRequest extends FormRequest
8+
{
9+
/**
10+
* Determine if the user is authorized to make this request.
11+
*
12+
* @return bool
13+
*/
14+
public function authorize()
15+
{
16+
return true;
17+
}
18+
19+
protected function prepareForValidation()
20+
{
21+
}
22+
23+
/**
24+
* Get the validation rules that apply to the request.
25+
*
26+
* @return array
27+
*/
28+
public function rules()
29+
{
30+
return [
31+
'message_param' => 'nullable|string',
32+
];
33+
}
34+
}

0 commit comments

Comments
 (0)