Skip to content

Commit

Permalink
Merge pull request #62 from rakutentech/feature/ui
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
kevincobain2000 authored Mar 29, 2022
2 parents eb12f27 + 5cedb5d commit adfc957
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 32 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,5 @@ Fixing lints
- v1.15 Adds Filter and fall back to regexp upon Exception
- v1.17 Donot restrict to FormRequest
- v1.18 Fix where prism had fixed height. Allow text area resize.
- v1.18 Updated UI and pushed unit tests

50 changes: 20 additions & 30 deletions resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@
</nav>
<div id="app" v-cloak class="w-full flex lg:pt-10">
<aside class="text-sm ml-1.5 text-grey-darkest break-all bg-gray-200 pl-2 h-screen sticky top-1 overflow-auto">
<section class="pt-5 pl-2 pr-2 pb-5 border mb-10 rounded bg-white shadow">
<div class="font-sans">
<h2 class="text-sm break-normal text-black break-normal font-sans pb-1 pt-1 text-black">
Filter
</h2>
<p class="text-xs pb-2 font-medium text-gray-500">Hide non matching</code></p>
<input type="text" v-model="filterTerm" @input="filterDocs" class="w-full p-2 border-2 border-gray-300 rounded" placeholder="/api/search">
</div>
</section>
<section class="pt-5 pl-2 pr-2 pb-5 border mb-10 rounded bg-white shadow">
<div class="font-sans">
<h2 class="text-sm break-normal text-black break-normal font-sans pb-1 pt-1 text-black">
Edit Request Headers
</h2>
<p class="text-xs pb-2 font-medium text-gray-500">Default headers sent on every request. Format <code>Key:Value</code></p>
<prism-editor
class="my-prism-editor"
style="max-width:100%;min-height:100px;background:#2d2d2d;color: #ccc;resize:both" v-model="requestHeaders" :highlight="highlighter" line-numbers></prism-editor>
</div>
</section>
<h1 class="font-medium mx-3 mt-3" style="width: max-content;min-width:350px;">Routes List</h1>
<hr class="border-b border-gray-300">
<table class="table-fixed text-sm mt-5" style="width: max-content">
Expand Down Expand Up @@ -153,36 +173,6 @@ class="inline-flex text-xs"
</aside>
<br><br>
<div class="ml-6 mr-6 pl-2 w-2/3 p-2" style="width: 100%">
<h1 class="pl-2 pr-2 break-normal text-black break-normal font-sans text-black font-medium">
Search・Sort settings
</h1>
<hr class="border-b border-gray-300">
<br>
<section class="pt-5 pl-2 pr-2 pb-5 border mb-10 rounded bg-white shadow">
<div class="font-sans">
<h2 class="text-sm break-normal text-black break-normal font-sans pb-1 pt-1 text-black">
Filter
</h2>
<p class="text-xs pb-2 font-medium text-gray-500">Hide non matching</code></p>
<input type="text" v-model="filterTerm" @input="filterDocs" class="w-full p-2 border-2 border-gray-300 rounded" placeholder="/api/search">
</div>
</section>
<h1 class="pl-2 pr-2 break-normal text-black break-normal font-sans text-black font-medium">
Request Settings (editable)
</h1>
<hr class="border-b border-gray-300">
<br>
<section class="pt-5 pl-2 pr-2 pb-5 border mb-10 rounded bg-white shadow">
<div class="font-sans">
<h2 class="text-sm break-normal text-black break-normal font-sans pb-1 pt-1 text-black">
Append Request Headers
</h2>
<p class="text-xs pb-2 font-medium text-gray-500">Default headers sent on every request. Format <code>Key:Value</code></p>
<prism-editor
class="my-prism-editor"
style="min-height:100px;background:#2d2d2d;color: #ccc;resize:both" v-model="requestHeaders" :highlight="highlighter" line-numbers></prism-editor>
</div>
</section>
<h1 class="pl-2 pr-2 break-normal text-black break-normal font-sans text-black font-medium">
Routes List
</h1>
Expand Down
7 changes: 6 additions & 1 deletion src/LaravelRequestDocs.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,15 @@ public function getControllersInfo(): array
}
}

$middlewares = [];
if (!empty($route->action['middleware'])) {
$middlewares = !is_array($route->action['middleware']) ? [$route->action['middleware']] : $route->action['middleware'];
}

