Skip to content

Commit

Permalink
Resolve yiisoft#602 conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
rossaddison committed Apr 10, 2024
1 parent e6eb950 commit bf4d0de
Show file tree
Hide file tree
Showing 19 changed files with 372 additions and 508 deletions.
2 changes: 1 addition & 1 deletion blog-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Authorization is performed via the `X-Api-Key` header.

## API documentation

API documentation is available at `/docs`. It is built from OpenAPI annotations (`@OA`).
API documentation is available at `/docs`. It is built from OpenAPI attributes (`#[OA\ ... ]`).
See [Swagger-PHP documentation](https://zircote.github.io/swagger-php/Getting-started.html#write-annotations) for details
on how to annotate your code.

Expand Down
11 changes: 6 additions & 5 deletions blog-api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@
"yiisoft/cache": "^3.0",
"yiisoft/cache-file": "^3.0",
"yiisoft/config": "^1.0",
"yiisoft/data": "^1.0",
"yiisoft/data": "dev-master",
"yiisoft/data-cycle": "dev-master",
"yiisoft/data-response": "^2.0",
"yiisoft/definitions": "^3.0",
"yiisoft/di": "^1.0",
"yiisoft/error-handler": "^3.0",
"yiisoft/factory": "^1.0",
"yiisoft/files": "^2.0",
"yiisoft/http": "^1.2",
"yiisoft/hydrator-validator": "dev-master",
"yiisoft/hydrator-validator": "^2.0",
"yiisoft/injector": "^1.0",
"yiisoft/input-http": "dev-master",
"yiisoft/input-http": "^1.0",
"yiisoft/log": "^2.0",
"yiisoft/log-target-file": "^3.0",
"yiisoft/middleware-dispatcher": "^5.1",
Expand All @@ -64,12 +65,12 @@
"yiisoft/user": "^2.0",
"yiisoft/validator": "^1.0",
"yiisoft/yii-console": "^2.0",
"yiisoft/yii-cycle": "dev-master",
"yiisoft/yii-cycle": "^1.0",
"yiisoft/yii-debug": "^3.0@dev",
"yiisoft/yii-event": "^2.0",
"yiisoft/yii-http": "^1.0",
"yiisoft/yii-middleware": "^1.0",
"yiisoft/yii-queue": "3.0.x-dev",
"yiisoft/queue": "3.0.x-dev",
"yiisoft/yii-runner-console": "^2.0",
"yiisoft/yii-runner-http": "^2.0",
"yiisoft/yii-swagger": "^2.0"
Expand Down
8 changes: 5 additions & 3 deletions blog-api/config/common/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
use App\Queue\LoggingAuthorizationHandler;
use Cycle\Database\Config\SQLite\FileConnectionConfig;
use Cycle\Database\Config\SQLiteDriverConfig;
use Cycle\Schema\Provider\PhpFileSchemaProvider;
use Yiisoft\ErrorHandler\Middleware\ErrorCatcher;
use Yiisoft\RequestProvider\RequestCatcherMiddleware;
use Yiisoft\Router\Middleware\Router;
use Yiisoft\Yii\Cycle\Schema\Conveyor\AttributedSchemaConveyor;
use Yiisoft\Yii\Cycle\Schema\Provider\FromConveyorSchemaProvider;
use Yiisoft\Yii\Cycle\Schema\Provider\PhpFileSchemaProvider;
use Yiisoft\Yii\Cycle\Schema\SchemaProviderInterface;
use Yiisoft\Yii\Middleware\Locale;
use Yiisoft\Yii\Middleware\Subfolder;
use Yiisoft\Yii\Queue\Adapter\SynchronousAdapter;
use Yiisoft\Queue\Adapter\SynchronousAdapter;

return [
'locale' => [
Expand All @@ -25,6 +26,7 @@
],
'supportEmail' => '[email protected]',
'middlewares' => [
RequestCatcherMiddleware::class,
ErrorCatcher::class,
Subfolder::class,
Locale::class,
Expand Down Expand Up @@ -137,7 +139,7 @@
],
],

'yiisoft/yii-queue' => [
'yiisoft/queue' => [
'handlers' => [
LoggingAuthorizationHandler::NAME => [LoggingAuthorizationHandler::class, 'handle'],
],
Expand Down
2 changes: 1 addition & 1 deletion blog-api/config/common/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@
Route::get('/openapi.json')
->middleware(FormatDataResponseAsJson::class)
->middleware(CorsAllowAll::class)
->action([SwaggerJson::class, 'handle']),
->action([SwaggerJson::class, 'process']),
),
];
2 changes: 0 additions & 2 deletions blog-api/config/web/di/middleware-dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

use Yiisoft\Definitions\Reference;
use Yiisoft\Input\Http\HydratorAttributeParametersResolver;
use Yiisoft\Input\Http\Request\Catcher\RequestCatcherParametersResolver;
use Yiisoft\Input\Http\RequestInputParametersResolver;
use Yiisoft\Middleware\Dispatcher\CompositeParametersResolver;
use Yiisoft\Middleware\Dispatcher\ParametersResolverInterface;
Expand All @@ -17,7 +16,6 @@
ParametersResolverInterface::class => [
'class' => CompositeParametersResolver::class,
'__construct()' => [
Reference::to(RequestCatcherParametersResolver::class),
Reference::to(HydratorAttributeParametersResolver::class),
Reference::to(RequestInputParametersResolver::class),
],
Expand Down
140 changes: 58 additions & 82 deletions blog-api/src/Auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,12 @@

use App\User\UserRequest;
use App\User\UserService;
use OpenApi\Annotations as OA;
use OpenApi\Attributes as OA;
use Psr\Http\Message\ResponseInterface;
use Yiisoft\DataResponse\DataResponseFactoryInterface as ResponseFactory;

/**
* @OA\Tag(
* name="auth",
* description="Authentication"
* )
*
* @OA\SecurityScheme(
* securityScheme="ApiKey",
* type="apiKey",
* in="header",
* name="X-Api-Key"
* )
*/
#[OA\Tag(name: 'auth', description: 'Authentication')]
#[OA\SecurityScheme(securityScheme: 'ApiKey', type: 'apiKey', name: 'X-Api-Key', in: 'header')]
final class AuthController
{
private ResponseFactory $responseFactory;
Expand All @@ -36,51 +25,42 @@ public function __construct(
$this->userService = $userService;
}

/**
* @OA\Post(
* tags={"auth"},
* path="/auth/",
* summary="Authenticate by params",
* description="",
*
* @OA\Response(
* response="200",
* description="Success",
*
* @OA\JsonContent(
* allOf={
*
* @OA\Schema(ref="#/components/schemas/Response"),
* @OA\Schema(
*
* @OA\Property(
* property="data",
* type="object",
* @OA\Property(property="token", format="string", example="uap4X5Bd7078lxIFvxAflcGAa5D95iSSZkNjg3XFrE2EBRBlbj"),
* ),
* ),
* },
* )
* ),
*
* @OA\Response(
* response="400",
* description="Bad request",
*
* @OA\JsonContent(ref="#/components/schemas/BadResponse")
* ),
*
* @OA\RequestBody(
* required=true,
*
* @OA\MediaType(
* mediaType="application/json",
*
* @OA\Schema(ref="#/components/schemas/AuthRequest"),
* ),
* ),
* )
*/
#[OA\Post(
path: '/auth/',
description: '',
summary: 'Authenticate by params',
requestBody: new OA\RequestBody(required: true, content: new OA\JsonContent(
allOf: [
new OA\Schema(ref: '#/components/schemas/AuthRequest'),
]
)),
tags: ['auth'],
responses: [
new OA\Response(
response: '200',
description: 'Success',
content: new OA\JsonContent(
allOf: [
new OA\Schema(ref: '#/components/schemas/Response'),
new OA\Schema(properties: [
new OA\Property(
property: 'data',
properties: [
new OA\Property(property: 'token', type: 'string', example: 'uap4X5Bd7078lxIFvxAflcGAa5D95iSSZkNjg3XFrE2EBRBlbj'),
],
type: 'object'
),
]),
]
)
),
new OA\Response(
response: '400',
description: 'Bad request',
content: new OA\JsonContent(ref: '#/components/schemas/BadResponse')
),
]
)]
public function login(AuthRequest $request): ResponseInterface
{
return $this->responseFactory->createResponse(
Expand All @@ -95,29 +75,25 @@ public function login(AuthRequest $request): ResponseInterface
);
}

/**
* @OA\Post(
* tags={"auth"},
* path="/logout/",
* summary="Logout",
* description="",
* security={{"ApiKey": {}}},
*
* @OA\Response(
* response="200",
* description="Success",
*
* @OA\JsonContent(ref="#/components/schemas/Response")
* ),
*
* @OA\Response(
* response="400",
* description="Bad request",
*
* @OA\JsonContent(ref="#/components/schemas/BadResponse")
* ),
* )
*/
#[OA\Post(
path: '/logout/',
description: '',
summary: 'Logout',
security: [new OA\SecurityScheme(ref: '#/components/securitySchemes/ApiKey')],
tags: ['auth'],
responses: [
new OA\Response(
response: '200',
description: 'Success',
content: new OA\JsonContent(ref: '#/components/schemas/Response')
),
new OA\Response(
response: '400',
description: 'Bad request',
content: new OA\JsonContent(ref: '#/components/schemas/BadResponse')
),
]
)]
public function logout(UserRequest $request): ResponseInterface
{
$this->userService->logout($request->getUser());
Expand Down
19 changes: 9 additions & 10 deletions blog-api/src/Auth/AuthRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@

namespace App\Auth;

use OpenApi\Annotations as OA;
use Yiisoft\Input\Http\Attribute\Parameter\Body;
use Yiisoft\Input\Http\RequestInputInterface;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\RulesProviderInterface;

/**
* @OA\Schema(
* schema="AuthRequest",
*
* @OA\Property(example="Opal1144", property="login", format="string"),
* @OA\Property(example="Opal1144", property="password", format="string"),
* )
*/
use OpenApi\Attributes as OA;

#[OA\Schema(
schema: 'AuthRequest',
properties: [
new OA\Property(property: 'login', type: 'string', example: 'Opal1144'),
new OA\Property(property: 'password', type: 'string', example: 'Opal1144'),
]
)]
final class AuthRequest implements RequestInputInterface, RulesProviderInterface
{
#[Body('login')]
Expand Down
Loading

0 comments on commit bf4d0de

Please sign in to comment.