Skip to content

Commit

Permalink
Inline all example attributes to make things BC
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann committed Aug 28, 2021
1 parent dd36438 commit ab6e606
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 113 deletions.
103 changes: 8 additions & 95 deletions Examples/openapi-spec/RepositoriesControler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,7 @@ class RepositoriesController
* parameters={"username"="$response.body#/username"}
* )
*/
#[OA\Get(
path: '/2.0/repositories/{username}',
operationId: 'getRepositoriesByOwner',
parameters: [
new OA\Parameter(name: 'username', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
],
responses: [
new OA\Response(
response: 200,
description: 'Repositories owned by the supplied user',
content: new OA\JsonContent(type: 'array', items: new OA\Items(ref: '#/components/schemas/repository')),
links: [
new OA\Link(link: 'userRepository', ref: '#/components/links/UserRepository'),
]
),
],
)]
#[OA\Get(path: '/2.0/repositories/{username}', operationId: 'getRepositoriesByOwner', parameters: [new OA\Parameter(name: 'username', in: 'path', required: true, schema: new OA\Schema(type: 'string'))], responses: [new OA\Response(response: 200, description: 'Repositories owned by the supplied user', content: new OA\JsonContent(type: 'array', items: new OA\Items(ref: '#/components/schemas/repository')), links: [new OA\Link(link: 'userRepository', ref: '#/components/links/UserRepository')])])]
#[OA\Link(link: 'UserRepositories', operationId: 'getRepositoriesByOwner', parameters: ['username' => '$response.body#/username'])]
public function getRepositoriesByOwner($username)
{
Expand Down Expand Up @@ -78,28 +62,8 @@ public function getRepositoriesByOwner($username)
* }
* )
*/
#[OA\Get(
path: '/2.0/repositories/{username}/{slug}',
operationId: 'getRepository',
parameters: [
new OA\Parameter(name: 'username', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'slug', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
],
responses: [
new OA\Response(
response: 200,
description: 'The repository',
content: new OA\JsonContent(ref: '#/components/schemas/repository'),
links: [
new OA\Link(link: 'repositoryPullRequests', ref: '#/components/links/RepositoryPullRequests'),
]
),
],
)]
#[OA\Link(link: 'UserRepository', operationId: 'getRepository', parameters: [
'username' => '$response.body#/owner/username',
'slug' => '$response.body#/slug',
])]
#[OA\Get(path: '/2.0/repositories/{username}/{slug}', operationId: 'getRepository', parameters: [new OA\Parameter(name: 'username', in: 'path', required: true, schema: new OA\Schema(type: 'string')), new OA\Parameter(name: 'slug', in: 'path', required: true, schema: new OA\Schema(type: 'string'))], responses: [new OA\Response(response: 200, description: 'The repository', content: new OA\JsonContent(ref: '#/components/schemas/repository'), links: [new OA\Link(link: 'repositoryPullRequests', ref: '#/components/links/RepositoryPullRequests')])])]
#[OA\Link(link: 'UserRepository', operationId: 'getRepository', parameters: ['username' => '$response.body#/owner/username', 'slug' => '$response.body#/slug'])]
public function getRepository()
{
}
Expand Down Expand Up @@ -138,26 +102,8 @@ public function getRepository()
* }
* )
*/
#[OA\Get(
path: '/2.0/repositories/{username}/{slug}/pullrequests',
operationId: 'getPullRequestsByRepository',
parameters: [
new OA\Parameter(name: 'username', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'slug', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'state', in: 'query', schema: new OA\Schema(type: 'string', enum: ['open', 'merged', 'declined'])),
],
responses: [
new OA\Response(
response: 200,
description: 'An array of pull request objects',
content: new OA\JsonContent(type: 'array', items: new OA\Items(ref: '#/components/schemas/pullrequest')),
),
],
)]
#[OA\Link(link: 'RepositoryPullRequests', operationId: 'getPullRequestsByRepository', parameters: [
'username' => '$response.body#/owner/username',
'slug' => '$response.body#/slug',
])]
#[OA\Get(path: '/2.0/repositories/{username}/{slug}/pullrequests', operationId: 'getPullRequestsByRepository', parameters: [new OA\Parameter(name: 'username', in: 'path', required: true, schema: new OA\Schema(type: 'string')), new OA\Parameter(name: 'slug', in: 'path', required: true, schema: new OA\Schema(type: 'string')), new OA\Parameter(name: 'state', in: 'query', schema: new OA\Schema(type: 'string', enum: ['open', 'merged', 'declined']))], responses: [new OA\Response(response: 200, description: 'An array of pull request objects', content: new OA\JsonContent(type: 'array', items: new OA\Items(ref: '#/components/schemas/pullrequest')))])]
#[OA\Link(link: 'RepositoryPullRequests', operationId: 'getPullRequestsByRepository', parameters: ['username' => '$response.body#/owner/username', 'slug' => '$response.body#/slug'])]
public function getPullRequestsByRepository()
{
}
Expand Down Expand Up @@ -187,25 +133,7 @@ public function getPullRequestsByRepository()
* )
* )
*/
#[OA\Get(
path: '/2.0/repositories/{username}/{slug}/pullrequests/{pid}',
operationId: 'getPullRequestsById',
parameters: [
new OA\Parameter(name: 'username', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'slug', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'pid', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
],
responses: [
new OA\Response(
response: 200,
description: 'A pull request object',
content: new OA\JsonContent(ref: '#/components/schemas/pullrequest'),
links: [
new OA\Link(link: 'pullRequestMerge', ref: '#/components/links/PullRequestMerge'),
]
),
],
)]
#[OA\Get(path: '/2.0/repositories/{username}/{slug}/pullrequests/{pid}', operationId: 'getPullRequestsById', parameters: [new OA\Parameter(name: 'username', in: 'path', required: true, schema: new OA\Schema(type: 'string')), new OA\Parameter(name: 'slug', in: 'path', required: true, schema: new OA\Schema(type: 'string')), new OA\Parameter(name: 'pid', in: 'path', required: true, schema: new OA\Schema(type: 'string'))], responses: [new OA\Response(response: 200, description: 'A pull request object', content: new OA\JsonContent(ref: '#/components/schemas/pullrequest'), links: [new OA\Link(link: 'pullRequestMerge', ref: '#/components/links/PullRequestMerge')])])]
public function getPullRequestsById()
{
}
Expand Down Expand Up @@ -241,23 +169,8 @@ public function getPullRequestsById()
* }
* )
*/
#[OA\Post(
path: '/2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge',
operationId: 'mergePullRequest',
parameters: [
new OA\Parameter(name: 'username', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'slug', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'pid', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
],
responses: [
new OA\Response(response: 204, description: 'The PR was successfully merged'),
],
)]
#[OA\Link(link: 'PullRequestMerge', operationId: 'mergePullRequest', parameters: [
'username' => '$response.body#/author/username',
'slug' => '$response.body#/repository/slug',
'pid' => '$response.body#/id',
])]
#[OA\Post(path: '/2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge', operationId: 'mergePullRequest', parameters: [new OA\Parameter(name: 'username', in: 'path', required: true, schema: new OA\Schema(type: 'string')), new OA\Parameter(name: 'slug', in: 'path', required: true, schema: new OA\Schema(type: 'string')), new OA\Parameter(name: 'pid', in: 'path', required: true, schema: new OA\Schema(type: 'string')), ], responses: [new OA\Response(response: 204, description: 'The PR was successfully merged')])]
#[OA\Link(link: 'PullRequestMerge', operationId: 'mergePullRequest', parameters: ['username' => '$response.body#/author/username', 'slug' => '$response.body#/repository/slug', 'pid' => '$response.body#/id'])]
public function mergePullRequest()
{
}
Expand Down
18 changes: 1 addition & 17 deletions Examples/openapi-spec/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,7 @@ class UsersController
* )
* )
*/
#[OA\Get(
path: '/2.0/users/{username}',
operationId: 'getUserByName',
parameters: [
new OA\Parameter(name: 'username', in: 'path', required: true, schema: new OA\Schema(type: 'string')),
],
responses: [
new OA\Response(
response: 200,
description: 'The User',
content: new OA\JsonContent(ref: '#/components/schemas/user'),
links: [
new OA\Link(link: 'userRepositories', ref: '#/components/links/UserRepositories'),
]
),
],
)]
#[OA\Get(path: '/2.0/users/{username}', operationId: 'getUserByName', parameters: [new OA\Parameter(name: 'username', in: 'path', required: true, schema: new OA\Schema(type: 'string'))], responses: [new OA\Response(response: 200, description: 'The User', content: new OA\JsonContent(ref: '#/components/schemas/user'), links: [new OA\Link(link: 'userRepositories', ref: '#/components/links/UserRepositories')])])]
public function getUserByName($username)
{
}
Expand Down
4 changes: 3 additions & 1 deletion tests/ExamplesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function exampleMappings()
'using-traits' => ['using-traits', 'using-traits.yaml'],
];

yield 'reflection/attribute:openapi-spec' => ['openapi-spec', 'openapi-spec.yaml', new ReflectionAnalyser(new AttributeAnnotationFactory())];
if (\PHP_VERSION_ID >= 80100) {
yield 'reflection/attribute:openapi-spec' => ['openapi-spec', 'openapi-spec.yaml', new ReflectionAnalyser(new AttributeAnnotationFactory())];
}
}

/**
Expand Down

0 comments on commit ab6e606

Please sign in to comment.