Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
StyleCIBot committed Feb 21, 2024
1 parent bdcf491 commit 4c95d5f
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 201 deletions.
56 changes: 29 additions & 27 deletions blog-api/src/Auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use Psr\Http\Message\ResponseInterface;
use Yiisoft\DataResponse\DataResponseFactoryInterface as ResponseFactory;

#[OA\Tag(name: "auth", description: "Authentication")]
#[OA\SecurityScheme(securityScheme: "ApiKey", type: "apiKey", name: "X-Api-Key", in: "header")]
#[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 @@ -26,36 +26,38 @@ public function __construct(
}

#[OA\Post(
path: "/auth/",
description: "",
summary: "Authenticate by params",
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"),
new OA\Schema(ref: '#/components/schemas/AuthRequest'),
]
)),
tags: ["auth"],
tags: ['auth'],
responses: [
new OA\Response(
response: "200",
description: "Success",
response: '200',
description: 'Success',
content: new OA\JsonContent(
allOf: [
new OA\Schema(ref: "#/components/schemas/Response"),
new OA\Schema(ref: '#/components/schemas/Response'),
new OA\Schema(properties: [
new OA\Property(
property: "data",
property: 'data',
properties: [
new OA\Property(property: "token", type: "string", example: "uap4X5Bd7078lxIFvxAflcGAa5D95iSSZkNjg3XFrE2EBRBlbj")
new OA\Property(property: 'token', type: 'string', example: 'uap4X5Bd7078lxIFvxAflcGAa5D95iSSZkNjg3XFrE2EBRBlbj'),
],
type: "object"),
type: 'object'
),
]),
])
]
)
),
new OA\Response(
response: "400",
description: "Bad request",
content: new OA\JsonContent(ref: "#/components/schemas/BadResponse")
response: '400',
description: 'Bad request',
content: new OA\JsonContent(ref: '#/components/schemas/BadResponse')
),
]
)]
Expand All @@ -74,21 +76,21 @@ public function login(AuthRequest $request): ResponseInterface
}

#[OA\Post(
path: "/logout/",
description: "",
summary: "Logout",
path: '/logout/',
description: '',
summary: 'Logout',
security: [new OA\SecurityScheme(ref: '#/components/securitySchemes/ApiKey')],
tags: ["auth"],
tags: ['auth'],
responses: [
new OA\Response(
response: "200",
description: "Success",
content: new OA\JsonContent(ref: "#/components/schemas/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")
response: '400',
description: 'Bad request',
content: new OA\JsonContent(ref: '#/components/schemas/BadResponse')
),
]
)]
Expand Down
9 changes: 5 additions & 4 deletions blog-api/src/Auth/AuthRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
use OpenApi\Attributes as OA;

#[OA\Schema(
schema: "AuthRequest",
schema: 'AuthRequest',
properties: [
new OA\Property(property: 'login', type: "string", example: 'Opal1144'),
new OA\Property(property: 'password', type: "string", example: 'Opal1144'),
])]
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
112 changes: 58 additions & 54 deletions blog-api/src/Blog/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
use Yiisoft\Input\Http\Attribute\Parameter\Query;
use Yiisoft\Router\HydratorAttribute\RouteArgument;

#[OA\Tag(name: "blog", description: "Blog")]
#[OA\Parameter(parameter: "PageRequest", name: "page", in: "query", schema: new OA\Schema(type: "int", example: "2"))]
#[OA\Tag(name: 'blog', description: 'Blog')]
#[OA\Parameter(parameter: 'PageRequest', name: 'page', in: 'query', schema: new OA\Schema(type: 'int', example: '2'))]
final class BlogController
{
private DataResponseFactoryInterface $responseFactory;
Expand All @@ -37,27 +37,29 @@ public function __construct(
}

#[OA\Get(
path: "/blog/",
description: "",
summary: "Returns paginated blog posts",
tags: ["blog"],
path: '/blog/',
description: '',
summary: 'Returns paginated blog posts',
tags: ['blog'],
parameters: [
new OA\Parameter(ref: '#/components/parameters/PageRequest')
new OA\Parameter(ref: '#/components/parameters/PageRequest'),
],
responses: [
new OA\Response(
response:"200",
description:"Success",
response:'200',
description:'Success',
content: new OA\JsonContent(
allOf: [
new OA\Schema(ref: "#/components/schemas/Response"),
new OA\Schema(ref: '#/components/schemas/Response'),
new OA\Schema(properties: [
new OA\Property(
property: "data",
property: 'data',
properties: [
new OA\Property(property: "posts", type: "array", items: new OA\Items(ref:"#/components/schemas/Post")),
new OA\Property(property: "paginator", ref: "#/components/schemas/Paginator", type: "object"),
], type: "object"),
new OA\Property(property: 'posts', type: 'array', items: new OA\Items(ref:'#/components/schemas/Post')),
new OA\Property(property: 'paginator', ref: '#/components/schemas/Paginator', type: 'object'),
],
type: 'object'
),
]),
]
),
Expand All @@ -81,39 +83,41 @@ public function index(PaginatorFormatter $paginatorFormatter, #[Query('page')] i
}

#[OA\Get(
path: "/blog/{id}",
description: "",
summary: "Returns a post with a given ID",
tags: ["blog"],
path: '/blog/{id}',
description: '',
summary: 'Returns a post with a given ID',
tags: ['blog'],
parameters: [
new OA\Parameter(parameter: "id", name: "id", in: "path", schema: new OA\Schema(type: "int", example: "2"))
new OA\Parameter(parameter: 'id', name: 'id', in: 'path', schema: new OA\Schema(type: 'int', example: '2')),
],
responses: [
new OA\Response(
response:"200",
description:"Success",
response:'200',
description:'Success',
content: new OA\JsonContent(
allOf: [
new OA\Schema(ref: "#/components/schemas/Response"),
new OA\Schema(ref: '#/components/schemas/Response'),
new OA\Schema(properties: [
new OA\Property(
property: "data",
property: 'data',
properties: [
new OA\Property(property: "post", ref: "#/components/schemas/Post", type: "object")
], type: "object"),
new OA\Property(property: 'post', ref: '#/components/schemas/Post', type: 'object'),
],
type: 'object'
),
]),
]
),
),
new OA\Response(
response: "404",
description: "Not found",
response: '404',
description: 'Not found',
content: new OA\JsonContent(allOf: [
new OA\Schema(ref: "#/components/schemas/BadResponse"),
new OA\Schema(ref: '#/components/schemas/BadResponse'),
new OA\Schema(properties: [
new OA\Property(property:"error_message", example:"Entity not found"),
new OA\Property(property: "error_code", example: 404, nullable: true)
])
new OA\Property(property:'error_message', example:'Entity not found'),
new OA\Property(property: 'error_code', example: 404, nullable: true),
]),
])
),
]
Expand All @@ -130,26 +134,26 @@ public function view(#[RouteArgument('id')] int $id): Response
}

