Skip to content

Commit 7ccce68

Browse files
committed
exclude http methods from openapi export condition added
1 parent 923fbf3 commit 7ccce68

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

config/request-docs.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
//openapi 3.0.x doesn't support request body for develop operation
7070
//ref: https://github.com/OAI/OpenAPI-Specification/pull/2117
7171
'include_body_on_delete' => false,
72+
//exclude http methods that will be excluded from openapi export
73+
'exclude_http_methods' => [],
7274
// for now putting default responses for all. This can be changed later based on specific needs
7375
'responses' => [
7476
'200' => [

src/LaravelRequestDocsToOpenApi.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,18 @@ public function openApi(array $docs): LaravelRequestDocsToOpenApi
3333
private function docsToOpenApi(array $docs): void
3434
{
3535
$this->openApi['paths'] = [];
36-
$includeBodyForDelete = config('request-docs.open_api.include_body_on_delete');
36+
$includeBodyForDelete = config('request-docs.open_api.include_body_on_delete', false);
37+
$excludeHttpMethods = array_map(fn ($item) => strtolower($item), config('request-docs.open_api.exclude_http_methods', []));
38+
3739
foreach ($docs as $doc) {
38-
$requestHasFile = false;
40+
3941
$httpMethod = strtolower($doc->getHttpMethod());
42+
43+
if (in_array($httpMethod, $excludeHttpMethods)) {
44+
continue;
45+
}
46+
47+
$requestHasFile = false;
4048
$isGet = $httpMethod == 'get';
4149
$isPost = $httpMethod == 'post';
4250
$isPut = $httpMethod == 'put';

0 commit comments

Comments
 (0)