瀏覽代碼

Fix bug with fetching pagination type for API Resources

shalvah 5 年之前
父節點
當前提交
d442641b4b

+ 1 - 1
config/scribe.php

@@ -135,7 +135,7 @@ INTRO
     ],
 
     /*
-     * Name for the group of routes which do not have a @group set.
+     * Name for the group of endpoints which do not have a @group set.
      */
     'default_group' => 'Endpoints',
 

+ 4 - 1
resources/views/partials/endpoint.blade.php

@@ -19,10 +19,13 @@
 ```json
 @if(is_object($response['content']) || is_array($response['content']))
 {!! json_encode($response['content'], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) !!}
-@elseif(\Illuminate\Support\Str::startsWith($response['content'], "<<binary>>"))
+@elseif(is_string($response['content']) && \Illuminate\Support\Str::startsWith($response['content'], "<<binary>>"))
 <Binary data> - {{ str_replace("<<binary>>","",$response['content']) }}
 @elseif($response['status'] == 204)
 <Empty response>
+@elseif(is_string($response['content']) && json_decode($response['content']) == null && $response['content'] !== null)
+{{-- If response is a non-JSON string, just print it --}}
+{!! $response['content'] !!}
 @else
 {!! json_encode(json_decode($response['content']), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) !!}
 @endif

+ 2 - 2
src/Extracting/Strategies/Responses/UseApiResourceTags.php

@@ -97,8 +97,8 @@ class UseApiResourceTags extends Strategy
                     $perPage
                 );
                 $list = $paginator;
-            } elseif (count($pagination) == 2 && $pagination[0] == 'simple') {
-                $perPage = $pagination[1];
+            } elseif (count($pagination) == 2 && $pagination[1] == 'simple') {
+                $perPage = $pagination[0];
                 $paginator = new Paginator($models, $perPage);
                 $list = $paginator;
             } else {

+ 1 - 1
tests/Strategies/Responses/UseApiResourceTagsTest.php

@@ -214,7 +214,7 @@ class UseApiResourceTagsTest extends TestCase
         $strategy = new UseApiResourceTags($config);
         $tags = [
             new Tag('apiResourceCollection', 'Knuckles\Scribe\Tests\Fixtures\TestUserApiResourceCollection'),
-            new Tag('apiResourceModel', '\Knuckles\Scribe\Tests\Fixtures\TestUser paginate=simple,1'),
+            new Tag('apiResourceModel', '\Knuckles\Scribe\Tests\Fixtures\TestUser paginate=1,simple'),
         ];
         $results = $strategy->getApiResourceResponse($tags);