Skip to content

Commit 5fbb8aa

Browse files
Merge branch 'master' into 158-ability-to-generate-documentation-for-invokable-controllers
2 parents 6b1b86d + d8dea15 commit 5fbb8aa

24 files changed

+871
-274
lines changed

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/.github export-ignore
2+
/bootstrap export-ignore
3+
/storage export-ignore
4+
/tests export-ignore
5+
composer.lock export-ignore
6+
CONTRIBUTING.md export-ignore
7+
docker-compose.yml export-ignore
8+
MIGRATION-GUIDES.md export-ignore
9+
phpunit.xml export-ignore

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.idea
1+
.idea/
22
vendor/
33
node_modules/
44

@@ -12,8 +12,5 @@ bootstrap/cache/
1212
.env.php
1313
.env
1414

15-
# Rocketeer PHP task runner and deployment package. https://github.com/rocketeers/rocketeer
16-
.rocketeer/
17-
1815
.phpunit.result.cache
1916
.phpunit.cache

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"require": {
1818
"php": "^8.3",
19-
"laravel/framework": "^11.34",
19+
"laravel/framework": ">=11.34",
2020
"phpunit/phpunit": "^11.4",
2121
"ext-json": "*"
2222
},

composer.lock

Lines changed: 412 additions & 245 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/auto-doc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
|--------------------------------------------------------------------------
122122
|
123123
| Tool for rendering API documentation in HTML format.
124-
| Available values: "swagger", "elements", "rapidoc"
124+
| Available values: "swagger", "elements", "rapidoc", "scalar"
125125
*/
126126
'documentation_viewer' => env('SWAGGER_SPEC_VIEWER', 'swagger'),
127127

resources/assets/scalar/scalar-min.js

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Scalar</title>
5+
<meta charset="utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
</head>
8+
9+
<body>
10+
<script
11+
id="api-reference"
12+
data-url="{{ config('auto-doc.global_prefix') }}/auto-doc/documentation"
13+
data-proxy-url="https://proxy.scalar.com"></script>
14+
15+
<script src="{{ config('auto-doc.global_prefix') }}/auto-doc/scalar-min.js"></script>
16+
</body>
17+
</html>

src/Services/SwaggerService.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Http\Request;
77
use Illuminate\Http\Testing\File;
88
use Illuminate\Support\Arr;
9+
use Illuminate\Support\Facades\URL;
910
use Illuminate\Support\Str;
1011
use ReflectionClass;
1112
use RonasIT\AutoDoc\Exceptions\DocFileNotExistsException;
@@ -140,7 +141,7 @@ protected function generateEmptyData(): array
140141
$data = [
141142
'openapi' => self::OPEN_API_VERSION,
142143
'servers' => [
143-
['url' => $this->getAppUrl() . $this->config['basePath']],
144+
['url' => URL::query($this->config['basePath'])],
144145
],
145146
'paths' => [],
146147
'components' => [
@@ -158,13 +159,6 @@ protected function generateEmptyData(): array
158159
return $data;
159160
}
160161

161-
protected function getAppUrl(): string
162-
{
163-
$url = config('app.url');
164-
165-
return str_replace(['http://', 'https://', '/'], '', $url);
166-
}
167-
168162
protected function generateSecurityDefinition(): ?array
169163
{
170164
if (empty($this->security)) {
@@ -672,11 +666,17 @@ public function saveConsume()
672666

673667
public function saveTags()
674668
{
675-
$tagIndex = 1;
669+
$globalPrefix = config('auto-doc.global_prefix');
670+
$globalPrefix = Str::after($globalPrefix, '/');
676671

677672
$explodedUri = explode('/', $this->uri);
673+
$explodedUri = array_filter($explodedUri);
674+
675+
$tag = array_shift($explodedUri);
678676

679-
$tag = Arr::get($explodedUri, $tagIndex);
677+
if ($globalPrefix === $tag) {
678+
$tag = array_shift($explodedUri);
679+
}
680680

681681
$this->item['tags'] = [$tag];
682682
}

src/Validators/SwaggerSpecValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected function validatePaths(): void
137137
$this->validateParameters($operation, $path, $operationId);
138138

139139
if (!empty($operation['requestBody'])) {
140-
$this->validateRequestBody($operation, $path, $operationId);
140+
$this->validateRequestBody($operation, $operationId);
141141
}
142142

143143
foreach ($operation['responses'] as $statusCode => $response) {
@@ -242,7 +242,7 @@ protected function validateParameters(array $operation, string $path, string $op
242242
$this->validateBodyParameters($parameters, $operationId);
243243
}
244244

245-
protected function validateRequestBody(array $operation, string $path, string $operationId): void
245+
protected function validateRequestBody(array $operation, string $operationId): void
246246
{
247247
$requestBody = Arr::get($operation, 'requestBody', []);
248248

tests/AutoDocControllerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,20 @@ public function testGetViewRapidocDocumentation()
152152
$this->assertEqualsFixture('rendered_rapidoc_documentation.html', $response->getContent());
153153
}
154154

155+
public function testGetViewScalarDocumentation()
156+
{
157+
config([
158+
'auto-doc.display_environments' => ['testing'],
159+
'auto-doc.documentation_viewer' => 'scalar',
160+
]);
161+
162+
$response = $this->get('/');
163+
164+
$response->assertOk();
165+
166+
$this->assertEqualsFixture('rendered_scalar_documentation.html', $response->getContent());
167+
}
168+
155169
public function testGetViewDocumentationEnvironmentDisable()
156170
{
157171
$response = $this->get('/');

0 commit comments

Comments
 (0)