Skip to content

Commit 4a78b94

Browse files
Merge pull request #47 from rakutentech/feature/invade
Fixes: #37 with heuristic
2 parents 679b0cd + 8b92ee0 commit 4a78b94

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

config/request-docs.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

33
return [
4+
// change it to true will make lrd to throw exception if rules in request class need to be changed
5+
// keep it false
6+
'debug' => false,
47
'document_name' => 'LRD',
58

69
/*

resources/views/index.blade.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@
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-
<h1 class="font-medium mx-3 mt-3">Routes List</h1>
103+
<h1 class="font-medium mx-3 mt-3" style="width: max-content;min-width:350px;">Routes List</h1>
104104
<hr class="border-b border-gray-300">
105105
<table class="table-fixed text-sm mt-5" style="width: max-content">
106106
<tbody>
107107
@foreach ($docs as $index => $doc)
108108
<tr>
109109
<td>
110-
<a href="#{{$doc['methods'][0] .'-'. $doc['uri']}}" @click="highlightSidebar({{$index}})">
110+
<a href="#{{$doc['methods'][0] .'-'. $doc['uri']}}" @click="highlightSidebar({{$index}})" v-if="!docs[{{$index}}]['isHidden']">
111111
<span class="
112112
font-medium
113113
inline-flex
@@ -154,7 +154,21 @@ class="inline-flex text-xs"
154154
<br><br>
155155
<div class="ml-6 mr-6 pl-2 w-2/3 p-2" style="width: 100%">
156156
<h1 class="pl-2 pr-2 break-normal text-black break-normal font-sans text-black font-medium">
157-
Settings
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)
158172
</h1>
159173
<hr class="border-b border-gray-300">
160174
<br>
@@ -175,7 +189,7 @@ class="my-prism-editor"
175189
<hr class="border-b border-gray-300">
176190
<br>
177191
@foreach ($docs as $index => $doc)
178-
<section class="pt-5 pl-2 pr-2 pb-5 border mb-10 rounded bg-white shadow">
192+
<section class="pt-5 pl-2 pr-2 pb-5 border mb-10 rounded bg-white shadow" v-if="!docs[{{$index}}]['isHidden']">
179193
<div class="font-sans" id="{{$doc['httpMethod'] .'-'. $doc['uri']}}">
180194
<h1 class="text-sm break-normal text-black bg-indigo-50 break-normal font-sans pb-1 pt-1 text-black">
181195
<span class="w-20
@@ -618,7 +632,8 @@ class="my-prism-editor"
618632
data: {
619633
docs: docs,
620634
showRoute: false,
621-
requestHeaders: ''
635+
requestHeaders: '',
636+
filterTerm: ''
622637
},
623638
created: function () {
624639
axios.defaults.headers.common['X-CSRF-TOKEN'] = document.querySelector('meta[name="csrf-token"]').getAttribute('content'),
@@ -637,6 +652,11 @@ class="my-prism-editor"
637652
highlighterAtom(code) {
638653
return Prism.highlight(code, Prism.languages.atom, "js");
639654
},
655+
filterDocs() {
656+
for (doc of this.docs) {
657+
doc['isHidden'] = !doc['uri'].includes(this.filterTerm)
658+
}
659+
},
640660
request(doc) {
641661
642662
// convert string to lower case

src/LaravelRequestDocs.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ public function appendRequestRules(array $controllersInfo)
135135
// doesn't work well when the same rule is defined as array ['required', 'integer'] or in multiple lines such as
136136
// If your rules are not populated using this library, then fix your rule to only throw validation errors and not throw exceptions
137137
// such as 404, 500 inside the request class.
138-
// $controllersInfo[$index]['rules'] = $this->rulesByRegex($requestClassName);
138+
$controllersInfo[$index]['rules'] = $this->rulesByRegex($requestClassName);
139139

140-
//TODO: enable debug mode so unsupported coding practices can be fixed by the developer
141-
// throw $e;
140+
if (config('request-docs.debug')) {
141+
throw $e;
142+
}
142143
}
143144
$controllersInfo[$index]['docBlock'] = $this->lrdDocComment($reflectionMethod->getDocComment());
144145
}
@@ -206,8 +207,11 @@ public function rulesByRegex($requestClassName)
206207
$rules = [];
207208

208209
for ($i = $data->getStartLine() - 1; $i <= $data->getEndLine() - 1; $i++) {
209-
preg_match_all("/(?:'|\").*?(?:'|\")/", $lines[$i], $matches);
210-
$rules[] = $matches;
210+
// check if => in string, only pick up rules that are coded on single line
211+
if (Str::contains($lines[$i], '=>')) {
212+
preg_match_all("/(?:'|\").*?(?:'|\")/", $lines[$i], $matches);
213+
$rules[] = $matches;
214+
}
211215
}
212216

213217
$rules = collect($rules)

0 commit comments

Comments
 (0)