Skip to content

Commit 0a485ba

Browse files
authored
Merge pull request #4332 from BookStackApp/api_docs_tweaks
API Docs: Allowed multi-paragraph descriptions
2 parents 4bb2cf5 + 38883e8 commit 0a485ba

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed

app/Api/ApiDocsGenerator.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
class ApiDocsGenerator
1818
{
19-
protected $reflectionClasses = [];
20-
protected $controllerClasses = [];
19+
protected array $reflectionClasses = [];
20+
protected array $controllerClasses = [];
2121

2222
/**
2323
* Load the docs form the cache if existing
@@ -139,9 +139,10 @@ protected function getValidationAsString($validation): string
139139
protected function parseDescriptionFromMethodComment(string $comment): string
140140
{
141141
$matches = [];
142-
preg_match_all('/^\s*?\*\s((?![@\s]).*?)$/m', $comment, $matches);
142+
preg_match_all('/^\s*?\*\s?($|((?![\/@\s]).*?))$/m', $comment, $matches);
143143

144-
return implode(' ', $matches[1] ?? []);
144+
$text = implode(' ', $matches[1] ?? []);
145+
return str_replace(' ', "\n", $text);
145146
}
146147

147148
/**

app/Entities/Controllers/PageApiController.php

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public function create(Request $request)
8282

8383
/**
8484
* View the details of a single page.
85-
*
8685
* Pages will always have HTML content. They may have markdown content
8786
* if the markdown editor was used to last update the page.
8887
*

app/Permissions/ContentPermissionApiController.php

+3
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ public function __construct(
3838

3939
/**
4040
* Read the configured content-level permissions for the item of the given type and ID.
41+
*
4142
* 'contentType' should be one of: page, book, chapter, bookshelf.
4243
* 'contentId' should be the relevant ID of that item type you'd like to handle permissions for.
44+
*
4345
* The permissions shown are those that override the default for just the specified item, they do not show the
4446
* full evaluated permission for a role, nor do they reflect permissions inherited from other items in the hierarchy.
4547
* Fallback permission values may be `null` when inheriting is active.
@@ -57,6 +59,7 @@ public function read(string $contentType, string $contentId)
5759
/**
5860
* Update the configured content-level permission overrides for the item of the given type and ID.
5961
* 'contentType' should be one of: page, book, chapter, bookshelf.
62+
*
6063
* 'contentId' should be the relevant ID of that item type you'd like to handle permissions for.
6164
* Providing an empty `role_permissions` array will remove any existing configured role permissions,
6265
* so you may want to fetch existing permissions beforehand if just adding/removing a single item.

app/Uploads/Controllers/ImageGalleryApiController.php

+2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ public function list()
5252

5353
/**
5454
* Create a new image in the system.
55+
*
5556
* Since "image" is expected to be a file, this needs to be a 'multipart/form-data' type request.
5657
* The provided "uploaded_to" should be an existing page ID in the system.
58+
*
5759
* If the "name" parameter is omitted, the filename of the provided image file will be used instead.
5860
* The "type" parameter should be 'gallery' for page content images, and 'drawio' should only be used
5961
* when the file is a PNG file with diagrams.net image data embedded within.

resources/views/api-docs/parts/endpoint.blade.php

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
<h6 class="text-uppercase text-muted float right">{{ $endpoint['controller_method_kebab'] }}</h6>
1+
<div class="flex-container-row items-center gap-m">
2+
<span class="api-method text-mono" data-method="{{ $endpoint['method'] }}">{{ $endpoint['method'] }}</span>
3+
<h5 id="{{ $endpoint['name'] }}" class="text-mono pb-xs">
4+
@if($endpoint['controller_method_kebab'] === 'list')
5+
<a style="color: inherit;" target="_blank" rel="noopener" href="{{ url($endpoint['uri']) }}">{{ url($endpoint['uri']) }}</a>
6+
@else
7+
<span>{{ url($endpoint['uri']) }}</span>
8+
@endif
9+
</h5>
10+
<h6 class="text-uppercase text-muted text-mono ml-auto">{{ $endpoint['controller_method_kebab'] }}</h6>
11+
</div>
212

3-
<h5 id="{{ $endpoint['name'] }}" class="text-mono mb-m">
4-
<span class="api-method" data-method="{{ $endpoint['method'] }}">{{ $endpoint['method'] }}</span>
5-
@if($endpoint['controller_method_kebab'] === 'list')
6-
<a style="color: inherit;" target="_blank" rel="noopener" href="{{ url($endpoint['uri']) }}">{{ url($endpoint['uri']) }}</a>
7-
@else
8-
{{ url($endpoint['uri']) }}
9-
@endif
10-
</h5>
11-
12-
<p class="mb-m">{{ $endpoint['description'] ?? '' }}</p>
13+
<div class="mb-m">
14+
@foreach(explode("\n", $endpoint['description'] ?? '') as $descriptionBlock)
15+
<p class="mb-xxs">{{ $descriptionBlock }}</p>
16+
@endforeach
17+
</div>
1318

1419
@if($endpoint['body_params'] ?? false)
1520
<details class="mb-m">

tests/Api/ApiDocsTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ApiDocsTest extends TestCase
88
{
99
use TestsApi;
1010

11-
protected $endpoint = '/api/docs';
11+
protected string $endpoint = '/api/docs';
1212

1313
public function test_api_endpoint_redirects_to_docs()
1414
{

0 commit comments

Comments
 (0)