Skip to content

Commit eff5fa0

Browse files
committed
openapi3 delete method exclude request body configuration added
1 parent 094d0f3 commit eff5fa0

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

config/request-docs.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@
6666
'license' => 'Apache 2.0',
6767
'license_url' => 'https://www.apache.org/licenses/LICENSE-2.0.html',
6868
'server_url' => env('APP_URL', 'http://localhost'),
69-
69+
//openapi 3.0.x doesn't support request body for develop operation
70+
//ref: https://github.com/OAI/OpenAPI-Specification/pull/2117
71+
'include_body_on_delete' => false,
7072
// for now putting default responses for all. This can be changed later based on specific needs
7173
'responses' => [
7274
'200' => [

src/LaravelRequestDocsToOpenApi.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function openApi(array $docs): LaravelRequestDocsToOpenApi
3333
private function docsToOpenApi(array $docs): void
3434
{
3535
$this->openApi['paths'] = [];
36-
// dd($docs);
36+
$includeBodyForDelete = config('request-docs.open_api.include_body_on_delete');
3737
foreach ($docs as $doc) {
3838
$requestHasFile = false;
3939
$httpMethod = strtolower($doc->getHttpMethod());
@@ -66,7 +66,7 @@ private function docsToOpenApi(array $docs): void
6666

6767
$contentType = $requestHasFile ? 'multipart/form-data' : 'application/json';
6868

69-
if ($isPost || $isPut || $isDelete) {
69+
if ($isPost || $isPut || ($isDelete && $includeBodyForDelete)) {
7070
$this->openApi['paths'][$uriLeadingSlash][$httpMethod]['requestBody'] = $this->makeRequestBodyItem($contentType);
7171
}
7272

@@ -76,7 +76,7 @@ private function docsToOpenApi(array $docs): void
7676
$parameter = $this->makeQueryParameterItem($attribute, $rule);
7777
$this->openApi['paths'][$uriLeadingSlash][$httpMethod]['parameters'][] = $parameter;
7878
}
79-
if ($isPost || $isPut || $isDelete) {
79+
if ($isPost || $isPut || ($isDelete && $includeBodyForDelete)) {
8080
$this->openApi['paths'][$uriLeadingSlash][$httpMethod]['requestBody']['content'][$contentType]['schema']['properties'][$attribute] = $this->makeRequestBodyContentPropertyItem($rule);
8181
}
8282
}

0 commit comments

Comments
 (0)