$controllersInfo[] = [
'uri' => $route->uri,
'methods' => $route->methods,
'middlewares' => !is_array($route->action['middleware']) ? [$route->action['middleware']] : $route->action['middleware'],
'middlewares' => $middlewares,
'controller' => $controllerName,
'controller_full_path' => $controllerFullPath,
'method' => $method,
Expand Down
42 changes: 42 additions & 0 deletions tests/LRDTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Rakutentech\LaravelRequestDocs\Tests;
use Route;

class LRDTest extends TestCase
{
public function testDocsCount()
{
$docs = $this->lrd->getDocs();
$routes = collect(Route::getRoutes());

$this->assertSame($routes->count(), count($docs));
}

public function testDocsCanFetchAllMethods()
{
$docs = $this->lrd->getDocs();
$methods = [];
foreach ($docs as $doc) {
$methods = array_merge($methods, $doc['methods']);
}
$methods = array_unique($methods);
sort($methods);
$this->assertSame(['DELETE', 'GET', 'HEAD', 'POST', 'PUT'], $methods);
}

public function testDocsCanFetchInfo()
{
$docs = $this->lrd->getDocs();
foreach ($docs as $doc) {
$this->assertNotEmpty($doc['rules']);
$this->assertNotEmpty($doc['methods']);
// $this->assertNotEmpty($doc['middlewares']); //todo: add middlewares to test
$this->assertNotEmpty($doc['controller']);
$this->assertNotEmpty($doc['controller_full_path']);
$this->assertNotEmpty($doc['method']);
$this->assertNotEmpty($doc['httpMethod']);
$this->assertNotEmpty($doc['rules']);
}
}
}
15 changes: 14 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@

namespace Rakutentech\LaravelRequestDocs\Tests;

use Illuminate\Database\Eloquent\Factories\Factory;
use Orchestra\Testbench\TestCase as Orchestra;
use Rakutentech\LaravelRequestDocs\LaravelRequestDocsServiceProvider;
use Rakutentech\LaravelRequestDocs\LaravelRequestDocs;
use Illuminate\Support\Facades\Route;
use Rakutentech\LaravelRequestDocs\Tests\TestControllers;

class TestCase extends Orchestra
{
protected LaravelRequestDocs $lrd;
public function setUp(): void
{
parent::setUp();
$this->lrd = new LaravelRequestDocs();
$this->registerRoutes();
}

protected function getPackageProviders($app)
Expand All @@ -24,4 +29,12 @@ public function getEnvironmentSetUp($app)
{
config()->set('database.default', 'testing');
}

public function registerRoutes() {
Route::get('/', [TestControllers\WelcomeController::class, 'index']);
Route::get('welcome', [TestControllers\WelcomeController::class, 'index']);
Route::post('welcome', [TestControllers\WelcomeController::class, 'store']);
Route::put('welcome', [TestControllers\WelcomeController::class, 'edit']);
Route::delete('welcome', [TestControllers\WelcomeController::class, 'destroy']);
}
}
31 changes: 31 additions & 0 deletions tests/TestControllers/WelcomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rakutentech\LaravelRequestDocs\Tests\TestControllers;

use Rakutentech\LaravelRequestDocs\Tests\TestRequests\WelcomeIndexRequest;
use Rakutentech\LaravelRequestDocs\Tests\TestRequests\WelcomeEditRequest;
use Rakutentech\LaravelRequestDocs\Tests\TestRequests\WelcomeStoreRequest;
use Rakutentech\LaravelRequestDocs\Tests\TestRequests\WelcomeDeleteRequest;

class WelcomeController
{
public function index(WelcomeIndexRequest $request)
{
return 1;
}

public function edit(WelcomeEditRequest $request)
{
return 1;
}

public function store(WelcomeStoreRequest $request)
{
return 1;
}

public function destroy(WelcomeDeleteRequest $request)
{
return 1;
}
}
34 changes: 34 additions & 0 deletions tests/TestRequests/WelcomeDeleteRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Rakutentech\LaravelRequestDocs\Tests\TestRequests;

use Illuminate\Foundation\Http\FormRequest;

class WelcomeDeleteRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

protected function prepareForValidation()
{
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'message_param' => 'nullable|string',
];
}
}
34 changes: 34 additions & 0 deletions tests/TestRequests/WelcomeEditRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Rakutentech\LaravelRequestDocs\Tests\TestRequests;

use Illuminate\Foundation\Http\FormRequest;

class WelcomeEditRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

protected function prepareForValidation()
{
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'message_param' => 'nullable|string',
];
}
}
35 changes: 35 additions & 0 deletions tests/TestRequests/WelcomeIndexRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Rakutentech\LaravelRequestDocs\Tests\TestRequests;

use Illuminate\Foundation\Http\FormRequest;

class WelcomeIndexRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

protected function prepareForValidation()
{
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'page' => 'nullable|integer|min:1',
'per_page' => 'nullable|integer|min:1|max:100',
];
}
}
34 changes: 34 additions & 0 deletions tests/TestRequests/WelcomeStoreRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Rakutentech\LaravelRequestDocs\Tests\TestRequests;

use Illuminate\Foundation\Http\FormRequest;

class WelcomeStoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

protected function prepareForValidation()
{
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'message_param' => 'nullable|string',
];
}
}

0 comments on commit adfc957

Please sign in to comment.