Skip to content

Commit e9d2730

Browse files
committed
added more config options, better config structure
1 parent 8d927cb commit e9d2730

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

config/laravel-swagger.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
11
<?php
22

33
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Basic Info
8+
|--------------------------------------------------------------------------
9+
|
10+
| The basic info for the application such as the title description,
11+
| description, version, etc...
12+
|
13+
*/
14+
415
'title' => env('APP_NAME'),
16+
517
'description' => '',
18+
619
'appVersion' => '1.0.0',
20+
721
'host' => env('APP_URL'),
22+
823
'basePath' => '/',
24+
25+
'schemes' => [
26+
// 'http',
27+
// 'https',
28+
],
29+
30+
'consumes' => [
31+
// 'application/json',
32+
],
33+
34+
'produces' => [
35+
// 'application/json',
36+
],
937
];

src/Generator.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function generate()
5252

5353
protected function getBaseInfo()
5454
{
55-
return [
55+
$baseInfo = [
5656
'swagger' => '2.0',
5757
'info' => [
5858
'title' => $this->config['title'],
@@ -61,8 +61,23 @@ protected function getBaseInfo()
6161
],
6262
'host' => $this->config['host'],
6363
'basePath' => $this->config['basePath'],
64-
'paths' => [],
6564
];
65+
66+
if (!empty($this->config['schemes'])) {
67+
$baseInfo['schemes'] = $this->config['schemes'];
68+
}
69+
70+
if (!empty($this->config['consumes'])) {
71+
$baseInfo['consumes'] = $this->config['consumes'];
72+
}
73+
74+
if (!empty($this->config['produces'])) {
75+
$baseInfo['produces'] = $this->config['produces'];
76+
}
77+
78+
$baseInfo['paths'] = [];
79+
80+
return $baseInfo;
6681
}
6782

6883
protected function getAppRoutes()

tests/GeneratorTest.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66

77
class GeneratorTest extends TestCase
88
{
9+
protected $config;
10+
911
protected $generator;
1012

1113
public function setUp()
1214
{
1315
parent::setUp();
1416

15-
$this->generator = new Generator(config('laravel-swagger'));
17+
$this->generator = new Generator(
18+
$this->config = config('laravel-swagger')
19+
);
1620
}
1721

1822
public function testBaseInfo()
@@ -60,4 +64,35 @@ public function testPathData($paths)
6064
$this->assertArrayHasKey('responses', $paths['/users']['post']);
6165
$this->assertArrayHasKey('parameters', $paths['/users']['post']);
6266
}
67+
68+
public function testOptionalData()
69+
{
70+
$optionalData = [
71+
'schemes' => [
72+
'http',
73+
'https',
74+
],
75+
76+
'consumes' => [
77+
'application/json',
78+
],
79+
80+
'produces' => [
81+
'application/json',
82+
],
83+
];
84+
85+
$config = array_merge($this->config, $optionalData);
86+
87+
$docs = (new Generator($config))->generate();
88+
89+
$this->assertArrayHasKey('schemes', $docs);
90+
$this->assertArrayHasKey('consumes', $docs);
91+
$this->assertArrayHasKey('produces', $docs);
92+
93+
$this->assertContains('http', $docs['schemes']);
94+
$this->assertContains('https', $docs['schemes']);
95+
$this->assertContains('application/json', $docs['consumes']);
96+
$this->assertContains('application/json', $docs['produces']);
97+
}
6398
}

0 commit comments

Comments
 (0)