diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSlimServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSlimServerCodegen.java index abf676d4fec..3ff9aad4eaa 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSlimServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpSlimServerCodegen.java @@ -36,6 +36,7 @@ public class PhpSlimServerCodegen extends AbstractPhpCodegen { private static final Logger LOGGER = LoggerFactory.getLogger(PhpSlimServerCodegen.class); public static final String PHPCS_STANDARD = "phpcsStandard"; + public static final String USER_CLASSNAME_KEY = "userClassname"; protected String groupId = "org.openapitools"; protected String artifactId = "openapi-server"; @@ -125,7 +126,6 @@ public class PhpSlimServerCodegen extends AbstractPhpCodegen { supportingFiles.add(new SupportingFile("composer.mustache", "", "composer.json")); supportingFiles.add(new SupportingFile("index.mustache", "", "index.php")); supportingFiles.add(new SupportingFile(".htaccess", "", ".htaccess")); - supportingFiles.add(new SupportingFile("AbstractApiController.mustache", toSrcPath(invokerPackage, srcBasePath), toAbstractName("ApiController") + ".php")); supportingFiles.add(new SupportingFile("SlimRouter.mustache", toSrcPath(invokerPackage, srcBasePath), "SlimRouter.php")); supportingFiles.add(new SupportingFile("phpunit.xml.mustache", "", "phpunit.xml.dist")); } @@ -134,6 +134,7 @@ public class PhpSlimServerCodegen extends AbstractPhpCodegen { public Map postProcessOperationsWithModels(Map objs, List allModels) { Map operations = (Map) objs.get("operations"); List operationList = (List) operations.get("operation"); + addUserClassnameToOperations(operations); escapeMediaType(operationList); return objs; } @@ -160,8 +161,41 @@ public class PhpSlimServerCodegen extends AbstractPhpCodegen { return objs; } + /** + * Sets PHP CodeSniffer <standard> option. Accepts name or path of the coding standard to use. + * + * @param phpcsStandard standard option value + */ public void setPhpcsStandard(String phpcsStandard) { this.phpcsStandard = phpcsStandard; } + @Override + public String toApiName(String name) { + if (name.length() == 0) { + return toAbstractName("DefaultApi"); + } + return toAbstractName(initialCaps(name) + "Api"); + } + + @Override + public String toApiTestFilename(String name) { + if (name.length() == 0) { + return "DefaultApiTest"; + } + return initialCaps(name) + "ApiTest"; + } + + /** + * Strips out abstract prefix and suffix from classname and puts it in "userClassname" property of operations object. + * + * @param operations codegen object with operations + */ + private void addUserClassnameToOperations(Map operations) { + String classname = (String) operations.get("classname"); + classname = classname.replaceAll("^" + abstractNamePrefix, ""); + classname = classname.replaceAll(abstractNameSuffix + "$", ""); + operations.put(USER_CLASSNAME_KEY, classname); + } + } diff --git a/modules/openapi-generator/src/main/resources/php-slim-server/AbstractApiController.mustache b/modules/openapi-generator/src/main/resources/php-slim-server/AbstractApiController.mustache deleted file mode 100644 index ab214f671fa..00000000000 --- a/modules/openapi-generator/src/main/resources/php-slim-server/AbstractApiController.mustache +++ /dev/null @@ -1,64 +0,0 @@ -container = $container; - } -} diff --git a/modules/openapi-generator/src/main/resources/php-slim-server/README.mustache b/modules/openapi-generator/src/main/resources/php-slim-server/README.mustache index 5a25a65f234..389484693fa 100644 --- a/modules/openapi-generator/src/main/resources/php-slim-server/README.mustache +++ b/modules/openapi-generator/src/main/resources/php-slim-server/README.mustache @@ -44,12 +44,41 @@ Command | Tool | Target `$ composer run phpcs` | PHP CodeSniffer | All files `$ composer run phplint` | phplint | All files +## Show errors + +Change line in `./index.php`: +```diff +--- $router = new SlimRouter(); ++++ $router = new SlimRouter(['settings' => ['displayErrorDetails' => true]]); +``` {{#generateApiDocs}} ## API Endpoints All URIs are relative to *{{{basePath}}}* +> Important! Do not modify abstract API controllers directly! Instead extend them by implementation classes like: + +```php +// src/Api/PetApi.php + +namespace {{apiPackage}}; + +use {{apiPackage}}\AbstractPetApi; + +class PetApi extends AbstractPetApi +{ + + public function addPet($request, $response, $args) + { + // your implementation of addPet method here + } +} +``` + +Place all your implementation classes in `./src` folder accordingly. +For instance, when abstract class located at `./lib/Api/AbstractPetApi.php` you need to create implementation class at `./src/Api/PetApi.php`. + Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- {{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | **{{operationId}}** | **{{httpMethod}}** {{path}} | {{#summary}}{{{summary}}}{{/summary}} diff --git a/modules/openapi-generator/src/main/resources/php-slim-server/SlimRouter.mustache b/modules/openapi-generator/src/main/resources/php-slim-server/SlimRouter.mustache index 18ee144e6d5..c68b2b2022c 100644 --- a/modules/openapi-generator/src/main/resources/php-slim-server/SlimRouter.mustache +++ b/modules/openapi-generator/src/main/resources/php-slim-server/SlimRouter.mustache @@ -33,9 +33,6 @@ */ namespace {{invokerPackage}}; -{{#apis}} -use {{apiPackage}}\{{classname}}; -{{/apis}} use Slim\App; use Psr\Container\ContainerInterface; use InvalidArgumentException; @@ -47,7 +44,7 @@ use Tuupola\Middleware\HttpBasicAuthentication; * PHP version 5 * * @category Class - * @package {{apiPackage}} + * @package {{invokerPackage}} * @author OpenAPI Generator team * @link https://github.com/openapitools/openapi-generator */ @@ -59,6 +56,37 @@ class SlimRouter */ private $slimApp; + /** @var array[] list of all api operations */ + private $operations = [ + {{#apis}} + {{#operations}} + {{#operation}} + [ + 'httpMethod' => '{{httpMethod}}', + 'basePathWithoutHost' => '{{{basePathWithoutHost}}}', + 'path' => '{{path}}', + 'apiPackage' => '{{apiPackage}}', + 'classname' => '{{classname}}', + 'userClassname' => '{{userClassname}}', + 'operationId' => '{{operationId}}', + 'authMethods' => [ + {{#hasAuthMethods}} + {{#authMethods}} + {{#isBasic}} + [ + 'type' => '{{type}}', + 'isBasic' => true, + ], + {{/isBasic}} + {{/authMethods}} + {{/hasAuthMethods}} + ], + ], + {{/operation}} + {{/operations}} + {{/apis}} + ]; + /** * Class constructor * @@ -67,7 +95,7 @@ class SlimRouter */ public function __construct($container = []) { - $app = new App($container); + $this->slimApp = new App($container); $basicAuth = new HttpBasicAuthentication([ "secure" => false, @@ -78,26 +106,53 @@ class SlimRouter } ]); - {{#apis}} - {{#operations}} - {{#operation}} - $app->{{httpMethod}}( - '{{{basePathWithoutHost}}}{{{path}}}', - {{classname}}::class . ':{{operationId}}' -{{#hasAuthMethods}} -{{#authMethods}} -{{#isBasic}} - )->add( - $basicAuth -{{/isBasic}} -{{/authMethods}} -{{/hasAuthMethods}} - ); - {{/operation}} - {{/operations}} - {{/apis}} + 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); + return $response->withStatus(501)->write($message); + }; + $middlewares = []; - $this->slimApp = $app; + if (class_exists("\\{$operation['apiPackage']}\\{$operation['userClassname']}")) { + $callback = "\\{$operation['apiPackage']}\\{$operation['userClassname']}:{$operation['operationId']}"; + } + + + foreach ($operation['authMethods'] as $authMethod) { + if ($authMethod['type'] === 'http') { + $middlewares[] = $basicAuth; + } + } + + $this->addRoute( + [$operation['httpMethod']], + "{$operation['basePathWithoutHost']}{$operation['path']}", + $callback, + $middlewares + )->setName($operation['operationId']); + } + } + + /** + * Add route with multiple methods + * + * @param string[] $methods Numeric array of HTTP method names + * @param string $pattern The route URI pattern + * @param callable|string $callable The route callback routine + * @param array|null $middlewares List of middlewares + * + * @return Slim\Interfaces\RouteInterface + * + * @throws InvalidArgumentException if the route pattern isn't a string + */ + public function addRoute($methods, $pattern, $callable, $middlewares = []) + { + $route = $this->slimApp->map($methods, $pattern, $callable); + foreach ($middlewares as $middleware) { + $route->add($middleware); + } + return $route; } /** diff --git a/modules/openapi-generator/src/main/resources/php-slim-server/api.mustache b/modules/openapi-generator/src/main/resources/php-slim-server/api.mustache index 832374d761b..d7eab314008 100644 --- a/modules/openapi-generator/src/main/resources/php-slim-server/api.mustache +++ b/modules/openapi-generator/src/main/resources/php-slim-server/api.mustache @@ -34,8 +34,6 @@ */ namespace {{apiPackage}}; -use {{invokerPackage}}\{{abstractNamePrefix}}ApiController{{abstractNameSuffix}}; - /** * {{classname}} Class Doc Comment * @@ -46,8 +44,24 @@ use {{invokerPackage}}\{{abstractNamePrefix}}ApiController{{abstractNameSuffix}} * @author OpenAPI Generator team * @link https://github.com/openapitools/openapi-generator */ -class {{classname}} extends {{abstractNamePrefix}}ApiController{{abstractNameSuffix}} +abstract class {{classname}} { + + /** + * @var \Interop\Container\ContainerInterface Slim app container instance + */ + protected $container; + + /** + * Route Controller constructor receives container + * + * @param \Interop\Container\ContainerInterface $container Slim app container instance + */ + public function __construct($container) + { + $this->container = $container; + } + {{#operations}} {{#operation}} @@ -66,6 +80,8 @@ class {{classname}} extends {{abstractNamePrefix}}ApiController{{abstractNameSuf * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function {{operationId}}($request, $response, $args) { @@ -99,8 +115,10 @@ class {{classname}} extends {{abstractNamePrefix}}ApiController{{abstractNameSuf {{#hasBodyParam}} $body = $request->getParsedBody(); {{/hasBodyParam}} - $response->write('How about implementing {{nickname}} as a {{httpMethod}} method ?'); - return $response; + $message = "How about implementing {{nickname}} as a {{httpMethod}} method in {{apiPackage}}\{{userClassname}} class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } {{/operation}} {{/operations}} diff --git a/modules/openapi-generator/src/main/resources/php-slim-server/api_test.mustache b/modules/openapi-generator/src/main/resources/php-slim-server/api_test.mustache index 204d183b48c..35cdde8439e 100644 --- a/modules/openapi-generator/src/main/resources/php-slim-server/api_test.mustache +++ b/modules/openapi-generator/src/main/resources/php-slim-server/api_test.mustache @@ -1,6 +1,6 @@ ['displayErrorDetails' => true]]); +``` ## API Endpoints All URIs are relative to *http://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r* +> Important! Do not modify abstract API controllers directly! Instead extend them by implementation classes like: + +```php +// src/Api/PetApi.php + +namespace OpenAPIServer\Api; + +use OpenAPIServer\Api\AbstractPetApi; + +class PetApi extends AbstractPetApi +{ + + public function addPet($request, $response, $args) + { + // your implementation of addPet method here + } +} +``` + +Place all your implementation classes in `./src` folder accordingly. +For instance, when abstract class located at `./lib/Api/AbstractPetApi.php` you need to create implementation class at `./src/Api/PetApi.php`. + Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- -*FakeApi* | **testCodeInjectEndRnNR** | **PUT** /fake | To test code injection *_/ ' \" =end -- \\r\\n \\n \\r +*AbstractFakeApi* | **testCodeInjectEndRnNR** | **PUT** /fake | To test code injection *_/ ' \" =end -- \\r\\n \\n \\r ## Models diff --git a/samples/server/petstore-security-test/php-slim/composer.json b/samples/server/petstore-security-test/php-slim/composer.json index ee30a881405..5b4e586c7c8 100644 --- a/samples/server/petstore-security-test/php-slim/composer.json +++ b/samples/server/petstore-security-test/php-slim/composer.json @@ -11,7 +11,10 @@ "squizlabs/php_codesniffer": "^3.0" }, "autoload": { - "psr-4": { "OpenAPIServer\\": "lib/" } + "psr-4": { "OpenAPIServer\\": [ + "lib/", + "src/" + ]} }, "autoload-dev": { "psr-4": { "OpenAPIServer\\": "test/" } diff --git a/samples/server/petstore-security-test/php-slim/lib/AbstractApiController.php b/samples/server/petstore-security-test/php-slim/lib/AbstractApiController.php deleted file mode 100644 index 9d6b899e2d3..00000000000 --- a/samples/server/petstore-security-test/php-slim/lib/AbstractApiController.php +++ /dev/null @@ -1,56 +0,0 @@ -container = $container; - } -} diff --git a/samples/server/petstore-security-test/php-slim/lib/Api/FakeApi.php b/samples/server/petstore-security-test/php-slim/lib/Api/AbstractFakeApi.php similarity index 68% rename from samples/server/petstore-security-test/php-slim/lib/Api/FakeApi.php rename to samples/server/petstore-security-test/php-slim/lib/Api/AbstractFakeApi.php index 20beeaef3f1..961d47aaa10 100644 --- a/samples/server/petstore-security-test/php-slim/lib/Api/FakeApi.php +++ b/samples/server/petstore-security-test/php-slim/lib/Api/AbstractFakeApi.php @@ -1,6 +1,6 @@ container = $container; + } + + /** * PUT testCodeInjectEndRnNR * Summary: To test code injection *_/ ' \" =end -- \\r\\n \\n \\r @@ -49,11 +63,15 @@ class FakeApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function testCodeInjectEndRnNR($request, $response, $args) { $testCodeInjectEndRnNR = $request->getParsedBodyParam('test code inject */ ' " =end -- \r\n \n \r'); - $response->write('How about implementing testCodeInjectEndRnNR as a PUT method ?'); - return $response; + $message = "How about implementing testCodeInjectEndRnNR as a PUT method in OpenAPIServer\Api\FakeApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } } diff --git a/samples/server/petstore-security-test/php-slim/lib/SlimRouter.php b/samples/server/petstore-security-test/php-slim/lib/SlimRouter.php index 0b7509aab71..f57b96bed30 100644 --- a/samples/server/petstore-security-test/php-slim/lib/SlimRouter.php +++ b/samples/server/petstore-security-test/php-slim/lib/SlimRouter.php @@ -26,7 +26,6 @@ */ namespace OpenAPIServer; -use OpenAPIServer\Api\FakeApi; use Slim\App; use Psr\Container\ContainerInterface; use InvalidArgumentException; @@ -38,7 +37,7 @@ use Tuupola\Middleware\HttpBasicAuthentication; * PHP version 5 * * @category Class - * @package OpenAPIServer\Api + * @package OpenAPIServer * @author OpenAPI Generator team * @link https://github.com/openapitools/openapi-generator */ @@ -50,6 +49,21 @@ class SlimRouter */ private $slimApp; + /** @var array[] list of all api operations */ + private $operations = [ + [ + 'httpMethod' => 'PUT', + 'basePathWithoutHost' => '/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r', + 'path' => '/fake', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractFakeApi', + 'userClassname' => 'FakeApi', + 'operationId' => 'testCodeInjectEndRnNR', + 'authMethods' => [ + ], + ], + ]; + /** * Class constructor * @@ -58,7 +72,7 @@ class SlimRouter */ public function __construct($container = []) { - $app = new App($container); + $this->slimApp = new App($container); $basicAuth = new HttpBasicAuthentication([ "secure" => false, @@ -69,12 +83,53 @@ class SlimRouter } ]); - $app->PUT( - '/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r/fake', - FakeApi::class . ':testCodeInjectEndRnNR' - ); + 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); + return $response->withStatus(501)->write($message); + }; + $middlewares = []; - $this->slimApp = $app; + if (class_exists("\\{$operation['apiPackage']}\\{$operation['userClassname']}")) { + $callback = "\\{$operation['apiPackage']}\\{$operation['userClassname']}:{$operation['operationId']}"; + } + + + foreach ($operation['authMethods'] as $authMethod) { + if ($authMethod['type'] === 'http') { + $middlewares[] = $basicAuth; + } + } + + $this->addRoute( + [$operation['httpMethod']], + "{$operation['basePathWithoutHost']}{$operation['path']}", + $callback, + $middlewares + )->setName($operation['operationId']); + } + } + + /** + * Add route with multiple methods + * + * @param string[] $methods Numeric array of HTTP method names + * @param string $pattern The route URI pattern + * @param callable|string $callable The route callback routine + * @param array|null $middlewares List of middlewares + * + * @return Slim\Interfaces\RouteInterface + * + * @throws InvalidArgumentException if the route pattern isn't a string + */ + public function addRoute($methods, $pattern, $callable, $middlewares = []) + { + $route = $this->slimApp->map($methods, $pattern, $callable); + foreach ($middlewares as $middleware) { + $route->add($middleware); + } + return $route; } /** diff --git a/samples/server/petstore-security-test/php-slim/phpunit.xml.dist b/samples/server/petstore-security-test/php-slim/phpunit.xml.dist index 7a4a5fedbcf..5804ff4945e 100644 --- a/samples/server/petstore-security-test/php-slim/phpunit.xml.dist +++ b/samples/server/petstore-security-test/php-slim/phpunit.xml.dist @@ -20,8 +20,8 @@ - ./lib//Api - ./lib//Model + ./lib/Api + ./lib/Model \ No newline at end of file diff --git a/samples/server/petstore-security-test/php-slim/test/Api/FakeApiTest.php b/samples/server/petstore-security-test/php-slim/test/Api/FakeApiTest.php index 5e631afe49e..dd67697ae92 100644 --- a/samples/server/petstore-security-test/php-slim/test/Api/FakeApiTest.php +++ b/samples/server/petstore-security-test/php-slim/test/Api/FakeApiTest.php @@ -36,7 +36,7 @@ use OpenAPIServer\Api\FakeApi; * @package OpenAPIServer\Api * @author OpenAPI Generator team * @link https://github.com/openapitools/openapi-generator - * @coversDefaultClass \OpenAPIServer\Model\FakeApi + * @coversDefaultClass \OpenAPIServer\Api\FakeApi */ class FakeApiTest extends TestCase { diff --git a/samples/server/petstore/php-slim/README.md b/samples/server/petstore/php-slim/README.md index 9c0e467e273..00e100cca4f 100644 --- a/samples/server/petstore/php-slim/README.md +++ b/samples/server/petstore/php-slim/README.md @@ -44,48 +44,77 @@ Command | Tool | Target `$ composer run phpcs` | PHP CodeSniffer | All files `$ composer run phplint` | phplint | All files +## Show errors + +Change line in `./index.php`: +```diff +--- $router = new SlimRouter(); ++++ $router = new SlimRouter(['settings' => ['displayErrorDetails' => true]]); +``` ## API Endpoints All URIs are relative to *http://petstore.swagger.io:80/v2* +> Important! Do not modify abstract API controllers directly! Instead extend them by implementation classes like: + +```php +// src/Api/PetApi.php + +namespace OpenAPIServer\Api; + +use OpenAPIServer\Api\AbstractPetApi; + +class PetApi extends AbstractPetApi +{ + + public function addPet($request, $response, $args) + { + // your implementation of addPet method here + } +} +``` + +Place all your implementation classes in `./src` folder accordingly. +For instance, when abstract class located at `./lib/Api/AbstractPetApi.php` you need to create implementation class at `./src/Api/PetApi.php`. + Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- -*AnotherFakeApi* | **call123TestSpecialTags** | **PATCH** /another-fake/dummy | To test special tags -*FakeApi* | **fakeOuterBooleanSerialize** | **POST** /fake/outer/boolean | -*FakeApi* | **fakeOuterCompositeSerialize** | **POST** /fake/outer/composite | -*FakeApi* | **fakeOuterNumberSerialize** | **POST** /fake/outer/number | -*FakeApi* | **fakeOuterStringSerialize** | **POST** /fake/outer/string | -*FakeApi* | **testBodyWithFileSchema** | **PUT** /fake/body-with-file-schema | -*FakeApi* | **testBodyWithQueryParams** | **PUT** /fake/body-with-query-params | -*FakeApi* | **testClientModel** | **PATCH** /fake | To test \"client\" model -*FakeApi* | **testEndpointParameters** | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 -*FakeApi* | **testEnumParameters** | **GET** /fake | To test enum parameters -*FakeApi* | **testGroupParameters** | **DELETE** /fake | Fake endpoint to test group parameters (optional) -*FakeApi* | **testInlineAdditionalProperties** | **POST** /fake/inline-additionalProperties | test inline additionalProperties -*FakeApi* | **testJsonFormData** | **GET** /fake/jsonFormData | test json serialization of form data -*FakeClassnameTags123Api* | **testClassname** | **PATCH** /fake_classname_test | To test class name in snake case -*PetApi* | **addPet** | **POST** /pet | Add a new pet to the store -*PetApi* | **findPetsByStatus** | **GET** /pet/findByStatus | Finds Pets by status -*PetApi* | **findPetsByTags** | **GET** /pet/findByTags | Finds Pets by tags -*PetApi* | **updatePet** | **PUT** /pet | Update an existing pet -*PetApi* | **deletePet** | **DELETE** /pet/{petId} | Deletes a pet -*PetApi* | **getPetById** | **GET** /pet/{petId} | Find pet by ID -*PetApi* | **updatePetWithForm** | **POST** /pet/{petId} | Updates a pet in the store with form data -*PetApi* | **uploadFile** | **POST** /pet/{petId}/uploadImage | uploads an image -*PetApi* | **uploadFileWithRequiredFile** | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) -*StoreApi* | **getInventory** | **GET** /store/inventory | Returns pet inventories by status -*StoreApi* | **placeOrder** | **POST** /store/order | Place an order for a pet -*StoreApi* | **deleteOrder** | **DELETE** /store/order/{order_id} | Delete purchase order by ID -*StoreApi* | **getOrderById** | **GET** /store/order/{order_id} | Find purchase order by ID -*UserApi* | **createUser** | **POST** /user | Create user -*UserApi* | **createUsersWithArrayInput** | **POST** /user/createWithArray | Creates list of users with given input array -*UserApi* | **createUsersWithListInput** | **POST** /user/createWithList | Creates list of users with given input array -*UserApi* | **loginUser** | **GET** /user/login | Logs user into the system -*UserApi* | **logoutUser** | **GET** /user/logout | Logs out current logged in user session -*UserApi* | **deleteUser** | **DELETE** /user/{username} | Delete user -*UserApi* | **getUserByName** | **GET** /user/{username} | Get user by user name -*UserApi* | **updateUser** | **PUT** /user/{username} | Updated user +*AbstractAnotherFakeApi* | **call123TestSpecialTags** | **PATCH** /another-fake/dummy | To test special tags +*AbstractFakeApi* | **fakeOuterBooleanSerialize** | **POST** /fake/outer/boolean | +*AbstractFakeApi* | **fakeOuterCompositeSerialize** | **POST** /fake/outer/composite | +*AbstractFakeApi* | **fakeOuterNumberSerialize** | **POST** /fake/outer/number | +*AbstractFakeApi* | **fakeOuterStringSerialize** | **POST** /fake/outer/string | +*AbstractFakeApi* | **testBodyWithFileSchema** | **PUT** /fake/body-with-file-schema | +*AbstractFakeApi* | **testBodyWithQueryParams** | **PUT** /fake/body-with-query-params | +*AbstractFakeApi* | **testClientModel** | **PATCH** /fake | To test \"client\" model +*AbstractFakeApi* | **testEndpointParameters** | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 +*AbstractFakeApi* | **testEnumParameters** | **GET** /fake | To test enum parameters +*AbstractFakeApi* | **testGroupParameters** | **DELETE** /fake | Fake endpoint to test group parameters (optional) +*AbstractFakeApi* | **testInlineAdditionalProperties** | **POST** /fake/inline-additionalProperties | test inline additionalProperties +*AbstractFakeApi* | **testJsonFormData** | **GET** /fake/jsonFormData | test json serialization of form data +*AbstractFakeClassnameTags123Api* | **testClassname** | **PATCH** /fake_classname_test | To test class name in snake case +*AbstractPetApi* | **addPet** | **POST** /pet | Add a new pet to the store +*AbstractPetApi* | **findPetsByStatus** | **GET** /pet/findByStatus | Finds Pets by status +*AbstractPetApi* | **findPetsByTags** | **GET** /pet/findByTags | Finds Pets by tags +*AbstractPetApi* | **updatePet** | **PUT** /pet | Update an existing pet +*AbstractPetApi* | **deletePet** | **DELETE** /pet/{petId} | Deletes a pet +*AbstractPetApi* | **getPetById** | **GET** /pet/{petId} | Find pet by ID +*AbstractPetApi* | **updatePetWithForm** | **POST** /pet/{petId} | Updates a pet in the store with form data +*AbstractPetApi* | **uploadFile** | **POST** /pet/{petId}/uploadImage | uploads an image +*AbstractPetApi* | **uploadFileWithRequiredFile** | **POST** /fake/{petId}/uploadImageWithRequiredFile | uploads an image (required) +*AbstractStoreApi* | **getInventory** | **GET** /store/inventory | Returns pet inventories by status +*AbstractStoreApi* | **placeOrder** | **POST** /store/order | Place an order for a pet +*AbstractStoreApi* | **deleteOrder** | **DELETE** /store/order/{order_id} | Delete purchase order by ID +*AbstractStoreApi* | **getOrderById** | **GET** /store/order/{order_id} | Find purchase order by ID +*AbstractUserApi* | **createUser** | **POST** /user | Create user +*AbstractUserApi* | **createUsersWithArrayInput** | **POST** /user/createWithArray | Creates list of users with given input array +*AbstractUserApi* | **createUsersWithListInput** | **POST** /user/createWithList | Creates list of users with given input array +*AbstractUserApi* | **loginUser** | **GET** /user/login | Logs user into the system +*AbstractUserApi* | **logoutUser** | **GET** /user/logout | Logs out current logged in user session +*AbstractUserApi* | **deleteUser** | **DELETE** /user/{username} | Delete user +*AbstractUserApi* | **getUserByName** | **GET** /user/{username} | Get user by user name +*AbstractUserApi* | **updateUser** | **PUT** /user/{username} | Updated user ## Models diff --git a/samples/server/petstore/php-slim/composer.json b/samples/server/petstore/php-slim/composer.json index ee30a881405..5b4e586c7c8 100644 --- a/samples/server/petstore/php-slim/composer.json +++ b/samples/server/petstore/php-slim/composer.json @@ -11,7 +11,10 @@ "squizlabs/php_codesniffer": "^3.0" }, "autoload": { - "psr-4": { "OpenAPIServer\\": "lib/" } + "psr-4": { "OpenAPIServer\\": [ + "lib/", + "src/" + ]} }, "autoload-dev": { "psr-4": { "OpenAPIServer\\": "test/" } diff --git a/samples/server/petstore/php-slim/lib/AbstractApiController.php b/samples/server/petstore/php-slim/lib/AbstractApiController.php deleted file mode 100644 index 9f20afc8770..00000000000 --- a/samples/server/petstore/php-slim/lib/AbstractApiController.php +++ /dev/null @@ -1,55 +0,0 @@ -container = $container; - } -} diff --git a/samples/server/petstore/php-slim/lib/Api/AnotherFakeApi.php b/samples/server/petstore/php-slim/lib/Api/AbstractAnotherFakeApi.php similarity index 64% rename from samples/server/petstore/php-slim/lib/Api/AnotherFakeApi.php rename to samples/server/petstore/php-slim/lib/Api/AbstractAnotherFakeApi.php index 31a641e5528..901b4a6c07c 100644 --- a/samples/server/petstore/php-slim/lib/Api/AnotherFakeApi.php +++ b/samples/server/petstore/php-slim/lib/Api/AbstractAnotherFakeApi.php @@ -1,6 +1,6 @@ container = $container; + } + + /** * PATCH call123TestSpecialTags * Summary: To test special tags @@ -49,11 +63,15 @@ class AnotherFakeApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function call123TestSpecialTags($request, $response, $args) { $body = $request->getParsedBody(); - $response->write('How about implementing call123TestSpecialTags as a PATCH method ?'); - return $response; + $message = "How about implementing call123TestSpecialTags as a PATCH method in OpenAPIServer\Api\AnotherFakeApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } } diff --git a/samples/server/petstore/php-slim/lib/Api/FakeApi.php b/samples/server/petstore/php-slim/lib/Api/AbstractFakeApi.php similarity index 70% rename from samples/server/petstore/php-slim/lib/Api/FakeApi.php rename to samples/server/petstore/php-slim/lib/Api/AbstractFakeApi.php index d6dd7958c8f..244431feeca 100644 --- a/samples/server/petstore/php-slim/lib/Api/FakeApi.php +++ b/samples/server/petstore/php-slim/lib/Api/AbstractFakeApi.php @@ -1,6 +1,6 @@ container = $container; + } + + /** * POST fakeOuterBooleanSerialize * Notes: Test serialization of outer boolean types @@ -48,12 +62,16 @@ class FakeApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function fakeOuterBooleanSerialize($request, $response, $args) { $body = $request->getParsedBody(); - $response->write('How about implementing fakeOuterBooleanSerialize as a POST method ?'); - return $response; + $message = "How about implementing fakeOuterBooleanSerialize as a POST method in OpenAPIServer\Api\FakeApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -64,12 +82,16 @@ class FakeApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function fakeOuterCompositeSerialize($request, $response, $args) { $body = $request->getParsedBody(); - $response->write('How about implementing fakeOuterCompositeSerialize as a POST method ?'); - return $response; + $message = "How about implementing fakeOuterCompositeSerialize as a POST method in OpenAPIServer\Api\FakeApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -80,12 +102,16 @@ class FakeApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function fakeOuterNumberSerialize($request, $response, $args) { $body = $request->getParsedBody(); - $response->write('How about implementing fakeOuterNumberSerialize as a POST method ?'); - return $response; + $message = "How about implementing fakeOuterNumberSerialize as a POST method in OpenAPIServer\Api\FakeApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -96,12 +122,16 @@ class FakeApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function fakeOuterStringSerialize($request, $response, $args) { $body = $request->getParsedBody(); - $response->write('How about implementing fakeOuterStringSerialize as a POST method ?'); - return $response; + $message = "How about implementing fakeOuterStringSerialize as a POST method in OpenAPIServer\Api\FakeApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -111,12 +141,16 @@ class FakeApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function testBodyWithFileSchema($request, $response, $args) { $body = $request->getParsedBody(); - $response->write('How about implementing testBodyWithFileSchema as a PUT method ?'); - return $response; + $message = "How about implementing testBodyWithFileSchema as a PUT method in OpenAPIServer\Api\FakeApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -125,14 +159,18 @@ class FakeApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function testBodyWithQueryParams($request, $response, $args) { $queryParams = $request->getQueryParams(); $query = $request->getQueryParam('query'); $body = $request->getParsedBody(); - $response->write('How about implementing testBodyWithQueryParams as a PUT method ?'); - return $response; + $message = "How about implementing testBodyWithQueryParams as a PUT method in OpenAPIServer\Api\FakeApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -144,12 +182,16 @@ class FakeApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function testClientModel($request, $response, $args) { $body = $request->getParsedBody(); - $response->write('How about implementing testClientModel as a PATCH method ?'); - return $response; + $message = "How about implementing testClientModel as a PATCH method in OpenAPIServer\Api\FakeApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -160,6 +202,8 @@ class FakeApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function testEndpointParameters($request, $response, $args) { @@ -177,8 +221,10 @@ class FakeApi extends AbstractApiController $dateTime = $request->getParsedBodyParam('dateTime'); $password = $request->getParsedBodyParam('password'); $callback = $request->getParsedBodyParam('callback'); - $response->write('How about implementing testEndpointParameters as a POST method ?'); - return $response; + $message = "How about implementing testEndpointParameters as a POST method in OpenAPIServer\Api\FakeApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -189,6 +235,8 @@ class FakeApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function testEnumParameters($request, $response, $args) { @@ -202,8 +250,10 @@ class FakeApi extends AbstractApiController $enumQueryDouble = $request->getQueryParam('enum_query_double'); $enumFormStringArray = $request->getParsedBodyParam('enum_form_string_array'); $enumFormString = $request->getParsedBodyParam('enum_form_string'); - $response->write('How about implementing testEnumParameters as a GET method ?'); - return $response; + $message = "How about implementing testEnumParameters as a GET method in OpenAPIServer\Api\FakeApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -214,6 +264,8 @@ class FakeApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function testGroupParameters($request, $response, $args) { @@ -225,8 +277,10 @@ class FakeApi extends AbstractApiController $requiredInt64Group = $request->getQueryParam('required_int64_group'); $stringGroup = $request->getQueryParam('string_group'); $int64Group = $request->getQueryParam('int64_group'); - $response->write('How about implementing testGroupParameters as a DELETE method ?'); - return $response; + $message = "How about implementing testGroupParameters as a DELETE method in OpenAPIServer\Api\FakeApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -236,12 +290,16 @@ class FakeApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function testInlineAdditionalProperties($request, $response, $args) { $body = $request->getParsedBody(); - $response->write('How about implementing testInlineAdditionalProperties as a POST method ?'); - return $response; + $message = "How about implementing testInlineAdditionalProperties as a POST method in OpenAPIServer\Api\FakeApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -251,12 +309,16 @@ class FakeApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function testJsonFormData($request, $response, $args) { $param = $request->getParsedBodyParam('param'); $param2 = $request->getParsedBodyParam('param2'); - $response->write('How about implementing testJsonFormData as a GET method ?'); - return $response; + $message = "How about implementing testJsonFormData as a GET method in OpenAPIServer\Api\FakeApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } } diff --git a/samples/server/petstore/php-slim/lib/Api/FakeClassnameTags123Api.php b/samples/server/petstore/php-slim/lib/Api/AbstractFakeClassnameTags123Api.php similarity index 63% rename from samples/server/petstore/php-slim/lib/Api/FakeClassnameTags123Api.php rename to samples/server/petstore/php-slim/lib/Api/AbstractFakeClassnameTags123Api.php index c4699994049..7d4c971ccea 100644 --- a/samples/server/petstore/php-slim/lib/Api/FakeClassnameTags123Api.php +++ b/samples/server/petstore/php-slim/lib/Api/AbstractFakeClassnameTags123Api.php @@ -1,6 +1,6 @@ container = $container; + } + + /** * PATCH testClassname * Summary: To test class name in snake case @@ -49,11 +63,15 @@ class FakeClassnameTags123Api extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function testClassname($request, $response, $args) { $body = $request->getParsedBody(); - $response->write('How about implementing testClassname as a PATCH method ?'); - return $response; + $message = "How about implementing testClassname as a PATCH method in OpenAPIServer\Api\FakeClassnameTags123Api class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } } diff --git a/samples/server/petstore/php-slim/lib/Api/PetApi.php b/samples/server/petstore/php-slim/lib/Api/AbstractPetApi.php similarity index 67% rename from samples/server/petstore/php-slim/lib/Api/PetApi.php rename to samples/server/petstore/php-slim/lib/Api/AbstractPetApi.php index 08fd51b46e9..66331198991 100644 --- a/samples/server/petstore/php-slim/lib/Api/PetApi.php +++ b/samples/server/petstore/php-slim/lib/Api/AbstractPetApi.php @@ -1,6 +1,6 @@ container = $container; + } + + /** * POST addPet * Summary: Add a new pet to the store @@ -47,12 +61,16 @@ class PetApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function addPet($request, $response, $args) { $body = $request->getParsedBody(); - $response->write('How about implementing addPet as a POST method ?'); - return $response; + $message = "How about implementing addPet as a POST method in OpenAPIServer\Api\PetApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -62,14 +80,18 @@ class PetApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function deletePet($request, $response, $args) { $headers = $request->getHeaders(); $apiKey = $request->hasHeader('api_key') ? $headers['api_key'] : null; $petId = $args['petId']; - $response->write('How about implementing deletePet as a DELETE method ?'); - return $response; + $message = "How about implementing deletePet as a DELETE method in OpenAPIServer\Api\PetApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -81,13 +103,17 @@ class PetApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function findPetsByStatus($request, $response, $args) { $queryParams = $request->getQueryParams(); $status = $request->getQueryParam('status'); - $response->write('How about implementing findPetsByStatus as a GET method ?'); - return $response; + $message = "How about implementing findPetsByStatus as a GET method in OpenAPIServer\Api\PetApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -99,13 +125,17 @@ class PetApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function findPetsByTags($request, $response, $args) { $queryParams = $request->getQueryParams(); $tags = $request->getQueryParam('tags'); - $response->write('How about implementing findPetsByTags as a GET method ?'); - return $response; + $message = "How about implementing findPetsByTags as a GET method in OpenAPIServer\Api\PetApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -117,12 +147,16 @@ class PetApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function getPetById($request, $response, $args) { $petId = $args['petId']; - $response->write('How about implementing getPetById as a GET method ?'); - return $response; + $message = "How about implementing getPetById as a GET method in OpenAPIServer\Api\PetApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -132,12 +166,16 @@ class PetApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function updatePet($request, $response, $args) { $body = $request->getParsedBody(); - $response->write('How about implementing updatePet as a PUT method ?'); - return $response; + $message = "How about implementing updatePet as a PUT method in OpenAPIServer\Api\PetApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -147,14 +185,18 @@ class PetApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function updatePetWithForm($request, $response, $args) { $petId = $args['petId']; $name = $request->getParsedBodyParam('name'); $status = $request->getParsedBodyParam('status'); - $response->write('How about implementing updatePetWithForm as a POST method ?'); - return $response; + $message = "How about implementing updatePetWithForm as a POST method in OpenAPIServer\Api\PetApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -165,14 +207,18 @@ class PetApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function uploadFile($request, $response, $args) { $petId = $args['petId']; $additionalMetadata = $request->getParsedBodyParam('additionalMetadata'); $file = (key_exists('file', $request->getUploadedFiles())) ? $request->getUploadedFiles()['file'] : null; - $response->write('How about implementing uploadFile as a POST method ?'); - return $response; + $message = "How about implementing uploadFile as a POST method in OpenAPIServer\Api\PetApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -183,13 +229,17 @@ class PetApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function uploadFileWithRequiredFile($request, $response, $args) { $petId = $args['petId']; $additionalMetadata = $request->getParsedBodyParam('additionalMetadata'); $requiredFile = (key_exists('requiredFile', $request->getUploadedFiles())) ? $request->getUploadedFiles()['requiredFile'] : null; - $response->write('How about implementing uploadFileWithRequiredFile as a POST method ?'); - return $response; + $message = "How about implementing uploadFileWithRequiredFile as a POST method in OpenAPIServer\Api\PetApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } } diff --git a/samples/server/petstore/php-slim/lib/Api/StoreApi.php b/samples/server/petstore/php-slim/lib/Api/AbstractStoreApi.php similarity index 66% rename from samples/server/petstore/php-slim/lib/Api/StoreApi.php rename to samples/server/petstore/php-slim/lib/Api/AbstractStoreApi.php index f668236a34f..60f217b3eef 100644 --- a/samples/server/petstore/php-slim/lib/Api/StoreApi.php +++ b/samples/server/petstore/php-slim/lib/Api/AbstractStoreApi.php @@ -1,6 +1,6 @@ container = $container; + } + + /** * DELETE deleteOrder * Summary: Delete purchase order by ID @@ -48,12 +62,16 @@ class StoreApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function deleteOrder($request, $response, $args) { $orderId = $args['order_id']; - $response->write('How about implementing deleteOrder as a DELETE method ?'); - return $response; + $message = "How about implementing deleteOrder as a DELETE method in OpenAPIServer\Api\StoreApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -65,11 +83,15 @@ class StoreApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function getInventory($request, $response, $args) { - $response->write('How about implementing getInventory as a GET method ?'); - return $response; + $message = "How about implementing getInventory as a GET method in OpenAPIServer\Api\StoreApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -81,12 +103,16 @@ class StoreApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function getOrderById($request, $response, $args) { $orderId = $args['order_id']; - $response->write('How about implementing getOrderById as a GET method ?'); - return $response; + $message = "How about implementing getOrderById as a GET method in OpenAPIServer\Api\StoreApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -97,11 +123,15 @@ class StoreApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function placeOrder($request, $response, $args) { $body = $request->getParsedBody(); - $response->write('How about implementing placeOrder as a POST method ?'); - return $response; + $message = "How about implementing placeOrder as a POST method in OpenAPIServer\Api\StoreApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } } diff --git a/samples/server/petstore/php-slim/lib/Api/UserApi.php b/samples/server/petstore/php-slim/lib/Api/AbstractUserApi.php similarity index 64% rename from samples/server/petstore/php-slim/lib/Api/UserApi.php rename to samples/server/petstore/php-slim/lib/Api/AbstractUserApi.php index ef9863cfc33..0b69096365d 100644 --- a/samples/server/petstore/php-slim/lib/Api/UserApi.php +++ b/samples/server/petstore/php-slim/lib/Api/AbstractUserApi.php @@ -1,6 +1,6 @@ container = $container; + } + + /** * POST createUser * Summary: Create user @@ -48,12 +62,16 @@ class UserApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function createUser($request, $response, $args) { $body = $request->getParsedBody(); - $response->write('How about implementing createUser as a POST method ?'); - return $response; + $message = "How about implementing createUser as a POST method in OpenAPIServer\Api\UserApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -63,12 +81,16 @@ class UserApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function createUsersWithArrayInput($request, $response, $args) { $body = $request->getParsedBody(); - $response->write('How about implementing createUsersWithArrayInput as a POST method ?'); - return $response; + $message = "How about implementing createUsersWithArrayInput as a POST method in OpenAPIServer\Api\UserApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -78,12 +100,16 @@ class UserApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function createUsersWithListInput($request, $response, $args) { $body = $request->getParsedBody(); - $response->write('How about implementing createUsersWithListInput as a POST method ?'); - return $response; + $message = "How about implementing createUsersWithListInput as a POST method in OpenAPIServer\Api\UserApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -94,12 +120,16 @@ class UserApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function deleteUser($request, $response, $args) { $username = $args['username']; - $response->write('How about implementing deleteUser as a DELETE method ?'); - return $response; + $message = "How about implementing deleteUser as a DELETE method in OpenAPIServer\Api\UserApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -110,12 +140,16 @@ class UserApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function getUserByName($request, $response, $args) { $username = $args['username']; - $response->write('How about implementing getUserByName as a GET method ?'); - return $response; + $message = "How about implementing getUserByName as a GET method in OpenAPIServer\Api\UserApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -126,14 +160,18 @@ class UserApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function loginUser($request, $response, $args) { $queryParams = $request->getQueryParams(); $username = $request->getQueryParam('username'); $password = $request->getQueryParam('password'); - $response->write('How about implementing loginUser as a GET method ?'); - return $response; + $message = "How about implementing loginUser as a GET method in OpenAPIServer\Api\UserApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -143,11 +181,15 @@ class UserApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function logoutUser($request, $response, $args) { - $response->write('How about implementing logoutUser as a GET method ?'); - return $response; + $message = "How about implementing logoutUser as a GET method in OpenAPIServer\Api\UserApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } /** @@ -158,12 +200,16 @@ class UserApi extends AbstractApiController * @param \Psr\Http\Message\ServerRequestInterface $request Request * @param \Psr\Http\Message\ResponseInterface $response Response * @param array|null $args Path arguments + * + * @return \Psr\Http\Message\ResponseInterface */ public function updateUser($request, $response, $args) { $username = $args['username']; $body = $request->getParsedBody(); - $response->write('How about implementing updateUser as a PUT method ?'); - return $response; + $message = "How about implementing updateUser as a PUT method in OpenAPIServer\Api\UserApi class?"; + throw new \Exception($message); + + return $response->write($message)->withStatus(501); } } diff --git a/samples/server/petstore/php-slim/lib/Model/AnimalFarm.php b/samples/server/petstore/php-slim/lib/Model/AnimalFarm.php deleted file mode 100644 index 36466e01819..00000000000 --- a/samples/server/petstore/php-slim/lib/Model/AnimalFarm.php +++ /dev/null @@ -1,12 +0,0 @@ - 'PATCH', + 'basePathWithoutHost' => '/v2', + 'path' => '/another-fake/dummy', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractAnotherFakeApi', + 'userClassname' => 'AnotherFakeApi', + 'operationId' => 'call123TestSpecialTags', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'POST', + 'basePathWithoutHost' => '/v2', + 'path' => '/fake/outer/boolean', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractFakeApi', + 'userClassname' => 'FakeApi', + 'operationId' => 'fakeOuterBooleanSerialize', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'POST', + 'basePathWithoutHost' => '/v2', + 'path' => '/fake/outer/composite', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractFakeApi', + 'userClassname' => 'FakeApi', + 'operationId' => 'fakeOuterCompositeSerialize', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'POST', + 'basePathWithoutHost' => '/v2', + 'path' => '/fake/outer/number', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractFakeApi', + 'userClassname' => 'FakeApi', + 'operationId' => 'fakeOuterNumberSerialize', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'POST', + 'basePathWithoutHost' => '/v2', + 'path' => '/fake/outer/string', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractFakeApi', + 'userClassname' => 'FakeApi', + 'operationId' => 'fakeOuterStringSerialize', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'PUT', + 'basePathWithoutHost' => '/v2', + 'path' => '/fake/body-with-file-schema', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractFakeApi', + 'userClassname' => 'FakeApi', + 'operationId' => 'testBodyWithFileSchema', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'PUT', + 'basePathWithoutHost' => '/v2', + 'path' => '/fake/body-with-query-params', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractFakeApi', + 'userClassname' => 'FakeApi', + 'operationId' => 'testBodyWithQueryParams', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'PATCH', + 'basePathWithoutHost' => '/v2', + 'path' => '/fake', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractFakeApi', + 'userClassname' => 'FakeApi', + 'operationId' => 'testClientModel', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'POST', + 'basePathWithoutHost' => '/v2', + 'path' => '/fake', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractFakeApi', + 'userClassname' => 'FakeApi', + 'operationId' => 'testEndpointParameters', + 'authMethods' => [ + [ + 'type' => 'http', + 'isBasic' => true, + ], + ], + ], + [ + 'httpMethod' => 'GET', + 'basePathWithoutHost' => '/v2', + 'path' => '/fake', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractFakeApi', + 'userClassname' => 'FakeApi', + 'operationId' => 'testEnumParameters', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'DELETE', + 'basePathWithoutHost' => '/v2', + 'path' => '/fake', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractFakeApi', + 'userClassname' => 'FakeApi', + 'operationId' => 'testGroupParameters', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'POST', + 'basePathWithoutHost' => '/v2', + 'path' => '/fake/inline-additionalProperties', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractFakeApi', + 'userClassname' => 'FakeApi', + 'operationId' => 'testInlineAdditionalProperties', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'GET', + 'basePathWithoutHost' => '/v2', + 'path' => '/fake/jsonFormData', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractFakeApi', + 'userClassname' => 'FakeApi', + 'operationId' => 'testJsonFormData', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'PATCH', + 'basePathWithoutHost' => '/v2', + 'path' => '/fake_classname_test', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractFakeClassnameTags123Api', + 'userClassname' => 'FakeClassnameTags123Api', + 'operationId' => 'testClassname', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'POST', + 'basePathWithoutHost' => '/v2', + 'path' => '/pet', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractPetApi', + 'userClassname' => 'PetApi', + 'operationId' => 'addPet', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'GET', + 'basePathWithoutHost' => '/v2', + 'path' => '/pet/findByStatus', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractPetApi', + 'userClassname' => 'PetApi', + 'operationId' => 'findPetsByStatus', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'GET', + 'basePathWithoutHost' => '/v2', + 'path' => '/pet/findByTags', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractPetApi', + 'userClassname' => 'PetApi', + 'operationId' => 'findPetsByTags', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'PUT', + 'basePathWithoutHost' => '/v2', + 'path' => '/pet', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractPetApi', + 'userClassname' => 'PetApi', + 'operationId' => 'updatePet', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'DELETE', + 'basePathWithoutHost' => '/v2', + 'path' => '/pet/{petId}', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractPetApi', + 'userClassname' => 'PetApi', + 'operationId' => 'deletePet', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'GET', + 'basePathWithoutHost' => '/v2', + 'path' => '/pet/{petId}', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractPetApi', + 'userClassname' => 'PetApi', + 'operationId' => 'getPetById', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'POST', + 'basePathWithoutHost' => '/v2', + 'path' => '/pet/{petId}', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractPetApi', + 'userClassname' => 'PetApi', + 'operationId' => 'updatePetWithForm', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'POST', + 'basePathWithoutHost' => '/v2', + 'path' => '/pet/{petId}/uploadImage', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractPetApi', + 'userClassname' => 'PetApi', + 'operationId' => 'uploadFile', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'POST', + 'basePathWithoutHost' => '/v2', + 'path' => '/fake/{petId}/uploadImageWithRequiredFile', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractPetApi', + 'userClassname' => 'PetApi', + 'operationId' => 'uploadFileWithRequiredFile', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'GET', + 'basePathWithoutHost' => '/v2', + 'path' => '/store/inventory', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractStoreApi', + 'userClassname' => 'StoreApi', + 'operationId' => 'getInventory', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'POST', + 'basePathWithoutHost' => '/v2', + 'path' => '/store/order', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractStoreApi', + 'userClassname' => 'StoreApi', + 'operationId' => 'placeOrder', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'DELETE', + 'basePathWithoutHost' => '/v2', + 'path' => '/store/order/{order_id}', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractStoreApi', + 'userClassname' => 'StoreApi', + 'operationId' => 'deleteOrder', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'GET', + 'basePathWithoutHost' => '/v2', + 'path' => '/store/order/{order_id}', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractStoreApi', + 'userClassname' => 'StoreApi', + 'operationId' => 'getOrderById', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'POST', + 'basePathWithoutHost' => '/v2', + 'path' => '/user', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractUserApi', + 'userClassname' => 'UserApi', + 'operationId' => 'createUser', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'POST', + 'basePathWithoutHost' => '/v2', + 'path' => '/user/createWithArray', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractUserApi', + 'userClassname' => 'UserApi', + 'operationId' => 'createUsersWithArrayInput', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'POST', + 'basePathWithoutHost' => '/v2', + 'path' => '/user/createWithList', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractUserApi', + 'userClassname' => 'UserApi', + 'operationId' => 'createUsersWithListInput', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'GET', + 'basePathWithoutHost' => '/v2', + 'path' => '/user/login', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractUserApi', + 'userClassname' => 'UserApi', + 'operationId' => 'loginUser', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'GET', + 'basePathWithoutHost' => '/v2', + 'path' => '/user/logout', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractUserApi', + 'userClassname' => 'UserApi', + 'operationId' => 'logoutUser', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'DELETE', + 'basePathWithoutHost' => '/v2', + 'path' => '/user/{username}', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractUserApi', + 'userClassname' => 'UserApi', + 'operationId' => 'deleteUser', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'GET', + 'basePathWithoutHost' => '/v2', + 'path' => '/user/{username}', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractUserApi', + 'userClassname' => 'UserApi', + 'operationId' => 'getUserByName', + 'authMethods' => [ + ], + ], + [ + 'httpMethod' => 'PUT', + 'basePathWithoutHost' => '/v2', + 'path' => '/user/{username}', + 'apiPackage' => 'OpenAPIServer\Api', + 'classname' => 'AbstractUserApi', + 'userClassname' => 'UserApi', + 'operationId' => 'updateUser', + 'authMethods' => [ + ], + ], + ]; + /** * Class constructor * @@ -62,7 +449,7 @@ class SlimRouter */ public function __construct($container = []) { - $app = new App($container); + $this->slimApp = new App($container); $basicAuth = new HttpBasicAuthentication([ "secure" => false, @@ -73,150 +460,53 @@ class SlimRouter } ]); - $app->PATCH( - '/v2/another-fake/dummy', - AnotherFakeApi::class . ':call123TestSpecialTags' - ); - $app->POST( - '/v2/fake/outer/boolean', - FakeApi::class . ':fakeOuterBooleanSerialize' - ); - $app->POST( - '/v2/fake/outer/composite', - FakeApi::class . ':fakeOuterCompositeSerialize' - ); - $app->POST( - '/v2/fake/outer/number', - FakeApi::class . ':fakeOuterNumberSerialize' - ); - $app->POST( - '/v2/fake/outer/string', - FakeApi::class . ':fakeOuterStringSerialize' - ); - $app->PUT( - '/v2/fake/body-with-file-schema', - FakeApi::class . ':testBodyWithFileSchema' - ); - $app->PUT( - '/v2/fake/body-with-query-params', - FakeApi::class . ':testBodyWithQueryParams' - ); - $app->PATCH( - '/v2/fake', - FakeApi::class . ':testClientModel' - ); - $app->POST( - '/v2/fake', - FakeApi::class . ':testEndpointParameters' - )->add( - $basicAuth - ); - $app->GET( - '/v2/fake', - FakeApi::class . ':testEnumParameters' - ); - $app->DELETE( - '/v2/fake', - FakeApi::class . ':testGroupParameters' - ); - $app->POST( - '/v2/fake/inline-additionalProperties', - FakeApi::class . ':testInlineAdditionalProperties' - ); - $app->GET( - '/v2/fake/jsonFormData', - FakeApi::class . ':testJsonFormData' - ); - $app->PATCH( - '/v2/fake_classname_test', - FakeClassnameTags123Api::class . ':testClassname' - ); - $app->POST( - '/v2/pet', - PetApi::class . ':addPet' - ); - $app->GET( - '/v2/pet/findByStatus', - PetApi::class . ':findPetsByStatus' - ); - $app->GET( - '/v2/pet/findByTags', - PetApi::class . ':findPetsByTags' - ); - $app->PUT( - '/v2/pet', - PetApi::class . ':updatePet' - ); - $app->DELETE( - '/v2/pet/{petId}', - PetApi::class . ':deletePet' - ); - $app->GET( - '/v2/pet/{petId}', - PetApi::class . ':getPetById' - ); - $app->POST( - '/v2/pet/{petId}', - PetApi::class . ':updatePetWithForm' - ); - $app->POST( - '/v2/pet/{petId}/uploadImage', - PetApi::class . ':uploadFile' - ); - $app->POST( - '/v2/fake/{petId}/uploadImageWithRequiredFile', - PetApi::class . ':uploadFileWithRequiredFile' - ); - $app->GET( - '/v2/store/inventory', - StoreApi::class . ':getInventory' - ); - $app->POST( - '/v2/store/order', - StoreApi::class . ':placeOrder' - ); - $app->DELETE( - '/v2/store/order/{order_id}', - StoreApi::class . ':deleteOrder' - ); - $app->GET( - '/v2/store/order/{order_id}', - StoreApi::class . ':getOrderById' - ); - $app->POST( - '/v2/user', - UserApi::class . ':createUser' - ); - $app->POST( - '/v2/user/createWithArray', - UserApi::class . ':createUsersWithArrayInput' - ); - $app->POST( - '/v2/user/createWithList', - UserApi::class . ':createUsersWithListInput' - ); - $app->GET( - '/v2/user/login', - UserApi::class . ':loginUser' - ); - $app->GET( - '/v2/user/logout', - UserApi::class . ':logoutUser' - ); - $app->DELETE( - '/v2/user/{username}', - UserApi::class . ':deleteUser' - ); - $app->GET( - '/v2/user/{username}', - UserApi::class . ':getUserByName' - ); - $app->PUT( - '/v2/user/{username}', - UserApi::class . ':updateUser' - ); + 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); + return $response->withStatus(501)->write($message); + }; + $middlewares = []; - $this->slimApp = $app; + if (class_exists("\\{$operation['apiPackage']}\\{$operation['userClassname']}")) { + $callback = "\\{$operation['apiPackage']}\\{$operation['userClassname']}:{$operation['operationId']}"; + } + + + foreach ($operation['authMethods'] as $authMethod) { + if ($authMethod['type'] === 'http') { + $middlewares[] = $basicAuth; + } + } + + $this->addRoute( + [$operation['httpMethod']], + "{$operation['basePathWithoutHost']}{$operation['path']}", + $callback, + $middlewares + )->setName($operation['operationId']); + } + } + + /** + * Add route with multiple methods + * + * @param string[] $methods Numeric array of HTTP method names + * @param string $pattern The route URI pattern + * @param callable|string $callable The route callback routine + * @param array|null $middlewares List of middlewares + * + * @return Slim\Interfaces\RouteInterface + * + * @throws InvalidArgumentException if the route pattern isn't a string + */ + public function addRoute($methods, $pattern, $callable, $middlewares = []) + { + $route = $this->slimApp->map($methods, $pattern, $callable); + foreach ($middlewares as $middleware) { + $route->add($middleware); + } + return $route; } /** diff --git a/samples/server/petstore/php-slim/test/Api/AnotherFakeApiTest.php b/samples/server/petstore/php-slim/test/Api/AnotherFakeApiTest.php index a41b3878aa8..768b017a867 100644 --- a/samples/server/petstore/php-slim/test/Api/AnotherFakeApiTest.php +++ b/samples/server/petstore/php-slim/test/Api/AnotherFakeApiTest.php @@ -35,7 +35,7 @@ use OpenAPIServer\Api\AnotherFakeApi; * @package OpenAPIServer\Api * @author OpenAPI Generator team * @link https://github.com/openapitools/openapi-generator - * @coversDefaultClass \OpenAPIServer\Model\AnotherFakeApi + * @coversDefaultClass \OpenAPIServer\Api\AnotherFakeApi */ class AnotherFakeApiTest extends TestCase { diff --git a/samples/server/petstore/php-slim/test/Api/FakeApiTest.php b/samples/server/petstore/php-slim/test/Api/FakeApiTest.php index 76347875b33..5b5146ec853 100644 --- a/samples/server/petstore/php-slim/test/Api/FakeApiTest.php +++ b/samples/server/petstore/php-slim/test/Api/FakeApiTest.php @@ -35,7 +35,7 @@ use OpenAPIServer\Api\FakeApi; * @package OpenAPIServer\Api * @author OpenAPI Generator team * @link https://github.com/openapitools/openapi-generator - * @coversDefaultClass \OpenAPIServer\Model\FakeApi + * @coversDefaultClass \OpenAPIServer\Api\FakeApi */ class FakeApiTest extends TestCase { @@ -158,6 +158,16 @@ class FakeApiTest extends TestCase { } + /** + * Test case for testGroupParameters + * + * Fake endpoint to test group parameters (optional). + * @covers ::testGroupParameters + */ + public function testTestGroupParameters() + { + } + /** * Test case for testInlineAdditionalProperties * diff --git a/samples/server/petstore/php-slim/test/Api/FakeClassnameTags123ApiTest.php b/samples/server/petstore/php-slim/test/Api/FakeClassnameTags123ApiTest.php index 5fce14937ef..c64a2428151 100644 --- a/samples/server/petstore/php-slim/test/Api/FakeClassnameTags123ApiTest.php +++ b/samples/server/petstore/php-slim/test/Api/FakeClassnameTags123ApiTest.php @@ -35,7 +35,7 @@ use OpenAPIServer\Api\FakeClassnameTags123Api; * @package OpenAPIServer\Api * @author OpenAPI Generator team * @link https://github.com/openapitools/openapi-generator - * @coversDefaultClass \OpenAPIServer\Model\FakeClassnameTags123Api + * @coversDefaultClass \OpenAPIServer\Api\FakeClassnameTags123Api */ class FakeClassnameTags123ApiTest extends TestCase { diff --git a/samples/server/petstore/php-slim/test/Api/PetApiTest.php b/samples/server/petstore/php-slim/test/Api/PetApiTest.php index b6849de70b3..764761c9d7f 100644 --- a/samples/server/petstore/php-slim/test/Api/PetApiTest.php +++ b/samples/server/petstore/php-slim/test/Api/PetApiTest.php @@ -35,7 +35,7 @@ use OpenAPIServer\Api\PetApi; * @package OpenAPIServer\Api * @author OpenAPI Generator team * @link https://github.com/openapitools/openapi-generator - * @coversDefaultClass \OpenAPIServer\Model\PetApi + * @coversDefaultClass \OpenAPIServer\Api\PetApi */ class PetApiTest extends TestCase { diff --git a/samples/server/petstore/php-slim/test/Api/StoreApiTest.php b/samples/server/petstore/php-slim/test/Api/StoreApiTest.php index edc3c6a0e75..306e9e7e46b 100644 --- a/samples/server/petstore/php-slim/test/Api/StoreApiTest.php +++ b/samples/server/petstore/php-slim/test/Api/StoreApiTest.php @@ -35,7 +35,7 @@ use OpenAPIServer\Api\StoreApi; * @package OpenAPIServer\Api * @author OpenAPI Generator team * @link https://github.com/openapitools/openapi-generator - * @coversDefaultClass \OpenAPIServer\Model\StoreApi + * @coversDefaultClass \OpenAPIServer\Api\StoreApi */ class StoreApiTest extends TestCase { diff --git a/samples/server/petstore/php-slim/test/Api/UserApiTest.php b/samples/server/petstore/php-slim/test/Api/UserApiTest.php index a1d09015bb0..9dd3247ec8e 100644 --- a/samples/server/petstore/php-slim/test/Api/UserApiTest.php +++ b/samples/server/petstore/php-slim/test/Api/UserApiTest.php @@ -35,7 +35,7 @@ use OpenAPIServer\Api\UserApi; * @package OpenAPIServer\Api * @author OpenAPI Generator team * @link https://github.com/openapitools/openapi-generator - * @coversDefaultClass \OpenAPIServer\Model\UserApi + * @coversDefaultClass \OpenAPIServer\Api\UserApi */ class UserApiTest extends TestCase { diff --git a/samples/server/petstore/php-slim/test/Model/AnimalFarmTest.php b/samples/server/petstore/php-slim/test/Model/AnimalFarmTest.php deleted file mode 100644 index 7177a6d1a0e..00000000000 --- a/samples/server/petstore/php-slim/test/Model/AnimalFarmTest.php +++ /dev/null @@ -1,78 +0,0 @@ -