@@ -7,7 +7,7 @@ class LaravelRequestDocsToOpenApi
7
7
private array $ openApi = [];
8
8
9
9
/**
10
- * @param \Rakutentech\LaravelRequestDocs\Doc[] $docs
10
+ * @param \Rakutentech\LaravelRequestDocs\Doc[] $docs
11
11
* @return $this
12
12
*/
13
13
public function openApi (array $ docs ): LaravelRequestDocsToOpenApi
@@ -28,14 +28,14 @@ public function openApi(array $docs): LaravelRequestDocsToOpenApi
28
28
}
29
29
30
30
/**
31
- * @param \Rakutentech\LaravelRequestDocs\Doc[] $docs
31
+ * @param \Rakutentech\LaravelRequestDocs\Doc[] $docs
32
32
* @return void
33
33
*/
34
34
private function docsToOpenApi (array $ docs ): void
35
35
{
36
36
$ this ->openApi ['paths ' ] = [];
37
37
$ deleteWithBody = config ('request-docs.open_api.delete_with_body ' , false );
38
- $ excludeHttpMethods = array_map (fn ($ item ) => strtolower ($ item ), config ('request-docs.open_api.exclude_http_methods ' , []));
38
+ $ excludeHttpMethods = array_map (fn ($ item ) => strtolower ($ item ), config ('request-docs.open_api.exclude_http_methods ' , []));
39
39
40
40
foreach ($ docs as $ doc ) {
41
41
$ httpMethod = strtolower ($ doc ->getHttpMethod ());
@@ -91,6 +91,7 @@ private function docsToOpenApi(array $docs): void
91
91
}
92
92
}
93
93
}
94
+
94
95
protected function setAndFilterResponses (Doc $ doc ): array
95
96
{
96
97
$ docResponses = $ doc ->getResponses ();
@@ -116,12 +117,12 @@ protected function makeQueryParameterItem(string $attribute, $rule): array
116
117
$ rule = implode ('| ' , $ rule );
117
118
}
118
119
$ parameter = [
119
- 'name ' => $ attribute ,
120
+ 'name ' => $ attribute ,
120
121
'description ' => $ rule ,
121
- 'in ' => 'query ' ,
122
- 'style ' => 'form ' ,
123
- 'required ' => str_contains ($ rule , 'required ' ),
124
- 'schema ' => [
122
+ 'in ' => 'query ' ,
123
+ 'style ' => 'form ' ,
124
+ 'required ' => str_contains ($ rule , 'required ' ),
125
+ 'schema ' => [
125
126
'type ' => $ this ->getAttributeType ($ rule ),
126
127
],
127
128
];
@@ -135,12 +136,12 @@ protected function makePathParameterItem(string $attribute, $rule): array
135
136
}
136
137
137
138
$ parameter = [
138
- 'name ' => $ attribute ,
139
+ 'name ' => $ attribute ,
139
140
'description ' => $ rule ,
140
- 'in ' => 'path ' ,
141
- 'style ' => 'simple ' ,
142
- 'required ' => str_contains ($ rule , 'required ' ),
143
- 'schema ' => [
141
+ 'in ' => 'path ' ,
142
+ 'style ' => 'simple ' ,
143
+ 'required ' => str_contains ($ rule , 'required ' ),
144
+ 'schema ' => [
144
145
'type ' => $ this ->getAttributeType ($ rule ),
145
146
],
146
147
];
@@ -151,10 +152,10 @@ protected function makeRequestBodyItem(string $contentType): array
151
152
{
152
153
$ requestBody = [
153
154
'description ' => "Request body " ,
154
- 'content ' => [
155
+ 'content ' => [
155
156
$ contentType => [
156
157
'schema ' => [
157
- 'type ' => 'object ' ,
158
+ 'type ' => 'object ' ,
158
159
'properties ' => [],
159
160
],
160
161
],
@@ -168,9 +169,9 @@ protected function makeRequestBodyContentPropertyItem(string $rule): array
168
169
$ type = $ this ->getAttributeType ($ rule );
169
170
170
171
return [
171
- 'type ' => $ type ,
172
+ 'type ' => $ type ,
172
173
'nullable ' => str_contains ($ rule , 'nullable ' ),
173
- 'format ' => $ this ->attributeIsFile ($ rule ) ? 'binary ' : $ type ,
174
+ 'format ' => $ this ->attributeIsFile ($ rule ) ? 'binary ' : $ type ,
174
175
];
175
176
}
176
177
@@ -203,6 +204,7 @@ protected function appendGlobalSecurityScheme(): void
203
204
case 'bearer ' :
204
205
$ this ->openApi ['components ' ]['securitySchemes ' ]['bearerAuth ' ] = [
205
206
'type ' => 'http ' ,
207
+ 'name ' => config ('request-docs.open_api.security.name ' , 'Bearer Authorization Token ' ),
206
208
'scheme ' => 'bearer '
207
209
];
208
210
$ this ->openApi ['security ' ][] = [
@@ -213,6 +215,7 @@ protected function appendGlobalSecurityScheme(): void
213
215
case 'basic ' :
214
216
$ this ->openApi ['components ' ]['securitySchemes ' ]['basicAuth ' ] = [
215
217
'type ' => 'http ' ,
218
+ 'name ' => config ('request-docs.open_api.security.name ' , 'Basic Authorization Username and Password ' ),
216
219
'scheme ' => 'basic '
217
220
];
218
221
$ this ->openApi ['security ' ][] = [
@@ -223,16 +226,30 @@ protected function appendGlobalSecurityScheme(): void
223
226
case 'apikey ' :
224
227
$ this ->openApi ['components ' ]['securitySchemes ' ]['apiKeyAuth ' ] = [
225
228
'type ' => 'apiKey ' ,
226
- 'name ' => config ('request-docs.open_api.security.key_name ' , 'api_key ' ),
229
+ 'name ' => config ('request-docs.open_api.security.name ' , 'api_key ' ),
227
230
'in ' => config ('request-docs.open_api.security.position ' , 'header ' )
228
231
];
229
232
$ this ->openApi ['security ' ][] = ['apiKeyAuth ' => []];
230
233
break ;
231
234
235
+ case 'jwt ' :
236
+ $ this ->openApi ['components ' ]['securitySchemes ' ]['bearerAuth ' ] = [
237
+ 'type ' => 'http ' ,
238
+ 'scheme ' => 'bearer ' ,
239
+ 'name ' => config ('request-docs.open_api.security.name ' , 'Bearer Authorization Token ' ),
240
+ 'in ' => config ('request-docs.open_api.security.position ' , 'header ' ),
241
+ 'bearerFormat ' => 'JWT '
242
+ ];
243
+ $ this ->openApi ['security ' ][] = [
244
+ 'bearerAuth ' => []
245
+ ];
246
+ break ;
247
+
232
248
default :
233
249
break ;
234
250
}
235
251
}
252
+
236
253
/**
237
254
* @codeCoverageIgnore
238
255
*/
0 commit comments