Skip to content

Commit

Permalink
Fix bug with fetching pagination type for API Resources
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed May 16, 2020
1 parent f63536c commit d442641
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/scribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
],

/*
* 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',

Expand Down
5 changes: 4 additions & 1 deletion resources/views/partials/endpoint.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Extracting/Strategies/Responses/UseApiResourceTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public function getApiResourceResponse(array $tags)
$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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/Strategies/Responses/UseApiResourceTagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function can_parse_apiresourcecollection_tags_with_collection_class_and_p
$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);

Expand Down

0 comments on commit d442641

Please sign in to comment.