diff --git a/CHANGELOG.md b/CHANGELOG.md index 034e545..f3d2a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip ## [Unreleased][unreleased] ### Changed +* Update Request body schema in OpenApiHandler * Set null value when process empty file params, instead of false diff --git a/src/Handlers/OpenApiHandler.php b/src/Handlers/OpenApiHandler.php index bd81d4e..2cd69d8 100644 --- a/src/Handlers/OpenApiHandler.php +++ b/src/Handlers/OpenApiHandler.php @@ -484,6 +484,7 @@ private function createRequestBody(ApiHandlerInterface $handler) ]; $filesInBody = false; $requestBodyExample = []; + $result = []; foreach ($handler->params() as $param) { if ($param instanceof JsonInputParam) { $schema = json_decode($param->getSchema(), true); @@ -496,14 +497,11 @@ private function createRequestBody(ApiHandlerInterface $handler) } } } - return [ - 'description' => $param->getDescription(), - 'required' => $param->isRequired(), - 'content' => [ - 'application/json' => [ - 'schema' => $this->transformSchema($schema), - ], - ], + + $result['description'] = $param->getDescription(); + $result['required'] = $param->isRequired(); + $result['content']['application/json'] = [ + 'schema' => $this->transformSchema($schema), ]; } if ($param instanceof RawInputParam) { @@ -517,14 +515,10 @@ private function createRequestBody(ApiHandlerInterface $handler) $schema['examples'] = $examples; } } - return [ - 'description' => $param->getDescription(), - 'required' => $param->isRequired(), - 'content' => [ - 'text/plain' => [ - 'schema' => $schema, - ], - ], + $result['description'] = $result['description'] ?? $param->getDescription(); + $result['required'] = $result['required'] ?? $param->isRequired(); + $result['content']['text/plain'] = [ + 'schema' => $schema, ]; } if ($param->getType() === InputParam::TYPE_POST || $param->getType() === InputParam::TYPE_PUT) { @@ -594,17 +588,14 @@ private function createRequestBody(ApiHandlerInterface $handler) } $contentType = $filesInBody ? 'multipart/form-data' : 'application/x-www-form-urlencoded'; - return [ - 'required' => true, - 'content' => [ - $contentType => [ - 'schema' => $requestBodySchema, - ], - ], + + $result['required'] = true; + $result['content'][$contentType] = [ + 'schema' => $requestBodySchema, ]; } - return null; + return $result ?: null; } private function createIn($type)