@@ -33,9 +33,18 @@ public function openApi(array $docs): LaravelRequestDocsToOpenApi
3333 private function docsToOpenApi (array $ docs ): void
3434 {
3535 $ 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+
3639 foreach ($ docs as $ doc ) {
37- $ requestHasFile = false ;
40+
3841 $ httpMethod = strtolower ($ doc ->getHttpMethod ());
42+
43+ if (in_array ($ httpMethod , $ excludeHttpMethods )) {
44+ continue ;
45+ }
46+
47+ $ requestHasFile = false ;
3948 $ isGet = $ httpMethod == 'get ' ;
4049 $ isPost = $ httpMethod == 'post ' ;
4150 $ isPut = $ httpMethod == 'put ' ;
@@ -46,7 +55,7 @@ private function docsToOpenApi(array $docs): void
4655 $ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['parameters ' ] = [];
4756
4857 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 );
5059 }
5160
5261 $ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['responses ' ] = config ('request-docs.open_api.responses ' , []);
@@ -65,7 +74,7 @@ private function docsToOpenApi(array $docs): void
6574
6675 $ contentType = $ requestHasFile ? 'multipart/form-data ' : 'application/json ' ;
6776
68- if ($ isPost || $ isPut || $ isDelete ) {
77+ if ($ isPost || $ isPut || ( $ isDelete && $ deleteWithBody ) ) {
6978 $ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['requestBody ' ] = $ this ->makeRequestBodyItem ($ contentType );
7079 }
7180
@@ -75,7 +84,7 @@ private function docsToOpenApi(array $docs): void
7584 $ parameter = $ this ->makeQueryParameterItem ($ attribute , $ rule );
7685 $ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['parameters ' ][] = $ parameter ;
7786 }
78- if ($ isPost || $ isPut || $ isDelete ) {
87+ if ($ isPost || $ isPut || ( $ isDelete && $ deleteWithBody ) ) {
7988 $ this ->openApi ['paths ' ][$ uriLeadingSlash ][$ httpMethod ]['requestBody ' ]['content ' ][$ contentType ]['schema ' ]['properties ' ][$ attribute ] = $ this ->makeRequestBodyContentPropertyItem ($ rule );
8089 }
8190 }
@@ -106,6 +115,25 @@ protected function makeQueryParameterItem(string $attribute, $rule): array
106115 return $ parameter ;
107116 }
108117
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+
109137 protected function makeRequestBodyItem (string $ contentType ): array
110138 {
111139 $ requestBody = [
0 commit comments