From d4d151c87be3c57469f9c7e7d9d5703ca2d74f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20Benja=C4=8D?= Date: Thu, 11 Jan 2018 13:45:56 +0100 Subject: [PATCH] Support extended request param & request body --- composer.json | 2 +- src/OpenApiService.php | 41 ++++++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/composer.json b/composer.json index 41f91c0..adab379 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ ], "require": { "php": ">= 5.6", - "apitte/core": "~0.1.0", + "apitte/core": "~0.1.1", "tracy/tracy": "~2.4.9", "nette/di": "~2.4.10" }, diff --git a/src/OpenApiService.php b/src/OpenApiService.php index a4c49e2..742a521 100644 --- a/src/OpenApiService.php +++ b/src/OpenApiService.php @@ -51,19 +51,19 @@ public function createSchema() $mediaType = new MediaType(); $body = new Schema([ 'type' => 'object', - 'required' => [ - 'name', - ], - 'properties' => (object) [ - 'name' => (object) [ - 'type' => 'string', - ], - 'age' => (object) [ - 'type' => 'integer', - 'format' => 'int32', - 'minimum' => 0, - ], - ], + // 'required' => [ + // 'name', + // ], + // 'properties' => (object) [ + // 'name' => (object) [ + // 'type' => 'string', + // ], + // 'age' => (object) [ + // 'type' => 'integer', + // 'format' => 'int32', + // 'minimum' => 0, + // ], + // ], ]); $mediaType->setSchema($body); @@ -105,19 +105,22 @@ public function createSchema() //Parameters foreach ($endpoint->getParameters() as $endpointParam) { - $param = new Parameter($endpointParam->getName(), Parameter::IN_QUERY); + $param = new Parameter($endpointParam->getName(), $endpointParam->getIn()); $param->setDescription($endpointParam->getDescription()); - //$param->setRequired(TRUE); //TODO - //$param->setAllowEmptyValue(FALSE); //TODO - //$param->setDeprecated(FALSE); //TODO + $param->setRequired($endpointParam->isRequired()); + $param->setAllowEmptyValue($endpointParam->isAllowEmpty()); + $param->setDeprecated($endpointParam->isDeprecated()); $param->setSchema(new Schema([ 'type' => 'integer', 'format' => 'int32', ])); $operation->setParameter($param); } - //$operation->setRequestBody($requestBody); - $pathItem->setOperation(strtolower($method), $operation); + $method = strtolower($method); + if ($method === PathItem::OPERATION_PUT || $method === PathItem::OPERATION_POST || $method === PathItem::OPERATION_PATCH) { + $operation->setRequestBody($requestBody); + } + $pathItem->setOperation($method, $operation); } $paths->setPathItem($endpoint->getMask(), $pathItem); }