Skip to content

Commit 47f8692

Browse files
authored
Merge pull request #393 from shalvah/v3
Fix issues with rendering example requests
2 parents a6a4335 + 9219179 commit 47f8692

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

resources/views/partials/route.blade.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
<!-- START_{{$route['id']}} -->
22
@if($route['title'] != '')## {{ $route['title']}}
33
@else## {{$route['uri']}}@endif
4-
@if($route['authenticated'])<small style="
5-
padding: 1px 9px 2px;
6-
font-weight: bold;
7-
white-space: nowrap;
8-
color: #ffffff;
9-
-webkit-border-radius: 9px;
10-
-moz-border-radius: 9px;
11-
border-radius: 9px;
12-
background-color: #3a87ad;">Requires authentication</small>@endif
4+
@if($route['authenticated'])
5+
6+
<br><small style="padding: 1px 9px 2px;font-weight: bold;white-space: nowrap;color: #ffffff;-webkit-border-radius: 9px;-moz-border-radius: 9px;border-radius: 9px;background-color: #3a87ad;">Requires authentication</small>@endif
137
@if($route['description'])
148

159
{!! $route['description'] !!}
@@ -18,20 +12,17 @@
1812
> Example request:
1913

2014
```bash
21-
curl -X {{$route['methods'][0]}} {{$route['methods'][0] == 'GET' ? '-G ' : ''}}"{{ trim(config('app.docs_url') ?: config('app.url'), '/')}}/{{ ltrim($route['uri'], '/') }}" \
22-
-H "Accept: application/json"@if(count($route['headers'])) \
15+
curl -X {{$route['methods'][0]}} {{$route['methods'][0] == 'GET' ? '-G ' : ''}}"{{ trim(config('app.docs_url') ?: config('app.url'), '/')}}/{{ ltrim($route['uri'], '/') }}" @if(count($route['headers']))\
2316
@foreach($route['headers'] as $header => $value)
24-
-H "{{$header}}: {{$value}}" @if(! ($loop->last))\
25-
@endif
17+
-H "{{$header}}: {{$value}}"@if(! ($loop->last) || ($loop->last && count($route['bodyParameters']))) \
18+
@endif
2619
@endforeach
2720
@endif
28-
29-
@if(count($route['bodyParameters'])) \
3021
@foreach($route['bodyParameters'] as $attribute => $parameter)
3122
-d "{{$attribute}}"="{{$parameter['value']}}" @if(! ($loop->last))\
32-
@endif
33-
@endforeach
3423
@endif
24+
@endforeach
25+
3526
```
3627

3728
```javascript
@@ -44,7 +35,6 @@
4435
"data": {!! str_replace("\n}","\n }", str_replace(' ',' ',json_encode(array_combine(array_keys($route['bodyParameters']), array_map(function($param){ return $param['value']; },$route['bodyParameters'])), JSON_PRETTY_PRINT))) !!},
4536
@endif
4637
"headers": {
47-
"accept": "application/json",
4838
@foreach($route['headers'] as $header => $value)
4939
"{{$header}}": "{{$value}}",
5040
@endforeach

tests/Fixtures/partial_resource_index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var settings = {
3838
"url": "http://localhost/api/users",
3939
"method": "GET",
4040
"headers": {
41-
"accept": "application/json",
41+
"Accept": "application/json",
4242
}
4343
}
4444

@@ -78,7 +78,7 @@ var settings = {
7878
"url": "http://localhost/api/users/create",
7979
"method": "GET",
8080
"headers": {
81-
"accept": "application/json",
81+
"Accept": "application/json",
8282
}
8383
}
8484

tests/Fixtures/resource_index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var settings = {
3838
"url": "http://localhost/api/users",
3939
"method": "GET",
4040
"headers": {
41-
"accept": "application/json",
41+
"Accept": "application/json",
4242
}
4343
}
4444

@@ -78,7 +78,7 @@ var settings = {
7878
"url": "http://localhost/api/users/create",
7979
"method": "GET",
8080
"headers": {
81-
"accept": "application/json",
81+
"Accept": "application/json",
8282
}
8383
}
8484

@@ -118,7 +118,7 @@ var settings = {
118118
"url": "http://localhost/api/users",
119119
"method": "POST",
120120
"headers": {
121-
"accept": "application/json",
121+
"Accept": "application/json",
122122
}
123123
}
124124

@@ -151,7 +151,7 @@ var settings = {
151151
"url": "http://localhost/api/users/{user}",
152152
"method": "GET",
153153
"headers": {
154-
"accept": "application/json",
154+
"Accept": "application/json",
155155
}
156156
}
157157

@@ -191,7 +191,7 @@ var settings = {
191191
"url": "http://localhost/api/users/{user}/edit",
192192
"method": "GET",
193193
"headers": {
194-
"accept": "application/json",
194+
"Accept": "application/json",
195195
}
196196
}
197197

@@ -231,7 +231,7 @@ var settings = {
231231
"url": "http://localhost/api/users/{user}",
232232
"method": "PUT",
233233
"headers": {
234-
"accept": "application/json",
234+
"Accept": "application/json",
235235
}
236236
}
237237

@@ -266,7 +266,7 @@ var settings = {
266266
"url": "http://localhost/api/users/{user}",
267267
"method": "DELETE",
268268
"headers": {
269-
"accept": "application/json",
269+
"Accept": "application/json",
270270
}
271271
}
272272

tests/GenerateDocumentationTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ public function can_parse_resource_routes()
107107
RouteFacade::resource('/api/users', TestResourceController::class);
108108

109109
config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
110+
config([
111+
'apidoc.routes.0.apply.headers' => [
112+
'Accept' => 'application/json',
113+
],
114+
]);
115+
110116
$this->artisan('apidoc:generate');
111117

112118
$fixtureMarkdown = __DIR__.'/Fixtures/resource_index.md';
@@ -129,6 +135,12 @@ public function can_parse_partial_resource_routes()
129135
}
130136

131137
config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
138+
config([
139+
'apidoc.routes.0.apply.headers' => [
140+
'Accept' => 'application/json',
141+
],
142+
]);
143+
132144
$this->artisan('apidoc:generate');
133145

134146
$fixtureMarkdown = __DIR__.'/Fixtures/partial_resource_index.md';

0 commit comments

Comments
 (0)