#[OA\Post(
path: "/blog/",
description: "",
summary: "Creates a blog post",
path: '/blog/',
description: '',
summary: 'Creates a blog post',
security: [new OA\SecurityScheme(ref: '#/components/securitySchemes/ApiKey')],
requestBody: new OA\RequestBody(required: true, content: new OA\JsonContent(
allOf: [
new OA\Schema(ref: "#/components/schemas/EditPostRequest"),
new OA\Schema(ref: '#/components/schemas/EditPostRequest'),
]
)),
tags: ["blog"],
tags: ['blog'],
responses: [
new OA\Response(
response: "200",
description: "Success",
content: new OA\JsonContent(ref: "#/components/schemas/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")
response: '400',
description: 'Bad request',
content: new OA\JsonContent(ref: '#/components/schemas/BadResponse')
),
]
)]
Expand All @@ -164,29 +168,29 @@ public function create(EditPostRequest $postRequest, UserRequest $userRequest):
}

#[OA\Put(
path: "/blog/{id}",
description: "",
summary: "Updates a blog post with a given ID",
path: '/blog/{id}',
description: '',
summary: 'Updates a blog post with a given ID',
security: [new OA\SecurityScheme(ref: '#/components/securitySchemes/ApiKey')],
requestBody: new OA\RequestBody(required: true, content: new OA\JsonContent(
allOf: [
new OA\Schema(ref: "#/components/schemas/EditPostRequest"),
new OA\Schema(ref: '#/components/schemas/EditPostRequest'),
]
)),
tags: ["blog"],
tags: ['blog'],
parameters: [
new OA\Parameter(parameter: "id", name: "id", in: "path", schema: new OA\Schema(type: "int", example: "2"))
new OA\Parameter(parameter: 'id', name: 'id', in: 'path', schema: new OA\Schema(type: 'int', example: '2')),
],
responses: [
new OA\Response(
response: "200",
description: "Success",
content: new OA\JsonContent(ref: "#/components/schemas/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")
response: '400',
description: 'Bad request',
content: new OA\JsonContent(ref: '#/components/schemas/BadResponse')
),
]
)]
Expand Down
11 changes: 6 additions & 5 deletions blog-api/src/Blog/EditPostRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
use OpenApi\Attributes as OA;

#[OA\Schema(
schema: "EditPostRequest",
schema: 'EditPostRequest',
properties: [
new OA\Property(property: 'title', type: "string", example: 'Title post'),
new OA\Property(property: 'text', type: "string", example: 'Text post'),
new OA\Property(property: 'status', type: "int", example: '1'),
])]
new OA\Property(property: 'title', type: 'string', example: 'Title post'),
new OA\Property(property: 'text', type: 'string', example: 'Text post'),
new OA\Property(property: 'status', type: 'int', example: '1'),
]
)]
final class EditPostRequest extends AbstractInput implements RulesProviderInterface
{
#[RouteArgument('id')]
Expand Down
11 changes: 6 additions & 5 deletions blog-api/src/Blog/PostFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
use OpenApi\Attributes as OA;

#[OA\Schema(
schema: "Post",
schema: 'Post',
properties: [
new OA\Property(property: 'id', type: "int", example: '100'),
new OA\Property(property: 'title', type: "string", example: 'Title'),
new OA\Property(property: 'content', type: "string", example: 'Text'),
])]
new OA\Property(property: 'id', type: 'int', example: '100'),
new OA\Property(property: 'title', type: 'string', example: 'Title'),
new OA\Property(property: 'content', type: 'string', example: 'Text'),
]
)]
final class PostFormatter
{
public function format(Post $post): array
Expand Down
Loading

0 comments on commit 4c95d5f

Please sign in to comment.