@@ -33,9 +33,18 @@ public function openApi(array $docs): LaravelRequestDocsToOpenApi
33
33
private function docsToOpenApi (array $ docs ): void
34
34
{
35
35
$ this ->openApi ['paths ' ] = [];
36
+ $ deleteWithBody = config ('request-docs.open_api.delete_with_body ' , false );
37
+ $ excludeHttpMethods = array_map (fn ($ item ) => strtolower ($ item ), config ('request-docs.open_api.exclude_http_methods ' , []));
38
+
36
39
foreach ($ docs as $ doc ) {
37
- $ requestHasFile = false ;
40
+
38
41
$ httpMethod = strtolower ($ doc ->getHttpMethod ());
42
+
43
+ if (in_array ($ httpMethod , $ excludeHttpMethods )) {
44
+ continue ;
45
+ }
46
+
47
+ $ requestHasFile = false ;
39
48
$ isGet = $ httpMethod == 'get ' ;
40
49
$ isPost = $ httpMethod == 'post ' ;
41
50
$ isPut = $ httpMethod == 'put ' ;
@@ -46,7 +55,7 @@ private function docsToOpenApi(array $docs): void
46
55
$ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['parameters ' ] = [];
47
56
48
57
foreach ($ doc ->getPathParameters () as $ parameter => $ rule ) {
49
- $ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['parameters ' ][] = $ this ->makeQueryParameterItem ($ parameter , $ rule );
58
+ $ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['parameters ' ][] = $ this ->makePathParameterItem ($ parameter , $ rule );
50
59
}
51
60
52
61
$ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['responses ' ] = config ('request-docs.open_api.responses ' , []);
@@ -65,7 +74,7 @@ private function docsToOpenApi(array $docs): void
65
74
66
75
$ contentType = $ requestHasFile ? 'multipart/form-data ' : 'application/json ' ;
67
76
68
- if ($ isPost || $ isPut || $ isDelete ) {
77
+ if ($ isPost || $ isPut || ( $ isDelete && $ deleteWithBody ) ) {
69
78
$ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['requestBody ' ] = $ this ->makeRequestBodyItem ($ contentType );
70
79
}
71
80
@@ -75,7 +84,7 @@ private function docsToOpenApi(array $docs): void
75
84
$ parameter = $ this ->makeQueryParameterItem ($ attribute , $ rule );
76
85
$ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['parameters ' ][] = $ parameter ;
77
86
}
78
- if ($ isPost || $ isPut || $ isDelete ) {
87
+ if ($ isPost || $ isPut || ( $ isDelete && $ deleteWithBody ) ) {
79
88
$ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['requestBody ' ]['content ' ][$ contentType ]['schema ' ]['properties ' ][$ attribute ] = $ this ->makeRequestBodyContentPropertyItem ($ rule );
80
89
}
81
90
}
@@ -106,6 +115,25 @@ protected function makeQueryParameterItem(string $attribute, $rule): array
106
115
return $ parameter ;
107
116
}
108
117
118
+ protected function makePathParameterItem (string $ attribute , $ rule ): array
119
+ {
120
+ if (is_array ($ rule )) {
121
+ $ rule = implode ('| ' , $ rule );
122
+ }
123
+
124
+ $ parameter = [
125
+ 'name ' => $ attribute ,
126
+ 'description ' => $ rule ,
127
+ 'in ' => 'path ' ,
128
+ 'style ' => 'simple ' ,
129
+ 'required ' => str_contains ($ rule , 'required ' ),
130
+ 'schema ' => [
131
+ 'type ' => $ this ->getAttributeType ($ rule ),
132
+ ],
133
+ ];
134
+ return $ parameter ;
135
+ }
136
+
109
137
protected function makeRequestBodyItem (string $ contentType ): array
110
138
{
111
139
$ requestBody = [
0 commit comments