Skip to content

Commit f99482e

Browse files
Merge pull request rakutentech#13 from rakutentech/patch/rawahamid
Patch/rawahamid
2 parents 1217fc1 + 19f22ff commit f99482e

File tree

3 files changed

+45
-29
lines changed

3 files changed

+45
-29
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Automatically generate api documentation for Laravel without writing annotations.
44

5+
Read more: https://medium.com/web-developer/laravel-automatically-generate-api-documentation-without-annotations-a-swagger-alternative-e0699409a59e
56

67
## Requirements
78

resources/views/index.blade.php

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<link rel="stylesheet" href="https://unpkg.com/prismjs/themes/prism-tomorrow.css" />
1818

1919
<script src="https://unpkg.com/faker@5.5.3/dist/faker.min.js" referrerpolicy="no-referrer"></script>
20+
<script src="https://unpkg.com/string-similarity@4.0.2/umd/string-similarity.min.js" referrerpolicy="no-referrer"></script>
2021

2122
<script src="https://unpkg.com/vue-markdown@2.2.4/dist/vue-markdown.js"></script>
2223
<script src="https://cdnjs.cloudflare.com/ajax/libs/sql-formatter/3.1.0/sql-formatter.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
@@ -47,6 +48,7 @@
4748
}
4849
.dropdown-input, .dropdown-selected{
4950
width: 100%;
51+
font-size:14px;
5052
padding: 10px 16px;
5153
border: 1px solid transparent;
5254
background: #edf2f7;
@@ -77,9 +79,9 @@
7779
.dropdown-item{
7880
display: flex;
7981
width: 100%;
80-
padding: 11px 16px;
82+
padding: 2px 6px;
8183
cursor: pointer;
82-
font-size: 15;
84+
font-size: 12px;
8385
}
8486
.dropdown-item:hover{
8587
background: #edf2f7;
@@ -96,21 +98,23 @@
9698
</div>
9799
</nav>
98100
<div id="app" v-cloak class="w-full flex lg:pt-10">
99-
<aside class="text-xl text-grey-darkest break-all bg-gray-200 pl-2 h-screen sticky top-1 overflow-auto" style="width: 25%">
101+
<aside class="text-xl text-grey-darkest break-all bg-gray-200 pl-2 h-screen sticky top-1 overflow-auto" style="width: 35%">
100102
<h1 class="font-light mx-3">Routes List</h1>
101103
<div class="dropdown">
102104
<input
103105
v-model.trim="search"
104-
v-chang
105-
class="dropdown-input shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
106+
class="dropdown-input appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
106107
type="text"
107108
placeholder="Search"
108109
@focus="showRoute = true;$event.target.select()"
109110
@blur="setTimeout(() => { showRoute = false}, 200)"
110111
/>
111112
<div class="dropdown-list">
112113
@foreach ($docs as $index => $doc)
113-
<div v-show="showRoute" @click="searched('{{ $doc["methods"][0] }}', '{{ $doc["uri"] }}')" class="dropdown-item">
114+
<div v-if="filter('{{ $doc["uri"] }}')"
115+
v-show="showRoute"
116+
@click="searched('{{ $doc["methods"][0] }}', '{{ $doc["uri"] }}') ; highlightSidebar('{{ $index }}')"
117+
class="dropdown-item">
114118
{{ str_replace('api/', '', $doc['uri']) }}
115119
</div>
116120
@endforeach
@@ -126,10 +130,10 @@ class="dropdown-input shadow appearance-none border rounded w-full py-2 px-3 tex
126130
<tr>
127131
<td>
128132
@if ($previousController['controller'] !== $doc['controller'])
129-
<h3 class="my-2 font-semibold" style="font-size: 18px">{{ str_replace('Controller', '', $doc['controller']) }}</h3>
133+
<h3 class="mt-2 font-thin">{{ str_replace('Controller', '', $doc['controller']) }}</h3>
130134
@endif
131135
<a href="#{{$doc['methods'][0] .'-'. $doc['uri']}}" @click="highlightSidebar({{$index}})">
132-
<span class="w-20
136+
<span class="
133137
font-thin
134138
inline-flex
135139
items-center
@@ -201,7 +205,7 @@ class="dropdown-input shadow appearance-none border rounded w-full py-2 px-3 tex
201205
<tbody>
202206
<tr>
203207
<td class="align-left border border-gray-300 pl-2 pr-2 bg-gray-200 font-bold">Controller</td>
204-
<td class="align-left border pl-2 pr-2 break-all">{{$doc['controller']}}</td>
208+
<td class="align-left border pl-2 pr-2 break-all">{{$doc['controller_full_path']}}</td>
205209
</tr>
206210
<tr>
207211
<td class="align-left border border-gray-300 pl-2 pr-2 bg-gray-200 font-bold">Method</td>
@@ -494,6 +498,13 @@ class="my-prism-editor"
494498
showRoute: false
495499
},
496500
methods: {
501+
filter(uri) {
502+
if (!this.search) {
503+
return true
504+
}
505+
var similarity = stringSimilarity.compareTwoStrings(uri, this.search);
506+
return similarity > 0.1
507+
},
497508
searched(method, uri) {
498509
var oldUrl = new URL(document.URL);
499510
oldUrl.hash = '#' + method + '-' + uri;
@@ -567,8 +578,12 @@ class="my-prism-editor"
567578
doc.queries = error.data['_lrd']['queries']
568579
delete error.data['_lrd']
569580
}
570-
doc.response = JSON.stringify(error.response.data, null, 2)
571-
doc.responseCode = error.response.status;
581+
doc.loading = false
582+
if (error && error.response && error.response.data) {
583+
doc.response = JSON.stringify(error.response.data, null, 2)
584+
doc.responseCode = error.response.status;
585+
}
586+
572587
doc.responseOk = false
573588
}).then(function () {
574589
doc.loading = false

src/LaravelRequestDocs.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@ class LaravelRequestDocs
1414

1515
public function getDocs()
1616
{
17-
$docs = [];
18-
$excludePatterns = config('request-docs.hide_matching') ?? [];
19-
$controllersInfo = $this->getControllersInfo();
20-
$controllersInfo = $this->appendRequestRules($controllersInfo);
21-
foreach ($controllersInfo as $controllerInfo) {
22-
try {
23-
$exclude = false;
24-
foreach ($excludePatterns as $regex) {
25-
$uri = $controllerInfo['uri'];
26-
if (preg_match($regex, $uri)) {
27-
$exclude = true;
28-
}
29-
}
30-
if (!$exclude) {
31-
$docs[] = $controllerInfo;
17+
$docs = [];
18+
$excludePatterns = config('request-docs.hide_matching') ?? [];
19+
$controllersInfo = $this->getControllersInfo();
20+
$controllersInfo = $this->appendRequestRules($controllersInfo);
21+
foreach ($controllersInfo as $controllerInfo) {
22+
try {
23+
$exclude = false;
24+
foreach ($excludePatterns as $regex) {
25+
$uri = $controllerInfo['uri'];
26+
if (preg_match($regex, $uri)) {
27+
$exclude = true;
3228
}
33-
} catch (Exception $exception) {
34-
continue;
3529
}
30+
if (!$exclude) {
31+
$docs[] = $controllerInfo;
32+
}
33+
} catch (Exception $exception) {
34+
continue;
3635
}
37-
return array_filter($docs);
36+
}
37+
return array_filter($docs);
3838
}
3939

4040
public function sortDocs(array $docs, $sortBy = 'default'): Array

0 commit comments

Comments
 (0)