Sfoglia il codice sorgente

Fix issues with rendering example requests

shalvah 6 anni fa
parent
commit
8628be4c12

+ 5 - 9
resources/views/partials/route.blade.php

@@ -18,20 +18,17 @@
 > Example request:
 
 ```bash
-curl -X {{$route['methods'][0]}} {{$route['methods'][0] == 'GET' ? '-G ' : ''}}"{{ trim(config('app.docs_url') ?: config('app.url'), '/')}}/{{ ltrim($route['uri'], '/') }}" \
-    -H "Accept: application/json"@if(count($route['headers'])) \
+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']))\
 @foreach($route['headers'] as $header => $value)
-    -H "{{$header}}: {{$value}}" @if(! ($loop->last))\
-    @endif
+    -H "{{$header}}: {{$value}}"@if(! ($loop->last) || ($loop->last && count($route['bodyParameters']))) \
+@endif
 @endforeach
 @endif
-
-@if(count($route['bodyParameters'])) \
 @foreach($route['bodyParameters'] as $attribute => $parameter)
     -d "{{$attribute}}"="{{$parameter['value']}}" @if(! ($loop->last))\
-    @endif
-@endforeach
 @endif
+@endforeach
+
 ```
 
 ```javascript
@@ -44,7 +41,6 @@ var settings = {
 "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))) !!},
     @endif
 "headers": {
-        "accept": "application/json",
 @foreach($route['headers'] as $header => $value)
         "{{$header}}": "{{$value}}",
 @endforeach

+ 2 - 2
tests/Fixtures/partial_resource_index.md

@@ -38,7 +38,7 @@ var settings = {
     "url": "http://localhost/api/users",
     "method": "GET",
     "headers": {
-        "accept": "application/json",
+        "Accept": "application/json",
     }
 }
 
@@ -78,7 +78,7 @@ var settings = {
     "url": "http://localhost/api/users/create",
     "method": "GET",
     "headers": {
-        "accept": "application/json",
+        "Accept": "application/json",
     }
 }
 

+ 7 - 7
tests/Fixtures/resource_index.md

@@ -38,7 +38,7 @@ var settings = {
     "url": "http://localhost/api/users",
     "method": "GET",
     "headers": {
-        "accept": "application/json",
+        "Accept": "application/json",
     }
 }
 
@@ -78,7 +78,7 @@ var settings = {
     "url": "http://localhost/api/users/create",
     "method": "GET",
     "headers": {
-        "accept": "application/json",
+        "Accept": "application/json",
     }
 }
 
@@ -118,7 +118,7 @@ var settings = {
     "url": "http://localhost/api/users",
     "method": "POST",
     "headers": {
-        "accept": "application/json",
+        "Accept": "application/json",
     }
 }
 
@@ -151,7 +151,7 @@ var settings = {
     "url": "http://localhost/api/users/{user}",
     "method": "GET",
     "headers": {
-        "accept": "application/json",
+        "Accept": "application/json",
     }
 }
 
@@ -191,7 +191,7 @@ var settings = {
     "url": "http://localhost/api/users/{user}/edit",
     "method": "GET",
     "headers": {
-        "accept": "application/json",
+        "Accept": "application/json",
     }
 }
 
@@ -231,7 +231,7 @@ var settings = {
     "url": "http://localhost/api/users/{user}",
     "method": "PUT",
     "headers": {
-        "accept": "application/json",
+        "Accept": "application/json",
     }
 }
 
@@ -266,7 +266,7 @@ var settings = {
     "url": "http://localhost/api/users/{user}",
     "method": "DELETE",
     "headers": {
-        "accept": "application/json",
+        "Accept": "application/json",
     }
 }
 

+ 12 - 0
tests/GenerateDocumentationTest.php

@@ -107,6 +107,12 @@ class GenerateDocumentationTest extends TestCase
         RouteFacade::resource('/api/users', TestResourceController::class);
 
         config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
+        config([
+            'apidoc.routes.0.apply.headers' => [
+                'Accept' => 'application/json',
+            ],
+        ]);
+
         $this->artisan('apidoc:generate');
 
         $fixtureMarkdown = __DIR__.'/Fixtures/resource_index.md';
@@ -129,6 +135,12 @@ class GenerateDocumentationTest extends TestCase
         }
 
         config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
+        config([
+            'apidoc.routes.0.apply.headers' => [
+                'Accept' => 'application/json',
+            ],
+        ]);
+
         $this->artisan('apidoc:generate');
 
         $fixtureMarkdown = __DIR__.'/Fixtures/partial_resource_index.md';