File tree Expand file tree Collapse file tree 3 files changed +81
-3
lines changed Expand file tree Collapse file tree 3 files changed +81
-3
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
3
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
+
4
15
'title ' => env ('APP_NAME ' ),
16
+
5
17
'description ' => '' ,
18
+
6
19
'appVersion ' => '1.0.0 ' ,
20
+
7
21
'host ' => env ('APP_URL ' ),
22
+
8
23
'basePath ' => '/ ' ,
24
+
25
+ 'schemes ' => [
26
+ // 'http',
27
+ // 'https',
28
+ ],
29
+
30
+ 'consumes ' => [
31
+ // 'application/json',
32
+ ],
33
+
34
+ 'produces ' => [
35
+ // 'application/json',
36
+ ],
9
37
];
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ public function generate()
52
52
53
53
protected function getBaseInfo ()
54
54
{
55
- return [
55
+ $ baseInfo = [
56
56
'swagger ' => '2.0 ' ,
57
57
'info ' => [
58
58
'title ' => $ this ->config ['title ' ],
@@ -61,8 +61,23 @@ protected function getBaseInfo()
61
61
],
62
62
'host ' => $ this ->config ['host ' ],
63
63
'basePath ' => $ this ->config ['basePath ' ],
64
- 'paths ' => [],
65
64
];
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 ;
66
81
}
67
82
68
83
protected function getAppRoutes ()
Original file line number Diff line number Diff line change 6
6
7
7
class GeneratorTest extends TestCase
8
8
{
9
+ protected $ config ;
10
+
9
11
protected $ generator ;
10
12
11
13
public function setUp ()
12
14
{
13
15
parent ::setUp ();
14
16
15
- $ this ->generator = new Generator (config ('laravel-swagger ' ));
17
+ $ this ->generator = new Generator (
18
+ $ this ->config = config ('laravel-swagger ' )
19
+ );
16
20
}
17
21
18
22
public function testBaseInfo ()
@@ -60,4 +64,35 @@ public function testPathData($paths)
60
64
$ this ->assertArrayHasKey ('responses ' , $ paths ['/users ' ]['post ' ]);
61
65
$ this ->assertArrayHasKey ('parameters ' , $ paths ['/users ' ]['post ' ]);
62
66
}
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
+ }
63
98
}
You can’t perform that action at this time.
0 commit comments