Skip to content

Commit 7c65eb8

Browse files
KavajNarujJuraj Vanak
andauthored
Update OpenApiHandler.php (#160)
Co-authored-by: Juraj Vanak <juraj@vanak.sk>
1 parent 053cf73 commit 7c65eb8

2 files changed

Lines changed: 16 additions & 24 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
44

55
## [Unreleased][unreleased]
66
### Changed
7+
* Update Request body schema in OpenApiHandler
78
* Set null value when process empty file params, instead of false
89

910

src/Handlers/OpenApiHandler.php

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ private function createRequestBody(ApiHandlerInterface $handler)
484484
];
485485
$filesInBody = false;
486486
$requestBodyExample = [];
487+
$result = [];
487488
foreach ($handler->params() as $param) {
488489
if ($param instanceof JsonInputParam) {
489490
$schema = json_decode($param->getSchema(), true);
@@ -496,14 +497,11 @@ private function createRequestBody(ApiHandlerInterface $handler)
496497
}
497498
}
498499
}
499-
return [
500-
'description' => $param->getDescription(),
501-
'required' => $param->isRequired(),
502-
'content' => [
503-
'application/json' => [
504-
'schema' => $this->transformSchema($schema),
505-
],
506-
],
500+
501+
$result['description'] = $param->getDescription();
502+
$result['required'] = $param->isRequired();
503+
$result['content']['application/json'] = [
504+
'schema' => $this->transformSchema($schema),
507505
];
508506
}
509507
if ($param instanceof RawInputParam) {
@@ -517,14 +515,10 @@ private function createRequestBody(ApiHandlerInterface $handler)
517515
$schema['examples'] = $examples;
518516
}
519517
}
520-
return [
521-
'description' => $param->getDescription(),
522-
'required' => $param->isRequired(),
523-
'content' => [
524-
'text/plain' => [
525-
'schema' => $schema,
526-
],
527-
],
518+
$result['description'] = $result['description'] ?? $param->getDescription();
519+
$result['required'] = $result['required'] ?? $param->isRequired();
520+
$result['content']['text/plain'] = [
521+
'schema' => $schema,
528522
];
529523
}
530524
if ($param->getType() === InputParam::TYPE_POST || $param->getType() === InputParam::TYPE_PUT) {
@@ -594,17 +588,14 @@ private function createRequestBody(ApiHandlerInterface $handler)
594588
}
595589

596590
$contentType = $filesInBody ? 'multipart/form-data' : 'application/x-www-form-urlencoded';
597-
return [
598-
'required' => true,
599-
'content' => [
600-
$contentType => [
601-
'schema' => $requestBodySchema,
602-
],
603-
],
591+
592+
$result['required'] = true;
593+
$result['content'][$contentType] = [
594+
'schema' => $requestBodySchema,
604595
];
605596
}
606597

607-
return null;
598+
return $result ?: null;
608599
}
609600

610601
private function createIn($type)

0 commit comments

Comments
 (0)