From 1e7b540e798e0ca9f0cc69a79f712c0931d98999 Mon Sep 17 00:00:00 2001 From: Yuriy Belenko Date: Thu, 4 Jun 2020 13:15:58 +0300 Subject: [PATCH 1/2] Use HttpNotImplementedException from Slim Specialized HttpNotImplementedException from Slim makes possible to distinguish general exceptions from case when implementation isn't complete. This update doesn't change API call results. --- .../resources/php-slim4-server/SlimRouter.mustache | 14 +++++++------- .../main/resources/php-slim4-server/api.mustache | 9 +++------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php-slim4-server/SlimRouter.mustache b/modules/openapi-generator/src/main/resources/php-slim4-server/SlimRouter.mustache index d67b154d06d8..7b077c8dd766 100644 --- a/modules/openapi-generator/src/main/resources/php-slim4-server/SlimRouter.mustache +++ b/modules/openapi-generator/src/main/resources/php-slim4-server/SlimRouter.mustache @@ -35,6 +35,7 @@ namespace {{invokerPackage}}; use Slim\Factory\AppFactory; use Slim\Interfaces\RouteInterface; +use Slim\Exception\HttpNotImplementedException; use Psr\Container\ContainerInterface; use InvalidArgumentException; use Dyorg\TokenAuthentication; @@ -143,7 +144,8 @@ class SlimRouter * * @param ContainerInterface|array $settings Either a ContainerInterface or an associative array of app settings * - * @throws Exception When implementation class doesn't exists + * @throws HttpNotImplementedException When implementation class doesn't exists + * @throws Exception when not supported authorization schema type provided */ public function __construct($settings = []) { @@ -160,15 +162,15 @@ class SlimRouter $authPackage = '{{authPackage}}'; $basicAuthenticator = function (ServerRequestInterface &$request, TokenSearch $tokenSearch) use ($authPackage) { $message = "How about extending {{abstractNamePrefix}}Authenticator{{abstractNameSuffix}} class by {$authPackage}\BasicAuthenticator?"; - throw new Exception($message); + throw new HttpNotImplementedException($request, $message); }; $apiKeyAuthenticator = function (ServerRequestInterface &$request, TokenSearch $tokenSearch) use ($authPackage) { $message = "How about extending {{abstractNamePrefix}}Authenticator{{abstractNameSuffix}} class by {$authPackage}\ApiKeyAuthenticator?"; - throw new Exception($message); + throw new HttpNotImplementedException($request, $message); }; $oAuthAuthenticator = function (ServerRequestInterface &$request, TokenSearch $tokenSearch) use ($authPackage) { $message = "How about extending {{abstractNamePrefix}}Authenticator{{abstractNameSuffix}} class by {$authPackage}\OAuthAuthenticator?"; - throw new Exception($message); + throw new HttpNotImplementedException($request, $message); }; {{/hasAuthMethods}} @@ -183,9 +185,7 @@ class SlimRouter foreach ($this->operations as $operation) { $callback = function ($request, $response, $arguments) use ($operation) { $message = "How about extending {$operation['classname']} by {$operation['apiPackage']}\\{$operation['userClassname']} class implementing {$operation['operationId']} as a {$operation['httpMethod']} method?"; - throw new Exception($message); - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); }; $middlewares = [new JsonBodyParserMiddleware()]; diff --git a/modules/openapi-generator/src/main/resources/php-slim4-server/api.mustache b/modules/openapi-generator/src/main/resources/php-slim4-server/api.mustache index 1148da4ec0e9..ff90a276a008 100644 --- a/modules/openapi-generator/src/main/resources/php-slim4-server/api.mustache +++ b/modules/openapi-generator/src/main/resources/php-slim4-server/api.mustache @@ -37,7 +37,7 @@ namespace {{apiPackage}}; use Psr\Container\ContainerInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; -use Exception; +use Slim\Exception\HttpNotImplementedException; /** * {{classname}} Class Doc Comment @@ -84,7 +84,7 @@ abstract class {{classname}} * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function {{operationId}}(ServerRequestInterface $request, ResponseInterface $response, array $args) { @@ -125,10 +125,7 @@ abstract class {{classname}} $body = $request->getParsedBody(); {{/hasBodyParam}} $message = "How about implementing {{nickname}} as a {{httpMethod}} method in {{apiPackage}}\{{userClassname}} class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } {{/operation}} {{/operations}} From b1f3c63dafb068deb87f2f3c1237e048b680a876 Mon Sep 17 00:00:00 2001 From: Yuriy Belenko Date: Thu, 4 Jun 2020 13:47:03 +0300 Subject: [PATCH 2/2] Refresh samples --- .../lib/Api/AbstractAnotherFakeApi.php | 9 +- .../php-slim4/lib/Api/AbstractFakeApi.php | 100 +++++------------- .../Api/AbstractFakeClassnameTags123Api.php | 9 +- .../php-slim4/lib/Api/AbstractPetApi.php | 65 ++++-------- .../php-slim4/lib/Api/AbstractStoreApi.php | 30 ++---- .../php-slim4/lib/Api/AbstractUserApi.php | 58 +++------- .../petstore/php-slim4/lib/SlimRouter.php | 14 +-- 7 files changed, 87 insertions(+), 198 deletions(-) diff --git a/samples/server/petstore/php-slim4/lib/Api/AbstractAnotherFakeApi.php b/samples/server/petstore/php-slim4/lib/Api/AbstractAnotherFakeApi.php index 1473213d01e8..14cf312d692f 100644 --- a/samples/server/petstore/php-slim4/lib/Api/AbstractAnotherFakeApi.php +++ b/samples/server/petstore/php-slim4/lib/Api/AbstractAnotherFakeApi.php @@ -28,7 +28,7 @@ use Psr\Container\ContainerInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; -use Exception; +use Slim\Exception\HttpNotImplementedException; /** * AbstractAnotherFakeApi Class Doc Comment @@ -67,15 +67,12 @@ public function __construct(ContainerInterface $container = null) * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function call123TestSpecialTags(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing call123TestSpecialTags as a PATCH method in OpenAPIServer\Api\AnotherFakeApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } } diff --git a/samples/server/petstore/php-slim4/lib/Api/AbstractFakeApi.php b/samples/server/petstore/php-slim4/lib/Api/AbstractFakeApi.php index 6b3888966baa..a3887269f1fd 100644 --- a/samples/server/petstore/php-slim4/lib/Api/AbstractFakeApi.php +++ b/samples/server/petstore/php-slim4/lib/Api/AbstractFakeApi.php @@ -28,7 +28,7 @@ use Psr\Container\ContainerInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; -use Exception; +use Slim\Exception\HttpNotImplementedException; /** * AbstractFakeApi Class Doc Comment @@ -66,16 +66,13 @@ public function __construct(ContainerInterface $container = null) * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function createXmlItem(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing createXmlItem as a POST method in OpenAPIServer\Api\FakeApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -88,16 +85,13 @@ public function createXmlItem(ServerRequestInterface $request, ResponseInterface * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function fakeOuterBooleanSerialize(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing fakeOuterBooleanSerialize as a POST method in OpenAPIServer\Api\FakeApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -110,16 +104,13 @@ public function fakeOuterBooleanSerialize(ServerRequestInterface $request, Respo * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function fakeOuterCompositeSerialize(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing fakeOuterCompositeSerialize as a POST method in OpenAPIServer\Api\FakeApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -132,16 +123,13 @@ public function fakeOuterCompositeSerialize(ServerRequestInterface $request, Res * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function fakeOuterNumberSerialize(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing fakeOuterNumberSerialize as a POST method in OpenAPIServer\Api\FakeApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -154,16 +142,13 @@ public function fakeOuterNumberSerialize(ServerRequestInterface $request, Respon * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function fakeOuterStringSerialize(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing fakeOuterStringSerialize as a POST method in OpenAPIServer\Api\FakeApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -175,16 +160,13 @@ public function fakeOuterStringSerialize(ServerRequestInterface $request, Respon * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function testBodyWithFileSchema(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing testBodyWithFileSchema as a PUT method in OpenAPIServer\Api\FakeApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -195,7 +177,7 @@ public function testBodyWithFileSchema(ServerRequestInterface $request, Response * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function testBodyWithQueryParams(ServerRequestInterface $request, ResponseInterface $response, array $args) { @@ -203,10 +185,7 @@ public function testBodyWithQueryParams(ServerRequestInterface $request, Respons $query = (key_exists('query', $queryParams)) ? $queryParams['query'] : null; $body = $request->getParsedBody(); $message = "How about implementing testBodyWithQueryParams as a PUT method in OpenAPIServer\Api\FakeApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -220,16 +199,13 @@ public function testBodyWithQueryParams(ServerRequestInterface $request, Respons * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function testClientModel(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing testClientModel as a PATCH method in OpenAPIServer\Api\FakeApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -242,7 +218,7 @@ public function testClientModel(ServerRequestInterface $request, ResponseInterfa * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function testEndpointParameters(ServerRequestInterface $request, ResponseInterface $response, array $args) { @@ -262,10 +238,7 @@ public function testEndpointParameters(ServerRequestInterface $request, Response $password = (isset($body['password'])) ? $body['password'] : null; $callback = (isset($body['callback'])) ? $body['callback'] : null; $message = "How about implementing testEndpointParameters as a POST method in OpenAPIServer\Api\FakeApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -278,7 +251,7 @@ public function testEndpointParameters(ServerRequestInterface $request, Response * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function testEnumParameters(ServerRequestInterface $request, ResponseInterface $response, array $args) { @@ -294,10 +267,7 @@ public function testEnumParameters(ServerRequestInterface $request, ResponseInte $enumFormStringArray = (isset($body['enum_form_string_array'])) ? $body['enum_form_string_array'] : null; $enumFormString = (isset($body['enum_form_string'])) ? $body['enum_form_string'] : null; $message = "How about implementing testEnumParameters as a GET method in OpenAPIServer\Api\FakeApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -310,7 +280,7 @@ public function testEnumParameters(ServerRequestInterface $request, ResponseInte * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function testGroupParameters(ServerRequestInterface $request, ResponseInterface $response, array $args) { @@ -323,10 +293,7 @@ public function testGroupParameters(ServerRequestInterface $request, ResponseInt $stringGroup = (key_exists('string_group', $queryParams)) ? $queryParams['string_group'] : null; $int64Group = (key_exists('int64_group', $queryParams)) ? $queryParams['int64_group'] : null; $message = "How about implementing testGroupParameters as a DELETE method in OpenAPIServer\Api\FakeApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -338,16 +305,13 @@ public function testGroupParameters(ServerRequestInterface $request, ResponseInt * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function testInlineAdditionalProperties(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing testInlineAdditionalProperties as a POST method in OpenAPIServer\Api\FakeApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -359,7 +323,7 @@ public function testInlineAdditionalProperties(ServerRequestInterface $request, * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function testJsonFormData(ServerRequestInterface $request, ResponseInterface $response, array $args) { @@ -367,10 +331,7 @@ public function testJsonFormData(ServerRequestInterface $request, ResponseInterf $param = (isset($body['param'])) ? $body['param'] : null; $param2 = (isset($body['param2'])) ? $body['param2'] : null; $message = "How about implementing testJsonFormData as a GET method in OpenAPIServer\Api\FakeApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -382,7 +343,7 @@ public function testJsonFormData(ServerRequestInterface $request, ResponseInterf * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function testQueryParameterCollectionFormat(ServerRequestInterface $request, ResponseInterface $response, array $args) { @@ -393,9 +354,6 @@ public function testQueryParameterCollectionFormat(ServerRequestInterface $reque $url = (key_exists('url', $queryParams)) ? $queryParams['url'] : null; $context = (key_exists('context', $queryParams)) ? $queryParams['context'] : null; $message = "How about implementing testQueryParameterCollectionFormat as a PUT method in OpenAPIServer\Api\FakeApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } } diff --git a/samples/server/petstore/php-slim4/lib/Api/AbstractFakeClassnameTags123Api.php b/samples/server/petstore/php-slim4/lib/Api/AbstractFakeClassnameTags123Api.php index fb8a7b9db353..dbbfe05e0be0 100644 --- a/samples/server/petstore/php-slim4/lib/Api/AbstractFakeClassnameTags123Api.php +++ b/samples/server/petstore/php-slim4/lib/Api/AbstractFakeClassnameTags123Api.php @@ -28,7 +28,7 @@ use Psr\Container\ContainerInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; -use Exception; +use Slim\Exception\HttpNotImplementedException; /** * AbstractFakeClassnameTags123Api Class Doc Comment @@ -67,15 +67,12 @@ public function __construct(ContainerInterface $container = null) * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function testClassname(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing testClassname as a PATCH method in OpenAPIServer\Api\FakeClassnameTags123Api class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } } diff --git a/samples/server/petstore/php-slim4/lib/Api/AbstractPetApi.php b/samples/server/petstore/php-slim4/lib/Api/AbstractPetApi.php index 9c3121b5eca2..f1ec2d3cafc0 100644 --- a/samples/server/petstore/php-slim4/lib/Api/AbstractPetApi.php +++ b/samples/server/petstore/php-slim4/lib/Api/AbstractPetApi.php @@ -28,7 +28,7 @@ use Psr\Container\ContainerInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; -use Exception; +use Slim\Exception\HttpNotImplementedException; /** * AbstractPetApi Class Doc Comment @@ -65,16 +65,13 @@ public function __construct(ContainerInterface $container = null) * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function addPet(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing addPet as a POST method in OpenAPIServer\Api\PetApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -86,7 +83,7 @@ public function addPet(ServerRequestInterface $request, ResponseInterface $respo * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function deletePet(ServerRequestInterface $request, ResponseInterface $response, array $args) { @@ -94,10 +91,7 @@ public function deletePet(ServerRequestInterface $request, ResponseInterface $re $apiKey = $request->hasHeader('api_key') ? $headers['api_key'] : null; $petId = $args['petId']; $message = "How about implementing deletePet as a DELETE method in OpenAPIServer\Api\PetApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -111,17 +105,14 @@ public function deletePet(ServerRequestInterface $request, ResponseInterface $re * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function findPetsByStatus(ServerRequestInterface $request, ResponseInterface $response, array $args) { $queryParams = $request->getQueryParams(); $status = (key_exists('status', $queryParams)) ? $queryParams['status'] : null; $message = "How about implementing findPetsByStatus as a GET method in OpenAPIServer\Api\PetApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -135,17 +126,14 @@ public function findPetsByStatus(ServerRequestInterface $request, ResponseInterf * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function findPetsByTags(ServerRequestInterface $request, ResponseInterface $response, array $args) { $queryParams = $request->getQueryParams(); $tags = (key_exists('tags', $queryParams)) ? $queryParams['tags'] : null; $message = "How about implementing findPetsByTags as a GET method in OpenAPIServer\Api\PetApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -159,16 +147,13 @@ public function findPetsByTags(ServerRequestInterface $request, ResponseInterfac * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function getPetById(ServerRequestInterface $request, ResponseInterface $response, array $args) { $petId = $args['petId']; $message = "How about implementing getPetById as a GET method in OpenAPIServer\Api\PetApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -180,16 +165,13 @@ public function getPetById(ServerRequestInterface $request, ResponseInterface $r * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function updatePet(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing updatePet as a PUT method in OpenAPIServer\Api\PetApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -201,7 +183,7 @@ public function updatePet(ServerRequestInterface $request, ResponseInterface $re * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function updatePetWithForm(ServerRequestInterface $request, ResponseInterface $response, array $args) { @@ -210,10 +192,7 @@ public function updatePetWithForm(ServerRequestInterface $request, ResponseInter $name = (isset($body['name'])) ? $body['name'] : null; $status = (isset($body['status'])) ? $body['status'] : null; $message = "How about implementing updatePetWithForm as a POST method in OpenAPIServer\Api\PetApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -226,7 +205,7 @@ public function updatePetWithForm(ServerRequestInterface $request, ResponseInter * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function uploadFile(ServerRequestInterface $request, ResponseInterface $response, array $args) { @@ -235,10 +214,7 @@ public function uploadFile(ServerRequestInterface $request, ResponseInterface $r $additionalMetadata = (isset($body['additionalMetadata'])) ? $body['additionalMetadata'] : null; $file = (key_exists('file', $request->getUploadedFiles())) ? $request->getUploadedFiles()['file'] : null; $message = "How about implementing uploadFile as a POST method in OpenAPIServer\Api\PetApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -251,7 +227,7 @@ public function uploadFile(ServerRequestInterface $request, ResponseInterface $r * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function uploadFileWithRequiredFile(ServerRequestInterface $request, ResponseInterface $response, array $args) { @@ -260,9 +236,6 @@ public function uploadFileWithRequiredFile(ServerRequestInterface $request, Resp $additionalMetadata = (isset($body['additionalMetadata'])) ? $body['additionalMetadata'] : null; $requiredFile = (key_exists('requiredFile', $request->getUploadedFiles())) ? $request->getUploadedFiles()['requiredFile'] : null; $message = "How about implementing uploadFileWithRequiredFile as a POST method in OpenAPIServer\Api\PetApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } } diff --git a/samples/server/petstore/php-slim4/lib/Api/AbstractStoreApi.php b/samples/server/petstore/php-slim4/lib/Api/AbstractStoreApi.php index 48ef2d19da10..b1cfa80969e2 100644 --- a/samples/server/petstore/php-slim4/lib/Api/AbstractStoreApi.php +++ b/samples/server/petstore/php-slim4/lib/Api/AbstractStoreApi.php @@ -28,7 +28,7 @@ use Psr\Container\ContainerInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; -use Exception; +use Slim\Exception\HttpNotImplementedException; /** * AbstractStoreApi Class Doc Comment @@ -66,16 +66,13 @@ public function __construct(ContainerInterface $container = null) * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function deleteOrder(ServerRequestInterface $request, ResponseInterface $response, array $args) { $orderId = $args['order_id']; $message = "How about implementing deleteOrder as a DELETE method in OpenAPIServer\Api\StoreApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -89,15 +86,12 @@ public function deleteOrder(ServerRequestInterface $request, ResponseInterface $ * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function getInventory(ServerRequestInterface $request, ResponseInterface $response, array $args) { $message = "How about implementing getInventory as a GET method in OpenAPIServer\Api\StoreApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -111,16 +105,13 @@ public function getInventory(ServerRequestInterface $request, ResponseInterface * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function getOrderById(ServerRequestInterface $request, ResponseInterface $response, array $args) { $orderId = $args['order_id']; $message = "How about implementing getOrderById as a GET method in OpenAPIServer\Api\StoreApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -133,15 +124,12 @@ public function getOrderById(ServerRequestInterface $request, ResponseInterface * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function placeOrder(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing placeOrder as a POST method in OpenAPIServer\Api\StoreApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } } diff --git a/samples/server/petstore/php-slim4/lib/Api/AbstractUserApi.php b/samples/server/petstore/php-slim4/lib/Api/AbstractUserApi.php index 4a8e268bf060..d2beb8573dfa 100644 --- a/samples/server/petstore/php-slim4/lib/Api/AbstractUserApi.php +++ b/samples/server/petstore/php-slim4/lib/Api/AbstractUserApi.php @@ -28,7 +28,7 @@ use Psr\Container\ContainerInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; -use Exception; +use Slim\Exception\HttpNotImplementedException; /** * AbstractUserApi Class Doc Comment @@ -66,16 +66,13 @@ public function __construct(ContainerInterface $container = null) * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function createUser(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing createUser as a POST method in OpenAPIServer\Api\UserApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -87,16 +84,13 @@ public function createUser(ServerRequestInterface $request, ResponseInterface $r * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function createUsersWithArrayInput(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing createUsersWithArrayInput as a POST method in OpenAPIServer\Api\UserApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -108,16 +102,13 @@ public function createUsersWithArrayInput(ServerRequestInterface $request, Respo * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function createUsersWithListInput(ServerRequestInterface $request, ResponseInterface $response, array $args) { $body = $request->getParsedBody(); $message = "How about implementing createUsersWithListInput as a POST method in OpenAPIServer\Api\UserApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -130,16 +121,13 @@ public function createUsersWithListInput(ServerRequestInterface $request, Respon * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function deleteUser(ServerRequestInterface $request, ResponseInterface $response, array $args) { $username = $args['username']; $message = "How about implementing deleteUser as a DELETE method in OpenAPIServer\Api\UserApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -152,16 +140,13 @@ public function deleteUser(ServerRequestInterface $request, ResponseInterface $r * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function getUserByName(ServerRequestInterface $request, ResponseInterface $response, array $args) { $username = $args['username']; $message = "How about implementing getUserByName as a GET method in OpenAPIServer\Api\UserApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -174,7 +159,7 @@ public function getUserByName(ServerRequestInterface $request, ResponseInterface * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function loginUser(ServerRequestInterface $request, ResponseInterface $response, array $args) { @@ -182,10 +167,7 @@ public function loginUser(ServerRequestInterface $request, ResponseInterface $re $username = (key_exists('username', $queryParams)) ? $queryParams['username'] : null; $password = (key_exists('password', $queryParams)) ? $queryParams['password'] : null; $message = "How about implementing loginUser as a GET method in OpenAPIServer\Api\UserApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -197,15 +179,12 @@ public function loginUser(ServerRequestInterface $request, ResponseInterface $re * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function logoutUser(ServerRequestInterface $request, ResponseInterface $response, array $args) { $message = "How about implementing logoutUser as a GET method in OpenAPIServer\Api\UserApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } /** @@ -218,16 +197,13 @@ public function logoutUser(ServerRequestInterface $request, ResponseInterface $r * @param array|null $args Path arguments * * @return ResponseInterface - * @throws Exception to force implementation class to override this method + * @throws HttpNotImplementedException to force implementation class to override this method */ public function updateUser(ServerRequestInterface $request, ResponseInterface $response, array $args) { $username = $args['username']; $body = $request->getParsedBody(); $message = "How about implementing updateUser as a PUT method in OpenAPIServer\Api\UserApi class?"; - throw new Exception($message); - - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); } } diff --git a/samples/server/petstore/php-slim4/lib/SlimRouter.php b/samples/server/petstore/php-slim4/lib/SlimRouter.php index 4588e17fd56a..ea386ac13320 100644 --- a/samples/server/petstore/php-slim4/lib/SlimRouter.php +++ b/samples/server/petstore/php-slim4/lib/SlimRouter.php @@ -27,6 +27,7 @@ use Slim\Factory\AppFactory; use Slim\Interfaces\RouteInterface; +use Slim\Exception\HttpNotImplementedException; use Psr\Container\ContainerInterface; use InvalidArgumentException; use Dyorg\TokenAuthentication; @@ -1307,7 +1308,8 @@ class SlimRouter * * @param ContainerInterface|array $settings Either a ContainerInterface or an associative array of app settings * - * @throws Exception When implementation class doesn't exists + * @throws HttpNotImplementedException When implementation class doesn't exists + * @throws Exception when not supported authorization schema type provided */ public function __construct($settings = []) { @@ -1323,15 +1325,15 @@ public function __construct($settings = []) $authPackage = 'OpenAPIServer\Auth'; $basicAuthenticator = function (ServerRequestInterface &$request, TokenSearch $tokenSearch) use ($authPackage) { $message = "How about extending AbstractAuthenticator class by {$authPackage}\BasicAuthenticator?"; - throw new Exception($message); + throw new HttpNotImplementedException($request, $message); }; $apiKeyAuthenticator = function (ServerRequestInterface &$request, TokenSearch $tokenSearch) use ($authPackage) { $message = "How about extending AbstractAuthenticator class by {$authPackage}\ApiKeyAuthenticator?"; - throw new Exception($message); + throw new HttpNotImplementedException($request, $message); }; $oAuthAuthenticator = function (ServerRequestInterface &$request, TokenSearch $tokenSearch) use ($authPackage) { $message = "How about extending AbstractAuthenticator class by {$authPackage}\OAuthAuthenticator?"; - throw new Exception($message); + throw new HttpNotImplementedException($request, $message); }; $userOptions = $this->getSetting($settings, 'tokenAuthenticationOptions', null); @@ -1345,9 +1347,7 @@ public function __construct($settings = []) foreach ($this->operations as $operation) { $callback = function ($request, $response, $arguments) use ($operation) { $message = "How about extending {$operation['classname']} by {$operation['apiPackage']}\\{$operation['userClassname']} class implementing {$operation['operationId']} as a {$operation['httpMethod']} method?"; - throw new Exception($message); - $response->getBody()->write($message); - return $response->withStatus(501); + throw new HttpNotImplementedException($request, $message); }; $middlewares = [new JsonBodyParserMiddleware()];