mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-02-20 06:29:44 +08:00
Refined docs view, Added example requests
This commit is contained in:
parent
45b5e631e2
commit
8016f1121e
|
@ -31,9 +31,12 @@ class ApiDocsGenerator
|
||||||
protected function loadDetailsFromFiles(Collection $routes): Collection
|
protected function loadDetailsFromFiles(Collection $routes): Collection
|
||||||
{
|
{
|
||||||
return $routes->map(function (array $route) {
|
return $routes->map(function (array $route) {
|
||||||
$exampleResponseFile = base_path('dev/api/responses/' . $route['name'] . '.json');
|
$exampleTypes = ['request', 'response'];
|
||||||
$exampleResponse = file_exists($exampleResponseFile) ? file_get_contents($exampleResponseFile) : null;
|
foreach ($exampleTypes as $exampleType) {
|
||||||
$route['example_response'] = $exampleResponse;
|
$exampleFile = base_path("dev/api/{$exampleType}s/{$route['name']}.json");
|
||||||
|
$exampleContent = file_exists($exampleFile) ? file_get_contents($exampleFile) : null;
|
||||||
|
$route["example_{$exampleType}"] = $exampleContent;
|
||||||
|
}
|
||||||
return $route;
|
return $route;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
4
dev/api/requests/books-create.json
Normal file
4
dev/api/requests/books-create.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"name": "My own book",
|
||||||
|
"description": "This is my own little book"
|
||||||
|
}
|
4
dev/api/requests/books-update.json
Normal file
4
dev/api/requests/books-update.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"name": "My updated book",
|
||||||
|
"description": "This is my book with updated details"
|
||||||
|
}
|
|
@ -12,32 +12,64 @@
|
||||||
|
|
||||||
@foreach($endpoints as $endpoint)
|
@foreach($endpoints as $endpoint)
|
||||||
<div class="mb-xs">
|
<div class="mb-xs">
|
||||||
<a href="#{{ $endpoint['name'] }}" class="text-mono">
|
<a href="#{{ $endpoint['name'] }}" class="text-mono inline block mr-s">
|
||||||
<span class="api-method" data-method="{{ $endpoint['method'] }}">{{ $endpoint['method'] }}</span>
|
<span class="api-method" data-method="{{ $endpoint['method'] }}">{{ $endpoint['method'] }}</span>
|
||||||
/{{ $endpoint['uri'] }}
|
</a>
|
||||||
|
<a href="#{{ $endpoint['name'] }}" class="text-mono">
|
||||||
|
{{ $endpoint['controller_method'] }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@endforeach
|
@endforeach
|
||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div style="overflow: auto;">
|
||||||
@foreach($docs as $model => $endpoints)
|
@foreach($docs as $model => $endpoints)
|
||||||
<section class="card content-wrap auto-height">
|
<section class="card content-wrap auto-height">
|
||||||
<h1 class="list-heading text-capitals">{{ $model }}</h1>
|
<h1 class="list-heading text-capitals">{{ $model }}</h1>
|
||||||
|
|
||||||
@foreach($endpoints as $endpoint)
|
@foreach($endpoints as $endpoint)
|
||||||
|
<h6 class="text-uppercase text-muted float right">{{ $endpoint['controller_method'] }}</h6>
|
||||||
<h5 id="{{ $endpoint['name'] }}" class="text-mono mb-m">
|
<h5 id="{{ $endpoint['name'] }}" class="text-mono mb-m">
|
||||||
<span class="api-method" data-method="{{ $endpoint['method'] }}">{{ $endpoint['method'] }}</span>
|
<span class="api-method" data-method="{{ $endpoint['method'] }}">{{ $endpoint['method'] }}</span>
|
||||||
{{ url($endpoint['uri']) }}
|
{{ url($endpoint['uri']) }}
|
||||||
</h5>
|
</h5>
|
||||||
<p class="mb-m">{{ $endpoint['description'] ?? '' }}</p>
|
<p class="mb-m">{{ $endpoint['description'] ?? '' }}</p>
|
||||||
|
@if($endpoint['body_params'] ?? false)
|
||||||
|
<details class="mb-m">
|
||||||
|
<summary class="text-muted">Body Parameters</summary>
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th>Param Name</th>
|
||||||
|
<th>Value Rules</th>
|
||||||
|
</tr>
|
||||||
|
@foreach($endpoint['body_params'] as $paramName => $rules)
|
||||||
|
<tr>
|
||||||
|
<td>{{ $paramName }}</td>
|
||||||
|
<td>
|
||||||
|
@foreach($rules as $rule)
|
||||||
|
<code class="mr-xs">{{ $rule }}</code>
|
||||||
|
@endforeach
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</table>
|
||||||
|
</details>
|
||||||
|
@endif
|
||||||
|
@if($endpoint['example_request'] ?? false)
|
||||||
|
<details details-highlighter class="mb-m">
|
||||||
|
<summary class="text-muted">Example Request</summary>
|
||||||
|
<pre><code class="language-json">{{ $endpoint['example_request'] }}</code></pre>
|
||||||
|
</details>
|
||||||
|
@endif
|
||||||
@if($endpoint['example_response'] ?? false)
|
@if($endpoint['example_response'] ?? false)
|
||||||
<details details-highlighter>
|
<details details-highlighter class="mb-m">
|
||||||
<summary class="text-muted">Example Response</summary>
|
<summary class="text-muted">Example Response</summary>
|
||||||
<pre><code class="language-json">{{ $endpoint['example_response'] }}</code></pre>
|
<pre><code class="language-json">{{ $endpoint['example_response'] }}</code></pre>
|
||||||
</details>
|
</details>
|
||||||
<hr class="mt-m">
|
@endif
|
||||||
|
@if(!$loop->last)
|
||||||
|
<hr>
|
||||||
@endif
|
@endif
|
||||||
@endforeach
|
@endforeach
|
||||||
</section>
|
</section>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user