diff --git a/composer.json b/composer.json index c7e871dd7..9a51da83f 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,6 @@ "ext-mbstring": "*", "ext-openssl": "*", "clio/clio": "@stable", - "doctrine/annotations": "^1.11.1", "egulias/email-validator": "^2.1.10", "gettext/gettext": "^4.6.0", "laminas/laminas-diactoros": "^2.2", @@ -37,8 +36,7 @@ "symfony/process": "~5.1", "symfony/psr-http-message-bridge": "~2.0", "symfony/var-dumper": "~5.1", - "vlucas/phpdotenv": "~4.1.0", - "zircote/swagger-php": "^3.1.0" + "vlucas/phpdotenv": "~4.1.0" }, "replace": { "leevel/auth": "self.version", diff --git a/src/Leevel/Router/Matching/PathInfo.php b/src/Leevel/Router/Matching/PathInfo.php index 2e5c97dd4..eff8b53c8 100644 --- a/src/Leevel/Router/Matching/PathInfo.php +++ b/src/Leevel/Router/Matching/PathInfo.php @@ -94,7 +94,7 @@ protected function matchApp(array $path): array } /** - * 匹配路由 Mvc. + * 匹配路由 MVC. */ protected function matchMvc(array $path): array { diff --git a/src/Leevel/Router/OpenApiRouter.php b/src/Leevel/Router/OpenApiRouter.php index 7e35ee0a9..041d07cb5 100644 --- a/src/Leevel/Router/OpenApiRouter.php +++ b/src/Leevel/Router/OpenApiRouter.php @@ -21,21 +21,19 @@ namespace Leevel\Router; use InvalidArgumentException; +use Leevel\Kernel\Utils\ClassParser; use function Leevel\Support\Arr\normalize; use Leevel\Support\Arr\normalize; use function Leevel\Support\Type\arr; use Leevel\Support\Type\arr; -use OpenApi\Annotations\OpenApi; -use OpenApi\Annotations\PathItem; -use OpenApi\Context; -use function OpenApi\scan; +use ReflectionClass; +use Symfony\Component\Finder\Finder; /** - * OpenApi 注解路由. + * 注解路由. * - * - 忽略已删除的路由 deprecated 和带有 leevelIgnore 的路由. - * - 如果没有绑定路由参数 leevelBind,系统会尝试自动解析注解所在控制器方法. - * - 只支持最新的 zircote/swagger-php 3,支持最新的 OpenApi 3.0 规范. + * - 1.1.0-alpha2 之前在最新的 zircote/swagger-php 3 上构建的路由,支持最新的 OpenApi 3.0 规范. + * - 新版本采用 PHP 8 属性作为数据源提供。 */ class OpenApiRouter { @@ -120,7 +118,7 @@ public function __construct(MiddlewareParser $middlewareParser, ?string $domain public function addScandir(string $dir): void { if (!is_dir($dir)) { - $e = sprintf('OpenApi scandir %s is exits.', $dir); + $e = sprintf('Annotation routing scandir %s is not exits.', $dir); throw new InvalidArgumentException($e); } @@ -129,22 +127,29 @@ public function addScandir(string $dir): void } /** - * 处理 OpenApi 注解路由. + * 查找视图目录中的视图文件. */ - public function handle(): array + protected function findFiles(array $paths): Finder { - // 忽略 OpenApi 扩展字段警告,改变 set_error_handler 抛出时机 - // 补充基于标准 OpenApi 路由,并可以扩展注解路由的功能 - $oldErrorReporting = error_reporting(); - error_reporting(E_ERROR | E_PARSE | E_STRICT); - - $openApi = $this->makeOpenApi(); - $routers = $this->normalizeFastRoute($this->parseRouters($openApi)); - $result = $this->packageRouters($routers); + return (new Finder()) + ->in($paths) + ->exclude(['vendor', 'node_modules']) + ->followLinks() + ->name('*.php') + ->sortByName() + ->files(); + } - error_reporting($oldErrorReporting); + /** + * 处理注解路由. + */ + public function handle(): array + { + $routers = $this->parseControllerAnnotationRouters(); + $routers = $this->parseRouters($routers); + $routers = $this->normalizeFastRoute($routers); - return $result; + return $this->packageRouters($routers); } /** @@ -153,46 +158,87 @@ public function handle(): array protected function packageRouters(array $routers): array { return [ - 'base_paths' => $this->basePaths, - 'groups' => $this->groups, - 'routers' => $routers, + 'base_paths' => $this->basePaths, + 'groups' => $this->groups, + 'routers' => $routers, ]; } /** - * 解析路由. + * 分析控制器注解路由. */ - protected function parseRouters(OpenApi $openApi): array + protected function parseControllerAnnotationRouters(): array { + $finder = $this->findFiles($this->scandirs); + $classParser = new ClassParser(); $routers = []; - if ($openApi->paths) { - foreach ($openApi->paths as $path) { - $routers = $this->parseOpenApiPath($path, $routers); + foreach ($finder as $file) { + $content = file_get_contents($file->getRealPath()); + if (false !== strpos($content, '#[Route(')) { + $controllerClassName = $classParser->handle($file->getRealPath()); + $this->parseEachControllerAnnotationRouters($routers, $controllerClassName); + } + } + + return $routers; + } + + /** + * 分析每一个控制器注解路由. + */ + protected function parseEachControllerAnnotationRouters(array &$routers, string $controllerClassName): void + { + $ref = new ReflectionClass($controllerClassName); + $routeAttribute = (substr($controllerClassName, 0, strrpos($controllerClassName, '\\')).'\\Route'); + foreach ($ref->getMethods() as $v) { + if($routeAttributes = $v->getAttributes($routeAttribute)) { + $temp = $routeAttributes[0]->getArguments(); + if (empty($temp['method'])) { + $temp['method'] = 'get'; + } + $temp['method'] = strtolower($temp['method']); + if (!array_key_exists('bind', $temp)) { + $temp['bind'] = $controllerClassName.'@'.$v->getName(); + } + if ($temp['bind']) { + $temp['bind'] = '\\'.trim($temp['bind'], '\\'); + } + $routers[$temp['method']][] = $temp; } } + } + + /** + * 解析路由. + */ + protected function parseRouters(array $result): array + { + $routers = []; + foreach ($result as $httpMethod => $items) { + $this->parseHttpMethodAnnotationRouters($routers, $httpMethod, $items); + } return $routers; } /** - * 解析 openApi 每一项路径. + * 解析 HTTP 不同类型请求路由. */ - protected function parseOpenApiPath(PathItem $path, array $routers): array + protected function parseHttpMethodAnnotationRouters(array &$routers, string $httpMethod, array $annotationRouters): void { - foreach ($this->methods as $m) { - $method = $path->{$m}; + if (!in_array($httpMethod, $this->methods, true)) { + return; + } + foreach ($annotationRouters as $router) { // 忽略已删除和带有忽略标记的路由 - if ($this->isRouterIgnore($method, $path->path)) { + if ($this->isRouterIgnore($sourceRouterPath = $router['path'])) { continue; } // 支持的自定义路由字段 - $router = $this->parseRouterField($method); - - // 根据源代码生成绑定 - $this->parseRouterBind($method, $router); - + $router = $this->parseRouterField($router); + // 解析中间件 $this->parseRouterMiddlewares($router); @@ -203,68 +249,45 @@ protected function parseOpenApiPath(PathItem $path, array $routers): array $this->parseRouterPort($router); // 解析基础路径 - list($prefix, $groupPrefix, $routerPath) = $this->parseRouterPath($path->path, $this->groups); + list($prefix, $groupPrefix, $routerPath) = $this->parseRouterPath($sourceRouterPath, $this->groups); // 解析路由正则 if ($this->isStaticRouter($routerPath)) { - $routers[$m]['static'][$routerPath] = $router; + \ksort($router); + $routers[$httpMethod]['static'][$routerPath] = $router; } else { - $routers[$m][$prefix][$groupPrefix][$routerPath] = - $this->parseRouterRegex($routerPath, $router); + $router = $this->parseRouterRegex($routerPath, $router); + \ksort($router); + $routers[$httpMethod][$prefix][$groupPrefix][$routerPath] = $router; } } - - return $routers; } /** * 判断是否为忽略路由. + * + * - 首页 `/` 默认提供 Home::index 需要过滤 */ - protected function isRouterIgnore(object|string $method, string $path): bool + protected function isRouterIgnore(string $path): bool { - if (!is_object($method) || true === $method->deprecated || - (property_exists($method, 'leevelIgnore') && $method->leevelIgnore)) { - return true; - } - - // 首页 `/` 默认提供 Home::index 需要过滤 - if ('//' === $this->normalizePath($path)) { - return true; - } - - return false; + return '//' === $this->normalizePath($path); } /** * 解析自定义路由字段. */ - protected function parseRouterField(object $method): array + protected function parseRouterField(array $method): array { $result = []; foreach ($this->routerField as $f) { - $field = 'leevel'.ucfirst($f); - if (property_exists($method, $field)) { - $result[$f] = $method->{$field}; + if (array_key_exists($f, $method)) { + $result[$f] = $method[$f]; } } return $result; } - /** - * 解析路由绑定. - */ - protected function parseRouterBind(object $method, array &$router): void - { - if (empty($router['bind'])) { - $router['bind'] = $this->parseBindBySource($method->_context); - } - - if ($router['bind']) { - $router['bind'] = '\\'.trim($router['bind'], '\\'); - } - } - /** * 解析基础路径和分组. * @@ -403,7 +426,6 @@ protected function parseGroupRegex(array $routers): array $ruleMap = []; $ruleKey = 0; $regex[] = '~^(?'; - foreach ($routers as $key => $router) { $countVar = $minCount + $ruleKey; $emptyMatche = $countVar - count($router['var']); @@ -411,13 +433,9 @@ protected function parseGroupRegex(array $routers): array $regex[] = '|'.$router['regex'].($emptyMatche ? str_repeat('()', $emptyMatche) : ''); $ruleKey++; } - $regex[] = ')$~x'; - return [ - implode('', $regex), - $ruleMap, - ]; + return [implode('', $regex), $ruleMap]; } /** @@ -435,18 +453,6 @@ protected function computeMinCountVar(array $routers): int return $minCount; } - /** - * 根据源代码生成绑定. - */ - protected function parseBindBySource(Context $context): ?string - { - if (!$context->class || !$context->method) { - return null; - } - - return $context->fullyQualifiedName($context->class).'@'.$context->method; - } - /** * 格式化正则. */ @@ -559,7 +565,6 @@ protected function filterBasePath(array &$basePath): void if (empty($basePath['middlewares']['handle'])) { unset($basePath['middlewares']['handle']); } - if (empty($basePath['middlewares']['terminate'])) { unset($basePath['middlewares']['terminate']); } @@ -588,14 +593,6 @@ protected function prepareRegexForWildcard(string $regex): string return $regex; } - - /** - * 生成 OpenApi. - */ - protected function makeOpenApi(): OpenApi - { - return scan($this->scandirs); - } } // import fn. diff --git a/src/Leevel/Router/composer.json b/src/Leevel/Router/composer.json index 85bed2591..bb58a54b1 100644 --- a/src/Leevel/Router/composer.json +++ b/src/Leevel/Router/composer.json @@ -18,9 +18,8 @@ "leevel/pipeline": "1.1.*", "leevel/di": "1.1.*", "leevel/filesystem": "1.1.*", - "zircote/swagger-php": "^3.1.0", - "doctrine/annotations": "^1.11.1", - "symfony/http-foundation": "~5.1" + "symfony/http-foundation": "~5.1", + "symfony/finder": "~5.1" }, "autoload": { "psr-4": { diff --git a/tests/Router/Apps/AppForAnnotation/Controllers/BasePath.php b/tests/Router/Apps/AppForAnnotation/Controllers/BasePath.php index bf4d84c83..d89f1dde7 100644 --- a/tests/Router/Apps/AppForAnnotation/Controllers/BasePath.php +++ b/tests/Router/Apps/AppForAnnotation/Controllers/BasePath.php @@ -22,34 +22,11 @@ class BasePath { - /** - * @OA\Get( - * path="/basePath/normalize/", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelBind="Tests\Router\Controllers\Annotation\BasePath@normalize" - * ) - */ - public function foo() + #[Route( + path: "/basePath/normalize/", + bind: "\\Tests\\Router\\Controllers\\Annotation\\BasePath@normalize", + )] + private function foo(): void { } } diff --git a/tests/Router/Apps/AppForAnnotation/Controllers/BindNotFound.php b/tests/Router/Apps/AppForAnnotation/Controllers/BindNotFound.php index 1c36e65b0..cb2b8eade 100644 --- a/tests/Router/Apps/AppForAnnotation/Controllers/BindNotFound.php +++ b/tests/Router/Apps/AppForAnnotation/Controllers/BindNotFound.php @@ -22,96 +22,27 @@ class BindNotFound { - /** - * @OA\Get( - * path="/bindNotFound/test/", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelBind="Tests\Router\Controllers\Annotation\BindNotFound@notFound" - * ) - */ - public function foo() + #[Route( + path: "/bindNotFound/test/", + bind: "\\Tests\\Router\\Controllers\\Annotation\\BindNotFound@notFound", + )] + private function foo(): void { } - /** - * @OA\Get( - * path="/bindNotFound/test2/", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelBind="Tests\Router\Controllers\Annotation\BindNotFound" - * ) - */ - public function bar() + #[Route( + path: "/bindNotFound/test2/", + bind: "\\Tests\\Router\\Controllers\\Annotation\\BindNotFound", + )] + private function bar(): void { } - /** - * @OA\Get( - * path="/bindNotFound/test3/", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelBind="Tests\Router\Controllers\Annotation\BindMethodNotFound" - * ) - */ - public function bar3() + #[Route( + path: "/bindNotFound/test3/", + bind: "\\Tests\\Router\\Controllers\\Annotation\\BindMethodNotFound", + )] + private function bar3(): void { } } diff --git a/tests/Router/Apps/AppForAnnotation/Controllers/BindNotSet.php b/tests/Router/Apps/AppForAnnotation/Controllers/BindNotSet.php index 8d8c2cd86..c57ea79d6 100644 --- a/tests/Router/Apps/AppForAnnotation/Controllers/BindNotSet.php +++ b/tests/Router/Apps/AppForAnnotation/Controllers/BindNotSet.php @@ -18,63 +18,24 @@ * file that was distributed with this source code. */ -/** - * @OA\Get( - * path="/bindNotSet/test", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"} - * ) - */ -function foo() -{ -} +namespace Tests\Router\Apps\AppForAnnotation\Controllers; -/** - * @OA\Get( - * path="/bindNotSet/test2", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelBind="" - * ) - */ -function bar() +class BindNotSet { + #[Route( + path: "/bindNotSet/test", + bind: null, + )] + private function routePlaceholderFoo(): void + { + } + + #[Route( + path: "/bindNotSet/test2", + bind: "", + )] + private function routePlaceholderBar(): void + { + } } + diff --git a/tests/Router/Apps/AppForAnnotation/Controllers/Domain.php b/tests/Router/Apps/AppForAnnotation/Controllers/Domain.php index f0f33ee9d..46081e4a4 100644 --- a/tests/Router/Apps/AppForAnnotation/Controllers/Domain.php +++ b/tests/Router/Apps/AppForAnnotation/Controllers/Domain.php @@ -24,130 +24,38 @@ class Domain { - /** - * @OA\Get( - * path="/domain/test", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelDomain="queryphp.com" - * ) - */ - public function fooNotMatchedDomain() + #[Route( + path: "/domain/test", + domain: "queryphp.com", + )] + private function fooNotMatchedDomain(): void { } - /** - * @OA\Get( - * path="/domain/test2", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelDomain="queryphp.com" - * ) - */ - public function barMatchedDomain() + #[Route( + path: "/domain/test2", + domain: "queryphp.com", + )] + public function barMatchedDomain(): string { return 'barMatchedDomain'; } - /** - * @OA\Get( - * path="/domain/test3", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelDomain="{subdomain:[A-Za-z]+}-vip.{domain}.queryphp.com" - * ) - */ - public function barMatchedDomainWithVar(Request $request) + #[Route( + path: "/domain/test3", + domain: "{subdomain:[A-Za-z]+}-vip.{domain}.queryphp.com", + )] + public function barMatchedDomainWithVar(Request $request): string { return 'barMatchedDomainWithVar and attributes are '. json_encode($request->attributes->all()); } - /** - * @OA\Get( - * path="/domain/test4", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelDomain="api" - * ) - */ - public function barMatchedDomainWithoutExtend() + #[Route( + path: "/domain/test4", + domain: "api", + )] + public function barMatchedDomainWithoutExtend(): string { return 'barMatchedDomainWithoutExtend'; } diff --git a/tests/Router/Apps/AppForAnnotation/Controllers/ExtendVar.php b/tests/Router/Apps/AppForAnnotation/Controllers/ExtendVar.php index 7ad5b7883..941e092b3 100644 --- a/tests/Router/Apps/AppForAnnotation/Controllers/ExtendVar.php +++ b/tests/Router/Apps/AppForAnnotation/Controllers/ExtendVar.php @@ -24,34 +24,11 @@ class ExtendVar { - /** - * @OA\Get( - * path="/extendVar/test", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelAttributes={"args1": "hello", "args2": "world"} - * ) - */ - public function withExtendVar(Request $request) + #[Route( + path: "/extendVar/test", + attributes: ["args1" => "hello", "args2" => "world"], + )] + public function withExtendVar(Request $request): string { return 'withExtendVar and attributes are '. json_encode($request->attributes->all()); diff --git a/tests/Router/Apps/AppForAnnotation/Controllers/Middleware.php b/tests/Router/Apps/AppForAnnotation/Controllers/Middleware.php index 2da9708d4..15f2e5d18 100644 --- a/tests/Router/Apps/AppForAnnotation/Controllers/Middleware.php +++ b/tests/Router/Apps/AppForAnnotation/Controllers/Middleware.php @@ -22,130 +22,38 @@ class Middleware { - /** - * @OA\Get( - * path="/middleware/test", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelMiddlewares="group1" - * ) - */ - public function foo() + #[Route( + path: "/middleware/test", + middlewares: "group1", + )] + public function foo(): string { return 'Middleware matched'; } - /** - * @OA\Get( - * path="/middleware/test2", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelMiddlewares={"group1", "group2"} - * ) - */ - public function bar() + #[Route( + path: "/middleware/test2", + middlewares: ["group1", "group2"], + )] + public function bar(): string { return 'Middleware matched 2'; } - /** - * @OA\Get( - * path="/middleware/test3", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelMiddlewares={"group1", "group2", "demo_for_base_path"} - * ) - */ - public function hello() + #[Route( + path: "/middleware/test3", + middlewares: ["group1", "group2", "demo_for_base_path"], + )] + public function hello(): string { return 'Middleware matched 3'; } - /** - * @OA\Get( - * path="/middleware/test4", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelMiddlewares={"Tests\Router\Middlewares\Demo1"} - * ) - */ - public function world() + #[Route( + path: "/middleware/test4", + middlewares: ["Tests\\Router\\Middlewares\\Demo1"], + )] + public function world(): string { return 'Middleware matched 4'; } diff --git a/tests/Router/Apps/AppForAnnotation/Controllers/Pet.php b/tests/Router/Apps/AppForAnnotation/Controllers/Pet.php index baeb6b73b..bc42c00c0 100644 --- a/tests/Router/Apps/AppForAnnotation/Controllers/Pet.php +++ b/tests/Router/Apps/AppForAnnotation/Controllers/Pet.php @@ -20,103 +20,29 @@ namespace Tests\Router\Apps\AppForAnnotation\Controllers; -/** - * Class Pet. - * - * @author Donii Sergii - */ class Pet { - /** - * @OA\Get( - * path="/api/v1/petLeevel/{petId:[A-Za-z]+}/", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelBind="\Tests\Router\Controllers\Annotation\PetLeevel" - * ) - */ - public function petLeevel() + #[Route( + path: "/api/v1/petLeevel/{petId:[A-Za-z]+}/", + bind: "\\Tests\\Router\\Controllers\\Annotation\\PetLeevel", + )] + private function petLeevel(): void { } - /** - * @OA\Get( - * path="/api/notInGroup/petLeevel/{petId:[A-Za-z]+}/", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * ) - */ + #[Route( + path: "/api/notInGroup/petLeevel/{petId:[A-Za-z]+}/", + )] public function petLeevelNotInGroup(): string { return 'petLeevelNotInGroup'; } - /** - * @OA\Get( - * path="/newPrefix/v1/petLeevel/{petId:[A-Za-z]+}/", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelBind="\Tests\Router\Controllers\Annotation\NewPrefix" - * ) - */ - public function newPrefix(): void + #[Route( + path: "/newPrefix/v1/petLeevel/{petId:[A-Za-z]+}/", + bind: "\\Tests\\Router\\Controllers\\Annotation\\NewPrefix", + )] + private function newPrefix(): void { } } diff --git a/tests/Router/Apps/AppForAnnotation/Controllers/Port.php b/tests/Router/Apps/AppForAnnotation/Controllers/Port.php index c2f259999..695926763 100644 --- a/tests/Router/Apps/AppForAnnotation/Controllers/Port.php +++ b/tests/Router/Apps/AppForAnnotation/Controllers/Port.php @@ -22,65 +22,19 @@ class Port { - /** - * @OA\Get( - * path="/port/test", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelPort=9527 - * ) - */ - public function fooNotMatchedPort() + #[Route( + path: "/port/test", + port: "9527", + )] + private function fooNotMatchedPort(): void { } - /** - * @OA\Get( - * path="/port/test2", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelPort=9527 - * ) - */ - public function barMatchedPort() + #[Route( + path: "/port/test2", + port: "9527", + )] + public function barMatchedPort(): string { return 'barMatchedPort'; } diff --git a/tests/Router/Apps/AppForAnnotation/Controllers/Scheme.php b/tests/Router/Apps/AppForAnnotation/Controllers/Scheme.php index 12f138132..23fbee1f2 100644 --- a/tests/Router/Apps/AppForAnnotation/Controllers/Scheme.php +++ b/tests/Router/Apps/AppForAnnotation/Controllers/Scheme.php @@ -22,65 +22,19 @@ class Scheme { - /** - * @OA\Get( - * path="/scheme/test", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelScheme="https" - * ) - */ - public function fooNotMatchedScheme() + #[Route( + path: "/scheme/test", + scheme: "https", + )] + private function fooNotMatchedScheme(): void { } - /** - * @OA\Get( - * path="/scheme/test2", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelScheme="http" - * ) - */ - public function barMatchedScheme() + #[Route( + path: "/scheme/test2", + scheme: "http", + )] + public function barMatchedScheme(): string { return 'barMatchedScheme'; } diff --git a/tests/Router/Apps/AppForAnnotation/data.json b/tests/Router/Apps/AppForAnnotation/data.json index 0870489f6..a3fd5acbe 100644 --- a/tests/Router/Apps/AppForAnnotation/data.json +++ b/tests/Router/Apps/AppForAnnotation/data.json @@ -80,19 +80,19 @@ "bind": null }, "\/bindNotSet\/test2\/": { - "bind": null + "bind": "" }, "\/domain\/test\/": { - "domain": "queryphp.com", - "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Domain@fooNotMatchedDomain" + "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Domain@fooNotMatchedDomain", + "domain": "queryphp.com" }, "\/domain\/test2\/": { - "domain": "queryphp.com", - "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Domain@barMatchedDomain" + "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Domain@barMatchedDomain", + "domain": "queryphp.com" }, "\/domain\/test3\/": { - "domain": "{subdomain:[A-Za-z]+}-vip.{domain}.queryphp.com", "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Domain@barMatchedDomainWithVar", + "domain": "{subdomain:[A-Za-z]+}-vip.{domain}.queryphp.com", "domain_regex": "\/^([A-Za-z]+)\\-vip\\.(\\S+)\\.queryphp\\.com$\/", "domain_var": [ "subdomain", @@ -100,8 +100,8 @@ ] }, "\/domain\/test4\/": { - "domain": "api.queryphp.com", - "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Domain@barMatchedDomainWithoutExtend" + "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Domain@barMatchedDomainWithoutExtend", + "domain": "api.queryphp.com" }, "\/extendVar\/test\/": { "attributes": { @@ -111,6 +111,7 @@ "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\ExtendVar@withExtendVar" }, "\/middleware\/test\/": { + "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Middleware@foo", "middlewares": { "handle": [ "Tests\\Router\\Middlewares\\Demo2@handle" @@ -119,10 +120,10 @@ "Tests\\Router\\Middlewares\\Demo1@terminate", "Tests\\Router\\Middlewares\\Demo2@terminate" ] - }, - "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Middleware@foo" + } }, "\/middleware\/test2\/": { + "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Middleware@bar", "middlewares": { "handle": [ "Tests\\Router\\Middlewares\\Demo2@handle", @@ -132,10 +133,10 @@ "Tests\\Router\\Middlewares\\Demo1@terminate", "Tests\\Router\\Middlewares\\Demo2@terminate" ] - }, - "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Middleware@bar" + } }, "\/middleware\/test3\/": { + "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Middleware@hello", "middlewares": { "handle": [ "Tests\\Router\\Middlewares\\Demo2@handle", @@ -146,33 +147,32 @@ "Tests\\Router\\Middlewares\\Demo1@terminate", "Tests\\Router\\Middlewares\\Demo2@terminate" ] - }, - "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Middleware@hello" + } }, "\/middleware\/test4\/": { + "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Middleware@world", "middlewares": { "handle": [], "terminate": [ "Tests\\Router\\Middlewares\\Demo1@terminate" ] - }, - "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Middleware@world" + } }, "\/port\/test\/": { - "port": 9527, - "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Port@fooNotMatchedPort" + "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Port@fooNotMatchedPort", + "port": 9527 }, "\/port\/test2\/": { - "port": 9527, - "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Port@barMatchedPort" + "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Port@barMatchedPort", + "port": 9527 }, "\/scheme\/test\/": { - "scheme": "https", - "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Scheme@fooNotMatchedScheme" + "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Scheme@fooNotMatchedScheme", + "scheme": "https" }, "\/scheme\/test2\/": { - "scheme": "http", - "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Scheme@barMatchedScheme" + "bind": "\\Tests\\Router\\Apps\\AppForAnnotation\\Controllers\\Scheme@barMatchedScheme", + "scheme": "http" } }, "a": { diff --git a/tests/Router/Apps/AppForAnnotation/models/Petstore/ApiResponse.php b/tests/Router/Apps/AppForAnnotation/models/Petstore/ApiResponse.php deleted file mode 100644 index 3e52ecfed..000000000 --- a/tests/Router/Apps/AppForAnnotation/models/Petstore/ApiResponse.php +++ /dev/null @@ -1,66 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Petstore; - -/** - * Class ApiResponse. - * - * @author Donii Sergii - * - * @OA\Schema( - * type="object", - * description="Api response", - * title="Api response" - * ) - */ -class ApiResponse -{ - /** - * @OA\Property( - * description="Code", - * title="Code", - * format="int32" - * ) - * - * @var int - */ - private $code; - - /** - * OAS\Property( - * description="Type", - * title="Type", - * ). - * - * @var string - */ - private $type; - - /** - * @OA\Property( - * description="Message", - * title="Message" - * ) - * - * @var string - */ - private $message; -} diff --git a/tests/Router/Apps/AppForAnnotation/router.php b/tests/Router/Apps/AppForAnnotation/router.php deleted file mode 100644 index 2860d5209..000000000 --- a/tests/Router/Apps/AppForAnnotation/router.php +++ /dev/null @@ -1,75 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -/** - * @OA\Info( - * description="This is a sample Petstore server. You can find - * out more about Swagger at - * [http://swagger.io](http://swagger.io) or on - * [irc.freenode.net, #swagger](http://swagger.io/irc/).", - * version="1.0.0", - * title="Swagger Petstore", - * termsOfService="http://swagger.io/terms/", - * @OA\Contact( - * email="apiteam@swagger.io" - * ), - * @OA\License( - * name="Apache 2.0", - * url="http://www.apache.org/licenses/LICENSE-2.0.html" - * ) - * ) - */ -class _ -{ -} - -/** - * @OA\Tag( - * name="pet", - * description="Everything about your Pets", - * @OA\ExternalDocumentation( - * description="Find out more", - * url="http://swagger.io" - * ) - * ) - * @OA\Tag( - * name="store", - * description="Access to Petstore orders", - * ) - * @OA\Tag( - * name="user", - * description="Operations about user", - * @OA\ExternalDocumentation( - * description="Find out more about store", - * url="http://swagger.io" - * ) - * ) - * @OA\Server( - * description="SwaggerHUB API Mocking", - * url="https://virtserver.swaggerhub.com/swagger/Petstore/1.0.0" - * ) - * @OA\ExternalDocumentation( - * description="Find out more about Swagger", - * url="http://swagger.io", - * ) - */ -class __ -{ -} diff --git a/tests/Router/Apps/AppForAnnotation/security.php b/tests/Router/Apps/AppForAnnotation/security.php deleted file mode 100644 index a6ca4aa08..000000000 --- a/tests/Router/Apps/AppForAnnotation/security.php +++ /dev/null @@ -1,44 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -/** - * @OA\SecurityScheme( - * type="oauth2", - * name="petstore_auth", - * securityScheme="petstore_auth", - * @OA\Flow( - * flow="implicit", - * authorizationUrl="http://petstore.swagger.io/oauth/dialog", - * scopes={ - * "write:pets": "modify pets in your account", - * "read:pets": "read your pets", - * } - * ) - * ) - * @OA\SecurityScheme( - * type="apiKey", - * in="header", - * securityScheme="api_key", - * name="api_key" - * ) - */ -class _ -{ -} diff --git a/tests/Router/Apps/AppGroup/Controllers/Pet.php b/tests/Router/Apps/AppGroup/Controllers/Pet.php index 1fd36c9c4..d9d0a6898 100644 --- a/tests/Router/Apps/AppGroup/Controllers/Pet.php +++ b/tests/Router/Apps/AppGroup/Controllers/Pet.php @@ -18,52 +18,14 @@ * file that was distributed with this source code. */ -namespace Tests\Router\Apps\AppWithoutExternalDocs\Controllers; +namespace Tests\Router\Apps\AppGroup\Controllers; -/** - * Class Pet. - * - * @author Donii Sergii - */ class Pet { - /** - * @OA\Get( - * path="/api/v1/petLeevel/{petId:[A-Za-z]+}/{petId2:[A-Za-z]+}/", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Parameter( - * name="petId2", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"} - * ) - */ - public function petLeevel() + #[Route( + path: "/api/v1/petLeevel/{petId:[A-Za-z]+}/{petId2:[A-Za-z]+}/", + )] + private function petLeevel(): void { } } diff --git a/tests/Router/Apps/AppGroup/models/Petstore/ApiResponse.php b/tests/Router/Apps/AppGroup/models/Petstore/ApiResponse.php deleted file mode 100644 index 3e52ecfed..000000000 --- a/tests/Router/Apps/AppGroup/models/Petstore/ApiResponse.php +++ /dev/null @@ -1,66 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Petstore; - -/** - * Class ApiResponse. - * - * @author Donii Sergii - * - * @OA\Schema( - * type="object", - * description="Api response", - * title="Api response" - * ) - */ -class ApiResponse -{ - /** - * @OA\Property( - * description="Code", - * title="Code", - * format="int32" - * ) - * - * @var int - */ - private $code; - - /** - * OAS\Property( - * description="Type", - * title="Type", - * ). - * - * @var string - */ - private $type; - - /** - * @OA\Property( - * description="Message", - * title="Message" - * ) - * - * @var string - */ - private $message; -} diff --git a/tests/Router/Apps/AppGroup/router.json b/tests/Router/Apps/AppGroup/router.json index 9f3368a5b..f2e49181f 100644 --- a/tests/Router/Apps/AppGroup/router.json +++ b/tests/Router/Apps/AppGroup/router.json @@ -10,7 +10,7 @@ "a": { "_": { "\/api\/v1\/petLeevel\/{petId:[A-Za-z]+}\/{petId2:[A-Za-z]+}\/": { - "bind": "\\Tests\\Router\\Apps\\AppWithoutExternalDocs\\Controllers\\Pet@petLeevel", + "bind": "\\Tests\\Router\\Apps\\AppGroup\\Controllers\\Pet@petLeevel", "var": [ "petId", "petId2" diff --git a/tests/Router/Apps/AppGroup/router.php b/tests/Router/Apps/AppGroup/router.php deleted file mode 100644 index 8ac7e2602..000000000 --- a/tests/Router/Apps/AppGroup/router.php +++ /dev/null @@ -1,71 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -/** - * @OA\Info( - * description="This is a sample Petstore server. You can find - * out more about Swagger at - * [http://swagger.io](http://swagger.io) or on - * [irc.freenode.net, #swagger](http://swagger.io/irc/).", - * version="1.0.0", - * title="Swagger Petstore", - * termsOfService="http://swagger.io/terms/", - * @OA\Contact( - * email="apiteam@swagger.io" - * ), - * @OA\License( - * name="Apache 2.0", - * url="http://www.apache.org/licenses/LICENSE-2.0.html" - * ) - * ) - */ -class _ -{ -} - -/** - * @OA\Tag( - * name="pet", - * description="Everything about your Pets", - * @OA\ExternalDocumentation( - * description="Find out more", - * url="http://swagger.io" - * ) - * ) - * @OA\Tag( - * name="store", - * description="Access to Petstore orders", - * ) - * @OA\Tag( - * name="user", - * description="Operations about user", - * @OA\ExternalDocumentation( - * description="Find out more about store", - * url="http://swagger.io" - * ) - * ) - * @OA\Server( - * description="SwaggerHUB API Mocking", - * url="https://virtserver.swaggerhub.com/swagger/Petstore/1.0.0" - * ) - */ -class __ -{ -} diff --git a/tests/Router/Apps/AppGroup/router/.gitkeep b/tests/Router/Apps/AppGroup/router/.gitkeep deleted file mode 100644 index 14badf807..000000000 --- a/tests/Router/Apps/AppGroup/router/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -Query Yet Simple \ No newline at end of file diff --git a/tests/Router/Apps/AppGroup/security.php b/tests/Router/Apps/AppGroup/security.php deleted file mode 100644 index a6ca4aa08..000000000 --- a/tests/Router/Apps/AppGroup/security.php +++ /dev/null @@ -1,44 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -/** - * @OA\SecurityScheme( - * type="oauth2", - * name="petstore_auth", - * securityScheme="petstore_auth", - * @OA\Flow( - * flow="implicit", - * authorizationUrl="http://petstore.swagger.io/oauth/dialog", - * scopes={ - * "write:pets": "modify pets in your account", - * "read:pets": "read your pets", - * } - * ) - * ) - * @OA\SecurityScheme( - * type="apiKey", - * in="header", - * securityScheme="api_key", - * name="api_key" - * ) - */ -class _ -{ -} diff --git a/tests/Router/Apps/AppScanRouter/Controllers/Pet.php b/tests/Router/Apps/AppScanRouter/Controllers/Pet.php index 33070b681..a72c64c7e 100644 --- a/tests/Router/Apps/AppScanRouter/Controllers/Pet.php +++ b/tests/Router/Apps/AppScanRouter/Controllers/Pet.php @@ -20,70 +20,20 @@ namespace Tests\Router\Apps\AppScanRouter\Controllers; -/** - * Class Pet. - * - * @author Donii Sergii - */ class Pet { - /** - * @OA\Get( - * path="/api/v1/petLeevel/{petId:[A-Za-z]+}/", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"} - * ) - */ - public function petLeevel() + #[Route( + path: "/api/v1/petLeevel/{petId:[A-Za-z]+}/", + )] + private function petLeevel(): void { } - /** - * @OA\Get( - * path="/web/petLeevelWithPort/", - * tags={"pet"}, - * summary="Just test ignore the router", - * operationId="petLeevelV2Web", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * leevelPort=9527, - * ) - */ - public function petLeevelWithPort() + #[Route( + path: "/web/petLeevelWithPort/", + port: "9527", + )] + private function petLeevelWithPort(): void { } } diff --git a/tests/Router/Apps/AppScanRouter/data.json b/tests/Router/Apps/AppScanRouter/data.json index 2edc703ba..4880b19f4 100644 --- a/tests/Router/Apps/AppScanRouter/data.json +++ b/tests/Router/Apps/AppScanRouter/data.json @@ -65,8 +65,8 @@ }, "static": { "\/web\/petLeevelWithPort\/": { - "port": 9527, - "bind": "\\Tests\\Router\\Apps\\AppScanRouter\\Controllers\\Pet@petLeevelWithPort" + "bind": "\\Tests\\Router\\Apps\\AppScanRouter\\Controllers\\Pet@petLeevelWithPort", + "port": 9527 } } } diff --git a/tests/Router/Apps/AppScanRouter/models/Petstore/ApiResponse.php b/tests/Router/Apps/AppScanRouter/models/Petstore/ApiResponse.php deleted file mode 100644 index 3e52ecfed..000000000 --- a/tests/Router/Apps/AppScanRouter/models/Petstore/ApiResponse.php +++ /dev/null @@ -1,66 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Petstore; - -/** - * Class ApiResponse. - * - * @author Donii Sergii - * - * @OA\Schema( - * type="object", - * description="Api response", - * title="Api response" - * ) - */ -class ApiResponse -{ - /** - * @OA\Property( - * description="Code", - * title="Code", - * format="int32" - * ) - * - * @var int - */ - private $code; - - /** - * OAS\Property( - * description="Type", - * title="Type", - * ). - * - * @var string - */ - private $type; - - /** - * @OA\Property( - * description="Message", - * title="Message" - * ) - * - * @var string - */ - private $message; -} diff --git a/tests/Router/Apps/AppScanRouter/router.php b/tests/Router/Apps/AppScanRouter/router.php deleted file mode 100644 index 2860d5209..000000000 --- a/tests/Router/Apps/AppScanRouter/router.php +++ /dev/null @@ -1,75 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -/** - * @OA\Info( - * description="This is a sample Petstore server. You can find - * out more about Swagger at - * [http://swagger.io](http://swagger.io) or on - * [irc.freenode.net, #swagger](http://swagger.io/irc/).", - * version="1.0.0", - * title="Swagger Petstore", - * termsOfService="http://swagger.io/terms/", - * @OA\Contact( - * email="apiteam@swagger.io" - * ), - * @OA\License( - * name="Apache 2.0", - * url="http://www.apache.org/licenses/LICENSE-2.0.html" - * ) - * ) - */ -class _ -{ -} - -/** - * @OA\Tag( - * name="pet", - * description="Everything about your Pets", - * @OA\ExternalDocumentation( - * description="Find out more", - * url="http://swagger.io" - * ) - * ) - * @OA\Tag( - * name="store", - * description="Access to Petstore orders", - * ) - * @OA\Tag( - * name="user", - * description="Operations about user", - * @OA\ExternalDocumentation( - * description="Find out more about store", - * url="http://swagger.io" - * ) - * ) - * @OA\Server( - * description="SwaggerHUB API Mocking", - * url="https://virtserver.swaggerhub.com/swagger/Petstore/1.0.0" - * ) - * @OA\ExternalDocumentation( - * description="Find out more about Swagger", - * url="http://swagger.io", - * ) - */ -class __ -{ -} diff --git a/tests/Router/Apps/AppWithControllerDirNotMatche/Controllers/Pet.php b/tests/Router/Apps/AppWithControllerDirNotMatche/Controllers/Pet.php index 267895c3f..dd03b8d92 100644 --- a/tests/Router/Apps/AppWithControllerDirNotMatche/Controllers/Pet.php +++ b/tests/Router/Apps/AppWithControllerDirNotMatche/Controllers/Pet.php @@ -20,40 +20,12 @@ namespace Tests\Router\Apps\AppWithControllerDirNotMatche\Controllers; -/** - * Class Pet. - * - * @author Donii Sergii - */ class Pet { - /** - * @OA\Get( - * path="/api/v1/petLeevel/{petId:[A-Za-z]+}/", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"} - * ) - */ - public function petLeevel() + #[Route( + path: "/api/v1/petLeevel/{petId:[A-Za-z]+}/", + )] + private function petLeevel(): void { } } diff --git a/tests/Router/Apps/AppWithControllerDirNotMatche/models/Petstore/ApiResponse.php b/tests/Router/Apps/AppWithControllerDirNotMatche/models/Petstore/ApiResponse.php deleted file mode 100644 index 3e52ecfed..000000000 --- a/tests/Router/Apps/AppWithControllerDirNotMatche/models/Petstore/ApiResponse.php +++ /dev/null @@ -1,66 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Petstore; - -/** - * Class ApiResponse. - * - * @author Donii Sergii - * - * @OA\Schema( - * type="object", - * description="Api response", - * title="Api response" - * ) - */ -class ApiResponse -{ - /** - * @OA\Property( - * description="Code", - * title="Code", - * format="int32" - * ) - * - * @var int - */ - private $code; - - /** - * OAS\Property( - * description="Type", - * title="Type", - * ). - * - * @var string - */ - private $type; - - /** - * @OA\Property( - * description="Message", - * title="Message" - * ) - * - * @var string - */ - private $message; -} diff --git a/tests/Router/Apps/AppWithControllerDirNotMatche/router.php b/tests/Router/Apps/AppWithControllerDirNotMatche/router.php deleted file mode 100644 index 2f72dc51c..000000000 --- a/tests/Router/Apps/AppWithControllerDirNotMatche/router.php +++ /dev/null @@ -1,75 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -/** - * @OA\Info( - * description="This is a sample Petstore server. You can find - * out more about Swagger at - * [http://swagger.io](http://swagger.io) or on - * [irc.freenode.net, #swagger](http://swagger.io/irc/).", - * version="1.0.0", - * title="Swagger Petstore", - * termsOfService="http://swagger.io/terms/", - * @OA\Contact( - * email="apiteam@swagger.io" - * ), - * @OA\License( - * name="Apache 2.0", - * url="http://www.apache.org/licenses/LICENSE-2.0.html" - * ) - * ) - */ -class _ -{ -} - -/** - * @OA\Tag( - * name="pet", - * description="Everything about your Pets", - * @OA\ExternalDocumentation( - * description="Find out more", - * url="http://swagger.io" - * ) - * ) - * @OA\Tag( - * name="store", - * description="Access to Petstore orders", - * ) - * @OA\Tag( - * name="user", - * description="Operations about user", - * @OA\ExternalDocumentation( - * description="Find out more about store", - * url="http://swagger.io" - * ) - * ) - * @OA\Server( - * description="SwaggerHUB API Mocking", - * url="https://virtserver.swaggerhub.com/swagger/Petstore/1.0.0" - * ) - * @OA\ExternalDocumentation( - * description="Find out more about Swagger", - * url="http://swagger.io" - * ) - */ -class __ -{ -} diff --git a/tests/Router/Apps/AppWithControllerDirNotMatche/router/.gitkeep b/tests/Router/Apps/AppWithControllerDirNotMatche/router/.gitkeep deleted file mode 100644 index 14badf807..000000000 --- a/tests/Router/Apps/AppWithControllerDirNotMatche/router/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -Query Yet Simple \ No newline at end of file diff --git a/tests/Router/Apps/AppWithControllerDirNotMatche/security.php b/tests/Router/Apps/AppWithControllerDirNotMatche/security.php deleted file mode 100644 index a6ca4aa08..000000000 --- a/tests/Router/Apps/AppWithControllerDirNotMatche/security.php +++ /dev/null @@ -1,44 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -/** - * @OA\SecurityScheme( - * type="oauth2", - * name="petstore_auth", - * securityScheme="petstore_auth", - * @OA\Flow( - * flow="implicit", - * authorizationUrl="http://petstore.swagger.io/oauth/dialog", - * scopes={ - * "write:pets": "modify pets in your account", - * "read:pets": "read your pets", - * } - * ) - * ) - * @OA\SecurityScheme( - * type="apiKey", - * in="header", - * securityScheme="api_key", - * name="api_key" - * ) - */ -class _ -{ -} diff --git a/tests/Router/Apps/AppScanRouter/security.php b/tests/Router/Apps/AppWithoutBasePaths/Controllers/Pet.php similarity index 57% rename from tests/Router/Apps/AppScanRouter/security.php rename to tests/Router/Apps/AppWithoutBasePaths/Controllers/Pet.php index a6ca4aa08..7f397dab6 100644 --- a/tests/Router/Apps/AppScanRouter/security.php +++ b/tests/Router/Apps/AppWithoutBasePaths/Controllers/Pet.php @@ -18,27 +18,14 @@ * file that was distributed with this source code. */ -/** - * @OA\SecurityScheme( - * type="oauth2", - * name="petstore_auth", - * securityScheme="petstore_auth", - * @OA\Flow( - * flow="implicit", - * authorizationUrl="http://petstore.swagger.io/oauth/dialog", - * scopes={ - * "write:pets": "modify pets in your account", - * "read:pets": "read your pets", - * } - * ) - * ) - * @OA\SecurityScheme( - * type="apiKey", - * in="header", - * securityScheme="api_key", - * name="api_key" - * ) - */ -class _ +namespace Tests\Router\Apps\AppWithoutBasePaths\Controllers; + +class Pet { + #[Route( + path: "/api/v1/petLeevel/{petId:[A-Za-z]+}/", + )] + private function demo(): void + { + } } diff --git a/tests/Router/Apps/AppWithoutLeevelBasePaths/router.json b/tests/Router/Apps/AppWithoutBasePaths/router.json similarity index 87% rename from tests/Router/Apps/AppWithoutLeevelBasePaths/router.json rename to tests/Router/Apps/AppWithoutBasePaths/router.json index 00d5dd940..567433ecb 100644 --- a/tests/Router/Apps/AppWithoutLeevelBasePaths/router.json +++ b/tests/Router/Apps/AppWithoutBasePaths/router.json @@ -10,7 +10,7 @@ "a": { "_": { "\/api\/v1\/petLeevel\/{petId:[A-Za-z]+}\/": { - "bind": null, + "bind": "\\Tests\\Router\\Apps\\AppWithoutBasePaths\\Controllers\\Pet@demo", "var": [ "petId" ] diff --git a/tests/Router/Apps/AppWithoutLeevelBasePaths/router_without_base_paths_and_groups.json b/tests/Router/Apps/AppWithoutBasePaths/router_without_base_paths_and_groups.json similarity index 86% rename from tests/Router/Apps/AppWithoutLeevelBasePaths/router_without_base_paths_and_groups.json rename to tests/Router/Apps/AppWithoutBasePaths/router_without_base_paths_and_groups.json index bba58da44..cc612f401 100644 --- a/tests/Router/Apps/AppWithoutLeevelBasePaths/router_without_base_paths_and_groups.json +++ b/tests/Router/Apps/AppWithoutBasePaths/router_without_base_paths_and_groups.json @@ -6,7 +6,7 @@ "a": { "_": { "\/api\/v1\/petLeevel\/{petId:[A-Za-z]+}\/": { - "bind": null, + "bind": "\\Tests\\Router\\Apps\\AppWithoutBasePaths\\Controllers\\Pet@demo", "var": [ "petId" ] diff --git a/tests/Router/Apps/AppWithoutLeevelBasePaths/Controllers/Pet.php b/tests/Router/Apps/AppWithoutLeevelBasePaths/Controllers/Pet.php deleted file mode 100644 index 01ce2a844..000000000 --- a/tests/Router/Apps/AppWithoutLeevelBasePaths/Controllers/Pet.php +++ /dev/null @@ -1,49 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -/** - * @OA\Get( - * path="/api/v1/petLeevel/{petId:[A-Za-z]+}/", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"} - * ) - */ -class _ -{ -} diff --git a/tests/Router/Apps/AppWithoutLeevelBasePaths/models/Petstore/ApiResponse.php b/tests/Router/Apps/AppWithoutLeevelBasePaths/models/Petstore/ApiResponse.php deleted file mode 100644 index 3e52ecfed..000000000 --- a/tests/Router/Apps/AppWithoutLeevelBasePaths/models/Petstore/ApiResponse.php +++ /dev/null @@ -1,66 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Petstore; - -/** - * Class ApiResponse. - * - * @author Donii Sergii - * - * @OA\Schema( - * type="object", - * description="Api response", - * title="Api response" - * ) - */ -class ApiResponse -{ - /** - * @OA\Property( - * description="Code", - * title="Code", - * format="int32" - * ) - * - * @var int - */ - private $code; - - /** - * OAS\Property( - * description="Type", - * title="Type", - * ). - * - * @var string - */ - private $type; - - /** - * @OA\Property( - * description="Message", - * title="Message" - * ) - * - * @var string - */ - private $message; -} diff --git a/tests/Router/Apps/AppWithoutLeevelBasePaths/router.php b/tests/Router/Apps/AppWithoutLeevelBasePaths/router.php deleted file mode 100644 index 2f72dc51c..000000000 --- a/tests/Router/Apps/AppWithoutLeevelBasePaths/router.php +++ /dev/null @@ -1,75 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -/** - * @OA\Info( - * description="This is a sample Petstore server. You can find - * out more about Swagger at - * [http://swagger.io](http://swagger.io) or on - * [irc.freenode.net, #swagger](http://swagger.io/irc/).", - * version="1.0.0", - * title="Swagger Petstore", - * termsOfService="http://swagger.io/terms/", - * @OA\Contact( - * email="apiteam@swagger.io" - * ), - * @OA\License( - * name="Apache 2.0", - * url="http://www.apache.org/licenses/LICENSE-2.0.html" - * ) - * ) - */ -class _ -{ -} - -/** - * @OA\Tag( - * name="pet", - * description="Everything about your Pets", - * @OA\ExternalDocumentation( - * description="Find out more", - * url="http://swagger.io" - * ) - * ) - * @OA\Tag( - * name="store", - * description="Access to Petstore orders", - * ) - * @OA\Tag( - * name="user", - * description="Operations about user", - * @OA\ExternalDocumentation( - * description="Find out more about store", - * url="http://swagger.io" - * ) - * ) - * @OA\Server( - * description="SwaggerHUB API Mocking", - * url="https://virtserver.swaggerhub.com/swagger/Petstore/1.0.0" - * ) - * @OA\ExternalDocumentation( - * description="Find out more about Swagger", - * url="http://swagger.io" - * ) - */ -class __ -{ -} diff --git a/tests/Router/Apps/AppWithoutLeevelBasePaths/router/.gitkeep b/tests/Router/Apps/AppWithoutLeevelBasePaths/router/.gitkeep deleted file mode 100644 index 14badf807..000000000 --- a/tests/Router/Apps/AppWithoutLeevelBasePaths/router/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -Query Yet Simple \ No newline at end of file diff --git a/tests/Router/Apps/AppWithoutLeevelBasePaths/security.php b/tests/Router/Apps/AppWithoutLeevelBasePaths/security.php deleted file mode 100644 index a6ca4aa08..000000000 --- a/tests/Router/Apps/AppWithoutLeevelBasePaths/security.php +++ /dev/null @@ -1,44 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -/** - * @OA\SecurityScheme( - * type="oauth2", - * name="petstore_auth", - * securityScheme="petstore_auth", - * @OA\Flow( - * flow="implicit", - * authorizationUrl="http://petstore.swagger.io/oauth/dialog", - * scopes={ - * "write:pets": "modify pets in your account", - * "read:pets": "read your pets", - * } - * ) - * ) - * @OA\SecurityScheme( - * type="apiKey", - * in="header", - * securityScheme="api_key", - * name="api_key" - * ) - */ -class _ -{ -} diff --git a/tests/Router/Apps/Petstore/Controllers/Api.php b/tests/Router/Apps/Petstore/Controllers/Api.php index 39d1c255e..1348cbf0a 100644 --- a/tests/Router/Apps/Petstore/Controllers/Api.php +++ b/tests/Router/Apps/Petstore/Controllers/Api.php @@ -20,99 +20,26 @@ namespace Tests\Router\Apps\Petstore\Controllers; -/** - * Class Api. - * - * @author Xiangmin Liu <635750556@qq.com> - */ class Api { - /** - * @OA\Get( - * path="/api/v1/petLeevelForApi/{petId:[A-Za-z]+}/", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevelForApi", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * } - * ) - */ - public function petLeevelForApi() + #[Route( + path: "/api/v1/petLeevelForApi/{petId:[A-Za-z]+}/", + )] + private function petLeevelForApi(): void { } - /** - * @OA\Get( - * path="/api/v2/petLeevelV2Api/", - * tags={"pet"}, - * summary="Just test ignore the router", - * operationId="petLeevelV2Api", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * leevelIgnore=true - * ) - */ - public function petLeevelV2ForApi() + #[IgnoreRoute( + path: "/api/v2/petLeevelV2Api/", + )] + private function petLeevelV2ForApi(): void { } - /** - * @OA\Get( - * path="/api/v1/petLeevelIgnoreForApi/", - * tags={"pet"}, - * summary="Just test ignore the router", - * operationId="petLeevelIgnoreForApi", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * leevelIgnore=true - * ) - */ - public function petLeevelIgnoreForApi() + #[IgnoreRoute( + path: "/api/v1/petLeevelIgnoreForApi/", + )] + private function petLeevelIgnoreForApi(): void { } } diff --git a/tests/Router/Apps/Petstore/Controllers/HomeIgnore.php b/tests/Router/Apps/Petstore/Controllers/HomeIgnore.php index b9aabd400..09d77ff41 100644 --- a/tests/Router/Apps/Petstore/Controllers/HomeIgnore.php +++ b/tests/Router/Apps/Petstore/Controllers/HomeIgnore.php @@ -20,69 +20,19 @@ namespace Tests\Router\Apps\Petstore\Controllers; -/** - * Class HomeIgnore. - * - * @author Xiangmin Liu <635750556@qq.com> - */ class HomeIgnore { - /** - * @OA\Get( - * path="/", - * tags={"pet"}, - * summary="Will be ignore", - * operationId="petLeevelForApi", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * } - * ) - */ - public function Home1() + #[Route( + path: "/", + )] + private function Home1(): void { } - /** - * @OA\Get( - * path="", - * tags={"pet"}, - * summary="Will be ignore", - * operationId="petLeevelV2Api", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * leevelIgnore=true - * ) - */ - public function home2() + #[IgnoreRoute( + path: "", + )] + private function home2(): void { } } diff --git a/tests/Router/Apps/Petstore/Controllers/Pet.php b/tests/Router/Apps/Petstore/Controllers/Pet.php index f10a9c52d..501456c42 100644 --- a/tests/Router/Apps/Petstore/Controllers/Pet.php +++ b/tests/Router/Apps/Petstore/Controllers/Pet.php @@ -20,425 +20,87 @@ namespace Tests\Router\Apps\Petstore\Controllers; -/** - * Class Pet. - * - * @author Donii Sergii - */ +use Leevel\Http\Request; + class Pet { - /** - * @OA\Get( - * path="/api/v2/petLeevel/{petId:[A-Za-z]+}/", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevel", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"}, - * leevelScheme="https", - * leevelDomain="{subdomain:[A-Za-z]+}-vip.{domain}", - * leevelAttributes={"args1": "hello", "args2": "world"}, - * leevelBind="\PetLeevel\show", - * leevelMiddlewares="api" - * ) - */ - public function petLeevel() + #[Route( + path: "/api/v2/petLeevel/{petId:[A-Za-z]+}/", + scheme: "https", + domain: "{subdomain:[A-Za-z]+}-vip.{domain}", + attributes: ["args1" => "hello", "args2" => "world"], + bind: "\\PetLeevel\\show", + middlewares: "api", + )] + private function petLeevel(): void { } - /** - * @OA\Get( - * path="/api/v2/petLeevelIgnore/", - * tags={"pet"}, - * summary="Just test ignore the router", - * operationId="petLeevelIgnore", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * leevelIgnore=true - * ) - */ - public function petLeevelIgnore() + #[IgnoreRoute( + path: "/api/v2/petLeevelIgnore/", + )] + private function petLeevelIgnore(): void { } - /** - * @OA\Post( - * path="/pet", - * tags={"pet"}, - * summary="Add a new pet to the store", - * operationId="addPet", - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"} - * ) - */ - public function addPet() + #[Route( + path: "/pet", + method: Request::METHOD_POST, + )] + private function addPet(): void { } - /** - * @OA\Put( - * path="/pet", - * tags={"pet"}, - * summary="Update an existing pet", - * operationId="updatePet", - * @OA\Response( - * response=400, - * description="Invalid ID supplied" - * ), - * @OA\Response( - * response=404, - * description="Pet not found" - * ), - * @OA\Response( - * response=405, - * description="Validation exception" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * requestBody={"$ref": "#/components/requestBodies/Pet"} - * ) - */ - public function updatePet() + #[Route( + path: "/pet", + method: Request::METHOD_PUT, + )] + private function updatePet(): void { } - /** - * @OA\Get( - * path="/pet/findByStatus", - * tags={"pet"}, - * summary="Finds Pets by status", - * description="Multiple status values can be provided with comma separated string", - * operationId="findPetsByStatus", - * deprecated=true, - * @OA\Parameter( - * name="status", - * in="query", - * description="Status values that needed to be considered for filter", - * required=true, - * explode=true, - * @OA\Schema( - * type="array", - * default="available", - * @OA\Items( - * type="string", - * enum = {"available", "pending", "sold"}, - * ) - * ) - * ), - * @OA\Response( - * response=200, - * description="successful operation", - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * type="array", - * @OA\Items( - * ref="#/components/schemas/Pet" - * ) - * ) - * ), - * @OA\MediaType( - * mediaType="application/xml", - * @OA\Schema( - * type="array", - * @OA\Items( - * ref="#/components/schemas/Pet" - * ) - * ) - * ) - * ), - * @OA\Response( - * response=400, - * description="Invalid status value" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * } - * ) - */ - public function findPetsByStatus() + #[IgnoreRoute( + path: "/pet/findByStatus", + )] + private function findPetsByStatus(): void { } - /** - * @OA\Get( - * path="/pet/findByTags", - * tags={"pet"}, - * summary="Finds Pets by tags", - * description=">- - * Muliple tags can be provided with comma separated strings. Use\ \ tag1, - * tag2, tag3 for testing.", - * operationId="findByTags", - * @OA\Parameter( - * name="tags", - * in="query", - * description="Tags to filter by", - * required=true, - * explode=true, - * @OA\Schema( - * type="array", - * @OA\Items( - * type="string", - * ) - * ) - * ), - * @OA\Response( - * response=200, - * description="successful operation", - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * type="array", - * @OA\Items( - * ref="#/components/schemas/Pet" - * ) - * ) - * ), - * @OA\MediaType( - * mediaType="application/xml", - * @OA\Schema( - * type="array", - * @OA\Items( - * ref="#/components/schemas/Pet" - * ) - * ) - * ) - * ), - * @OA\Response( - * response=400, - * description="Invalid status value" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * } - * ) - */ - public function findByTags() + #[Route( + path: "/pet/findByTags", + )] + private function findByTags(): void { } - /** - * @OA\Get( - * path="/pet/{petId}", - * tags={"pet"}, - * summary="Find pet by ID", - * description="Returns a single pet", - * operationId="getPetById", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=200, - * description="successful operation", - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * ref="#/components/schemas/Pet" - * ), - * ), - * @OA\MediaType( - * mediaType="application/xml", - * @OA\Schema( - * ref="#/components/schemas/Pet" - * ), - * ) - * ), - * @OA\Response( - * response=400, - * description="Invalid ID supplier" - * ), - * @OA\Response( - * response=404, - * description="Pet not found" - * ), - * security={ - * {"api_key": {}} - * } - * ) - * - * @param int $id - */ - public function getPetById($id) + #[Route( + path: "/pet/{petId}", + )] + private function getPetById(int $id): void { } - /** - * @OA\Post( - * path="/pet/{petId}", - * tags={"pet"}, - * summary="Updates a pet in the store with form data", - * operationId="updatePetWithForm", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet that needs to be updated", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * @OA\RequestBody( - * description="Input data format", - * @OA\MediaType( - * mediaType="application/x-www-form-urlencoded", - * @OA\Schema( - * type="object", - * @OA\Property( - * property="name", - * description="Updated name of the pet", - * type="string", - * ), - * @OA\Property( - * property="status", - * description="Updated status of the pet", - * type="string" - * ) - * ) - * ) - * ) - * ) - */ - public function updatePetWithForm() + #[Route( + path: "/pet/{petId}", + method: Request::METHOD_POST, + )] + private function updatePetWithForm(): void { } - /** - * @OA\Delete( - * path="/pet/{petId}", - * tags={"pet"}, - * summary="Deletes a pet", - * operationId="deletePet", - * @OA\Parameter( - * name="api_key", - * in="header", - * required=false, - * @OA\Schema( - * type="string" - * ) - * ), - * @OA\Parameter( - * name="petId", - * in="path", - * description="Pet id to delete", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ), - * ), - * @OA\Response( - * response=400, - * description="Invalid ID supplied", - * ), - * @OA\Response( - * response=404, - * description="Pet not found", - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * ) - */ - public function deletePet() + #[Route( + path: "/pet/{petId}", + method: Request::METHOD_DELETE, + )] + private function deletePet(): void { } - /** - * @OA\Post( - * path="/pet/{petId}/uploadImage", - * tags={"pet"}, - * summary="uploads an image", - * operationId="uploadFile", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to update", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64", - * example=1 - * ) - * ), - * @OA\Response( - * response=200, - * description="successful operation", - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * ref="#/components/schemas/ApiResponse" - * ) - * ) - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * @OA\RequestBody( - * description="Upload images request body", - * @OA\MediaType( - * mediaType="application/octet-stream", - * @OA\Schema( - * type="string", - * format="binary" - * ) - * ) - * ) - * ) - */ - public function uploadFile() + #[Route( + path: "/pet/{petId}/uploadImage", + method: Request::METHOD_POST, + )] + private function uploadFile(): void { } } diff --git a/tests/Router/Apps/Petstore/Controllers/Store.php b/tests/Router/Apps/Petstore/Controllers/Store.php index 5d151080d..f5111d5e2 100644 --- a/tests/Router/Apps/Petstore/Controllers/Store.php +++ b/tests/Router/Apps/Petstore/Controllers/Store.php @@ -20,162 +20,37 @@ namespace Tests\Router\Apps\Petstore\Controllers; -/** - * Class Store. - * - * @author Donii Sergii - */ +use Leevel\Http\Request; + class Store { - /** - * @OA\Get( - * path="/store", - * tags={"store"}, - * summary="Returns pet inventories by status", - * description="Returns a map of status codes to quantities", - * operationId="getInventory", - * @OA\Response( - * response=200, - * description="successful operation", - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * type="object", - * @OA\AdditionalProperties( - * type="integer", - * format="int32" - * ) - * ) - * ) - * ), - * security={ - * {"api_key": {}} - * } - * ) - */ - public function getInventory() + #[Route( + path: "/store", + )] + private function getInventory(): void { } - /** - * @OA\Post( - * path="/store/order", - * tags={"store"}, - * summary="Place an order for a pet", - * operationId="placeOrder", - * @OA\Response( - * response=200, - * description="successful operation", - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * ref="#/components/schemas/Order" - * ) - * ), - * @OA\MediaType( - * mediaType="application/xml", - * @OA\Schema( - * ref="#/components/schemas/Order" - * ) - * ) - * ), - * @OA\RequestBody( - * description="order placed for purchasing th pet", - * required=true, - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * ref="#/components/schemas/Order" - * ) - * ) - * ) - * ) - */ - public function placeOrder() + #[Route( + path: "/store/order", + method: Request::METHOD_POST, + )] + private function placeOrder(): void { } - /** - * @OA\Get( - * path="/store/order/{orderId}", - * tags={"store"}, - * description=">- - * For valid response try integer IDs with value >= 1 and <= 10.\ \ Other - * values will generated exceptions", - * operationId="getOrderById", - * @OA\Parameter( - * name="orderId", - * in="path", - * description="ID of pet that needs to be fetched", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64", - * maximum=1, - * minimum=10 - * ) - * ), - * @OA\Response( - * response=200, - * description="successful operation", - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * ref="#/components/schemas/Order" - * ) - * ), - * @OA\MediaType( - * mediaType="application/xml", - * @OA\Schema( - * ref="#/components/schemas/Order" - * ) - * ) - * ), - * @OA\Response( - * response=400, - * description="Invalid ID supplied" - * ), - * @OA\Response( - * response=404, - * description="Order not found" - * ) - * ) - */ - public function getOrderById() + #[Route( + path: "/store/order/{orderId}", + )] + private function getOrderById(): void { } - /** - * @OA\Delete( - * path="/store/order/{orderId}", - * tags={"store"}, - * summary="Delete purchase order by ID", - * description=">- - * For valid response try integer IDs with positive integer value.\ \ - * Negative or non-integer values will generate API errors", - * operationId="deleteOrder", - * @OA\Parameter( - * name="orderId", - * in="path", - * required=true, - * description="ID of the order that needs to be deleted", - * @OA\Schema( - * type="integer", - * format="int64", - * minimum=1 - * ) - * ), - * @OA\Response( - * response=400, - * description="Invalid ID supplied" - * ), - * @OA\Response( - * response=404, - * description="Order not found" - * ) - * ), - */ - public function deleteOrder() + #[Route( + path: "/store/order/{orderId}", + method: Request::METHOD_DELETE, + )] + private function deleteOrder(): void { } } diff --git a/tests/Router/Apps/Petstore/Controllers/User.php b/tests/Router/Apps/Petstore/Controllers/User.php index 4bab5ee63..e3b3411fa 100644 --- a/tests/Router/Apps/Petstore/Controllers/User.php +++ b/tests/Router/Apps/Petstore/Controllers/User.php @@ -20,248 +20,60 @@ namespace Tests\Router\Apps\Petstore\Controllers; -/** - * Class User. - * - * @author Donii Sergii - */ +use Leevel\Http\Request; + class User { - /** - * @OA\Post( - * path="/user", - * tags={"user"}, - * summary="Create user", - * description="This can only be done by the logged in user.", - * operationId="createUser", - * @OA\Response( - * response="default", - * description="successful operation" - * ), - * @OA\RequestBody( - * description="Create user object", - * required=true, - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * ref="#/components/schemas/User" - * ) - * ) - * ) - * ) - */ - public function createUser() + #[Route( + path: "/user", + method: Request::METHOD_POST, + )] + private function createUser(): void { } - /** - * @OA\Post( - * path="/user/createWithArray", - * tags={"user"}, - * summary="Create list of users with given input array", - * operationId="createUsersWithListInput", - * @OA\Response( - * response="default", - * description="successful operation" - * ), - * @OA\RequestBody( - * ref="#/components/requestBodies/UserArray" - * ) - * ) - */ - public function createUsersWithListInput() + #[Route( + path: "/user/createWithArray", + method: Request::METHOD_POST, + )] + private function createUsersWithListInput(): void { } - /** - * @OA\Get( - * path="/user/login", - * tags={"user"}, - * summary="Logs user into system", - * operationId="loginUser", - * @OA\Parameter( - * name="username", - * in="query", - * description="The user name for login", - * required=true, - * @OA\Schema( - * type="string" - * ) - * ), - * @OA\Parameter( - * name="password", - * in="query", - * required=true, - * @OA\Schema( - * type="string", - * ) - * ), - * @OA\Response( - * response=200, - * description="successful operation", - * @OA\Header( - * header="X-Rate-Limit", - * description="calls per hour allowed by the user", - * @OA\Schema( - * type="integer", - * format="int32" - * ) - * ), - * @OA\Header( - * header="X-Expires-After", - * description="date in UTC when token expires", - * @OA\Schema( - * type="string", - * format="datetime" - * ) - * ), - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * type="string" - * ) - * ), - * @OA\MediaType( - * mediaType="application/xml", - * @OA\Schema( - * type="string" - * ) - * ) - * ), - * @OA\Response( - * response=400, - * description="Invalid username/password supplied" - * ) - * ) - */ - public function loginUser() + #[Route( + path: "/user/login", + )] + private function loginUser(): void { } - /** - * @OA\Get( - * path="/user/logout", - * tags={"user"}, - * summary="Logs out current logged in user session", - * operationId="logoutUser", - * @OA\Response( - * response="default", - * description="successful operation" - * ) - * ) - */ - public function logoutUser() + #[Route( + path: "/user/logout", + )] + private function logoutUser(): void { } - /** - * @OA\Get( - * path="/user/{username}", - * summary="Get user by user name", - * operationId="getUserByName", - * @OA\Parameter( - * name="username", - * in="path", - * required=true, - * @OA\Schema( - * type="string" - * ) - * ), - * @OA\Response( - * response=200, - * description="successful operation", - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * ref="#/components/schemas/User" - * ) - * ), - * @OA\MediaType( - * mediaType="application/xml", - * @OA\Schema( - * ref="#/components/schemas/User" - * ) - * ) - * ), - * @OA\Response( - * response=400, - * description="Invalid username supplied" - * ), - * @OA\Response( - * response=404, - * description="User not found" - * ), - * ) - */ - public function getUserByName() + #[Route( + path: "/user/{username}", + )] + private function getUserByName(): void { } - /** - * @OA\Put( - * path="/user/{username}", - * summary="Updated user", - * description="This can pnly be done by the logged in user.", - * operationId="updateUser", - * @OA\Parameter( - * name="username", - * in="path", - * description="name that to be updated", - * required=true, - * @OA\Schema( - * type="string" - * ) - * ), - * @OA\Response( - * response=400, - * description="Invalid user supplied" - * ), - * @OA\Response( - * response=404, - * description="User not found" - * ), - * @OA\RequestBody( - * description="Updated user object", - * required=true, - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * ref="#/components/schemas/User" - * ) - * ) - * ) - * ) - */ - public function updateUser() + #[Route( + path: "/user/{username}", + method: Request::METHOD_PUT, + )] + private function updateUser(): void { } - /** - * @OA\Delete( - * path="/user/{username}", - * summary="Delete user", - * description="This can only be done by the logged in user.", - * operationId="deleteUser", - * @OA\Parameter( - * name="username", - * in="path", - * description="The name that needs to be deleted", - * required=true, - * @OA\Schema( - * type="string" - * ) - * ), - * @OA\Response( - * response=400, - * description="Invalid username supplied", - * ), - * @OA\Response( - * response=404, - * description="User not found", - * ) - * ) - */ - public function deleteUser() + #[Route( + path: "/user/{username}", + method: Request::METHOD_DELETE, + )] + private function deleteUser(): void { } } diff --git a/tests/Router/Apps/Petstore/Controllers/Web.php b/tests/Router/Apps/Petstore/Controllers/Web.php index 72e8a7a21..bd1cbf5e3 100644 --- a/tests/Router/Apps/Petstore/Controllers/Web.php +++ b/tests/Router/Apps/Petstore/Controllers/Web.php @@ -20,99 +20,26 @@ namespace Tests\Router\Apps\Petstore\Controllers; -/** - * Class Web. - * - * @author Xiangmin Liu <635750556@qq.com> - */ class Web { - /** - * @OA\Get( - * path="/web/v1/petLeevelForWeb/{petId:[A-Za-z]+}/", - * tags={"pet"}, - * summary="Just test the router", - * operationId="petLeevelForWeb", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * } - * ) - */ - public function petLeevelForWeb() + #[Route( + path: "/web/v1/petLeevelForWeb/{petId:[A-Za-z]+}/", + )] + private function petLeevelForWeb(): void { } - /** - * @OA\Get( - * path="/web/v2/petLeevelV2Web/", - * tags={"pet"}, - * summary="Just test ignore the router", - * operationId="petLeevelV2Web", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * leevelIgnore=true - * ) - */ - public function petLeevelV2ForWeb() + #[IgnoreRoute( + path: "/web/v2/petLeevelV2Web/", + )] + private function petLeevelV2ForWeb(): void { } - - /** - * @OA\Get( - * path="/web/v1/petLeevelIgnoreForWeb/", - * tags={"pet"}, - * summary="Just test ignore the router", - * operationId="petLeevelIgnoreForWeb", - * @OA\Parameter( - * name="petId", - * in="path", - * description="ID of pet to return", - * required=true, - * @OA\Schema( - * type="integer", - * format="int64" - * ) - * ), - * @OA\Response( - * response=405, - * description="Invalid input" - * ), - * security={ - * {"petstore_auth": {"write:pets", "read:pets"}} - * }, - * leevelIgnore=true - * ) - */ - public function petLeevelIgnoreForWeb() + + #[IgnoreRoute( + path: "/web/v1/petLeevelIgnoreForWeb/", + )] + private function petLeevelIgnoreForWeb(): void { } } diff --git a/tests/Router/Apps/Petstore/models/Petstore/ApiResponse.php b/tests/Router/Apps/Petstore/models/Petstore/ApiResponse.php deleted file mode 100644 index 3e52ecfed..000000000 --- a/tests/Router/Apps/Petstore/models/Petstore/ApiResponse.php +++ /dev/null @@ -1,66 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Petstore; - -/** - * Class ApiResponse. - * - * @author Donii Sergii - * - * @OA\Schema( - * type="object", - * description="Api response", - * title="Api response" - * ) - */ -class ApiResponse -{ - /** - * @OA\Property( - * description="Code", - * title="Code", - * format="int32" - * ) - * - * @var int - */ - private $code; - - /** - * OAS\Property( - * description="Type", - * title="Type", - * ). - * - * @var string - */ - private $type; - - /** - * @OA\Property( - * description="Message", - * title="Message" - * ) - * - * @var string - */ - private $message; -} diff --git a/tests/Router/Apps/Petstore/models/Petstore/Category.php b/tests/Router/Apps/Petstore/models/Petstore/Category.php deleted file mode 100644 index 5eab3e192..000000000 --- a/tests/Router/Apps/Petstore/models/Petstore/Category.php +++ /dev/null @@ -1,59 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Petstore; - -/** - * Class Category. - * - * @author Donii Sergii - * - * @OA\Schema( - * type="object", - * description="Pets Category", - * title="Pets Category", - * @OA\Xml( - * name="Category" - * ) - * ) - */ -class Category -{ - /** - * @OA\Property( - * title="ID", - * description="ID", - * format="int64", - * ) - * - * @var int - */ - private $id; - - /** - * @OA\Property( - * title="Category name", - * description="Category name" - * ) - * - * @var string - */ - private $name; -} diff --git a/tests/Router/Apps/Petstore/models/Petstore/Order.php b/tests/Router/Apps/Petstore/models/Petstore/Order.php deleted file mode 100644 index 4925123fd..000000000 --- a/tests/Router/Apps/Petstore/models/Petstore/Order.php +++ /dev/null @@ -1,108 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Petstore; - -/** - * Class Order. - * - * @author Donii Sergii - * @OA\Schema( - * title="Order model", - * description="Order model", - * ) - */ -class Order -{ - /** - * @OA\Property( - * format="int64", - * title="ID", - * default=1, - * description="ID", - * ) - * - * @var int - */ - private $id; - - /** - * @OA\Property( - * default=1, - * format="int64", - * description="Pet ID", - * title="Pet ID", - * ) - * - * @var int - */ - private $petId; - - /** - * @OA\Property( - * default=12, - * format="in32", - * description="Quantity", - * title="Quantity", - * ) - * - * @var int - */ - private $quantity; - - /** - * @OA\Property( - * default="2017-02-02 18:31:45", - * format="datetime", - * description="Shipping date", - * title="Shipping date", - * title="Pet ID", - * type="string" - * ) - * - * @var \DateTime - */ - private $shipDate; - - /** - * @OA\Property( - * default="placed", - * title="Order status", - * description="Order status", - * enum={"placed", "approved", "delivered"}, - * title="Pet ID", - * ) - * - * @var string - */ - private $status; - - /** - * @OA\Property( - * default="false", - * format="int64", - * description="Complete status", - * title="Complete status", - * ) - * - * @var bool - */ - private $complete; -} diff --git a/tests/Router/Apps/Petstore/models/Petstore/Pet.php b/tests/Router/Apps/Petstore/models/Petstore/Pet.php deleted file mode 100644 index 3c007a690..000000000 --- a/tests/Router/Apps/Petstore/models/Petstore/Pet.php +++ /dev/null @@ -1,103 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Petstore; - -/** - * Class Pet. - * - * @author Donii Sergii - * - * @OA\Schema( - * description="Pet model", - * title="Pet model", - * type="object", - * required={"name", "photoUrls"}, - * @OA\Xml( - * name="Pet" - * ) - * ) - */ -class Pet -{ - /** - * @OA\Property( - * format="int64", - * description="ID", - * title="ID", - * ) - * - * @var int - */ - private $id; - - /** - * @OA\Property( - * description="Category relation", - * title="Category", - * ) - * - * @var \Petstore\Category - */ - private $category; - - /** - * @OA\Property( - * format="int64", - * description="Pet name", - * title="Pet name", - * ) - * - * @var int - */ - private $name; - - /** - * @OA\Property( - * description="Photo urls", - * title="Photo urls", - * @OA\Xml( - * name="photoUrl", - * wrapped=true - * ), - * @OA\Items( - * type="string", - * default="images/image-1.png" - * ) - * ) - * - * @var array - */ - private $photoUrls; - - /** - * @OA\Property( - * description="Pet tags", - * title="Pet tags", - * @OA\Xml( - * name="tag", - * wrapped=true - * ), - * ) - * - * @var \Petstore\Tag[] - */ - private $tags; -} diff --git a/tests/Router/Apps/Petstore/models/Petstore/RequestBody.php b/tests/Router/Apps/Petstore/models/Petstore/RequestBody.php deleted file mode 100644 index 85798826a..000000000 --- a/tests/Router/Apps/Petstore/models/Petstore/RequestBody.php +++ /dev/null @@ -1,64 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Petstore; - -/** - * @OA\RequestBody( - * request="Pet", - * description="Pet object that needs to be added to the store", - * required=true, - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * ref="#/components/schemas/Pet" - * ) - * ), - * @OA\MediaType( - * mediaType="application/xml", - * @OA\Schema( - * ref="#/components/schemas/Pet" - * ) - * ) - * ) - */ -class _ -{ -} - -/** - * @OA\RequestBody( - * request="UserArray", - * description="List of user object", - * required=true, - * @OA\MediaType( - * mediaType="application/json", - * @OA\Schema( - * type="array", - * @OA\Items( - * ref="#/components/schemas/User" - * ) - * ) - * ) - * ) - */ -class _ -{ -} diff --git a/tests/Router/Apps/Petstore/models/Petstore/Tag.php b/tests/Router/Apps/Petstore/models/Petstore/Tag.php deleted file mode 100644 index db341e69e..000000000 --- a/tests/Router/Apps/Petstore/models/Petstore/Tag.php +++ /dev/null @@ -1,59 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Petstore; - -/** - * Class Tag. - * - * @author Donii Sergii - * - * @OA\Schema( - * type="object", - * description="Tag", - * title="Tag", - * @OA\Xml( - * name="Tag" - * ) - * ) - */ -class Tag -{ - /** - * @OA\Property( - * format="int64", - * description="ID", - * title="ID" - * ) - * - * @var int - */ - private $id; - - /** - * @OA\Property( - * description="Name", - * title="Name" - * ) - * - * @var string - */ - private $name; -} diff --git a/tests/Router/Apps/Petstore/models/Petstore/User.php b/tests/Router/Apps/Petstore/models/Petstore/User.php deleted file mode 100644 index 2596569d4..000000000 --- a/tests/Router/Apps/Petstore/models/Petstore/User.php +++ /dev/null @@ -1,121 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Petstore; - -/** - * Class User. - * - * @author Donii Sergii - * - * @OA\Schema( - * title="User model", - * description="User model", - * type="object" - * ) - */ -class User -{ - /** - * @OA\Property( - * format="int64", - * description="ID", - * title="ID", - * ) - * - * @var int - */ - private $id; - - /** - * @OA\Property( - * description="Username", - * title="Username", - * ) - * - * @var string - */ - private $username; - - /** - * @OA\Property( - * description="First name", - * title="First name", - * ) - * - * @var string - */ - private $firstName; - - /** - * @OA\Property( - * description="Last name", - * title="Last name", - * ) - * - * @var string - */ - private $lastName; - - /** - * @OA\Property( - * format="email", - * description="Email", - * title="Email", - * ) - * - * @var string - */ - private $email; - - /** - * @OA\Property( - * format="int64", - * description="Password", - * title="Password", - * maximum=255 - * ) - * - * @var string - */ - private $password; - - /** - * @OA\Property( - * format="msisdn", - * description="Phone", - * title="Phone", - * ) - * - * @var string - */ - private $phone; - - /** - * @OA\Property( - * format="int32", - * description="User status", - * title="User status", - * ) - * - * @var int - */ - private $userStatus; -} diff --git a/tests/Router/Apps/Petstore/router.json b/tests/Router/Apps/Petstore/router.json index fce366ce6..670fd9671 100644 --- a/tests/Router/Apps/Petstore/router.json +++ b/tests/Router/Apps/Petstore/router.json @@ -16,19 +16,19 @@ ] }, "\/api\/v2\/petLeevel\/{petId:[A-Za-z]+}\/": { - "scheme": "https", - "domain": "{subdomain:[A-Za-z]+}-vip.{domain}.queryphp.cn", "attributes": { "args1": "hello", "args2": "world" }, "bind": "\\PetLeevel\\show", - "middlewares": [], + "domain": "{subdomain:[A-Za-z]+}-vip.{domain}.queryphp.cn", "domain_regex": "\/^([A-Za-z]+)\\-vip\\.(\\S+)\\.queryphp\\.cn$\/", "domain_var": [ "subdomain", "domain" ], + "middlewares": [], + "scheme": "https", "var": [ "petId" ] diff --git a/tests/Router/Apps/Petstore/router.php b/tests/Router/Apps/Petstore/router.php deleted file mode 100644 index f4de09f5e..000000000 --- a/tests/Router/Apps/Petstore/router.php +++ /dev/null @@ -1,75 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -/** - * @OA\Info( - * description="This is a sample Petstore server. You can find - * out more about Swagger at - * [http://swagger.io](http://swagger.io) or on - * [irc.freenode.net, #swagger](http://swagger.io/irc/).", - * version="1.0.0", - * title="Swagger Petstore", - * termsOfService="http://swagger.io/terms/", - * @OA\Contact( - * email="apiteam@swagger.io" - * ), - * @OA\License( - * name="Apache 2.0", - * url="http://www.apache.org/licenses/LICENSE-2.0.html" - * ) - * ) - */ -class _ -{ -} - -/** - * @OA\Tag( - * name="pet", - * description="Everything about your Pets", - * @OA\ExternalDocumentation( - * description="Find out more", - * url="http://swagger.io" - * ) - * ) - * @OA\Tag( - * name="store", - * description="Access to Petstore orders", - * ) - * @OA\Tag( - * name="user", - * description="Operations about user", - * @OA\ExternalDocumentation( - * description="Find out more about store", - * url="http://swagger.io" - * ) - * ) - * @OA\Server( - * description="SwaggerHUB API Mocking 1.0.0", - * url="https://virtserver.swaggerhub.com/swagger/Petstore" - * ) - * @OA\ExternalDocumentation( - * description="Find out more about Swagger", - * url="http://swagger.io", - * ) - */ -class __ -{ -} diff --git a/tests/Router/Apps/Petstore/router/.gitkeep b/tests/Router/Apps/Petstore/router/.gitkeep deleted file mode 100644 index 14badf807..000000000 --- a/tests/Router/Apps/Petstore/router/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -Query Yet Simple \ No newline at end of file diff --git a/tests/Router/Apps/Petstore/security.php b/tests/Router/Apps/Petstore/security.php deleted file mode 100644 index a6ca4aa08..000000000 --- a/tests/Router/Apps/Petstore/security.php +++ /dev/null @@ -1,44 +0,0 @@ - - * (c) 2010-2020 http://queryphp.com All rights reserved. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -/** - * @OA\SecurityScheme( - * type="oauth2", - * name="petstore_auth", - * securityScheme="petstore_auth", - * @OA\Flow( - * flow="implicit", - * authorizationUrl="http://petstore.swagger.io/oauth/dialog", - * scopes={ - * "write:pets": "modify pets in your account", - * "read:pets": "read your pets", - * } - * ) - * ) - * @OA\SecurityScheme( - * type="apiKey", - * in="header", - * securityScheme="api_key", - * name="api_key" - * ) - */ -class _ -{ -} diff --git a/tests/Router/OpenApiRouterTest.php b/tests/Router/OpenApiRouterTest.php index 6114ed9b8..ddf6c4e66 100644 --- a/tests/Router/OpenApiRouterTest.php +++ b/tests/Router/OpenApiRouterTest.php @@ -77,7 +77,7 @@ public function testBaseUse(): void ); } - public function testWithoutLeevelBasePaths(): void + public function testWithoutBasePaths(): void { $openApiRouter = new OpenApiRouter( $this->createMiddlewareParser(), @@ -90,7 +90,7 @@ public function testWithoutLeevelBasePaths(): void ], ); - $scandir = __DIR__.'/Apps/AppWithoutLeevelBasePaths'; + $scandir = __DIR__.'/Apps/AppWithoutBasePaths'; $openApiRouter->addScandir($scandir); $result = $openApiRouter->handle(); @@ -133,7 +133,7 @@ public function testAppWithControllerDirMatche(): void ); } - public function testWithoutLeevelBasePathsAndGroups(): void + public function testWithoutBasePathsAndGroups(): void { $openApiRouter = new OpenApiRouter( $this->createMiddlewareParser(), @@ -142,7 +142,7 @@ public function testWithoutLeevelBasePathsAndGroups(): void [], ); - $scandir = __DIR__.'/Apps/AppWithoutLeevelBasePaths'; + $scandir = __DIR__.'/Apps/AppWithoutBasePaths'; $openApiRouter->addScandir($scandir); $result = $openApiRouter->handle(); @@ -190,7 +190,7 @@ public function testAddScandirButNotFound(): void $scandir = __DIR__.'/Apps/PetstorenNotFound'; $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage(sprintf('OpenApi scandir %s is exits.', $scandir)); + $this->expectExceptionMessage(sprintf('Annotation routing scandir %s is not exits.', $scandir)); $openApiRouter = new OpenApiRouter($this->createMiddlewareParser()); $openApiRouter->addScandir($scandir); @@ -208,7 +208,7 @@ public function testBasePathsIsInvalid(): void [], ); - $scandir = __DIR__.'/Apps/AppWithoutLeevelBasePaths'; + $scandir = __DIR__.'/Apps/AppWithoutBasePaths'; $openApiRouter->addScandir($scandir); $openApiRouter->handle(); @@ -226,7 +226,7 @@ public function testGroupsIsInvalid(): void ['middlewares' => 'hello world'], ); - $scandir = __DIR__.'/Apps/AppWithoutLeevelBasePaths'; + $scandir = __DIR__.'/Apps/AppWithoutBasePaths'; $openApiRouter->addScandir($scandir); $openApiRouter->handle();