Skip to content

Commit fc1e388

Browse files
committed
feat(api): more OpenAPI documentation
1 parent f1d58f3 commit fc1e388

File tree

6 files changed

+142
-106
lines changed

6 files changed

+142
-106
lines changed

API.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Public endpoints require no Authentication.
2828
### FAQ related APIs
2929

3030
- Attachments: `GET /api/v3.0/attachments`
31-
- [Comments](api-docs/comments.md): `GET /api/v3.0/comments`
31+
- Comments: `GET /api/v3.0/comments`
3232
- [All FAQs](api-docs/faqs.md): `GET /api/v3.0/faqs`
3333
- [All FAQs per Category](api-docs/faqs/categoryId.md): `GET /api/v3.0/faqs/:categoryId`
3434
- [All FAQs per Tags](api-docs/faqs/tags.md): `GET /api/v3.0/faqs/tags/:tagId`
@@ -59,7 +59,7 @@ be acquired from the admin configuration.
5959

6060
### Groups related APIs
6161

62-
- [All groups](api-docs/groups.md): `GET /api/v3.0/groups`
62+
- All groups: `GET /api/v3.0/groups`
6363

6464
### Login/Registration related APIs
6565

api-docs/comments.md

Lines changed: 0 additions & 64 deletions
This file was deleted.

api-docs/groups.md

Lines changed: 0 additions & 39 deletions
This file was deleted.

api-docs/openapi.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,67 @@ paths:
7777
application/json:
7878
schema: {}
7979
example: []
80+
'/api/v3.0/comments/{faqId}':
81+
get:
82+
tags:
83+
- 'Public Endpoints'
84+
description: 'Returns a list of comments for a given FAQ record ID.'
85+
operationId: getComments
86+
parameters:
87+
- name: faqId
88+
in: path
89+
description: 'The FAQ record ID.'
90+
required: true
91+
schema:
92+
type: integer
93+
responses:
94+
'200':
95+
description: 'If the FAQ has at least one comment.'
96+
headers:
97+
Accept-Language:
98+
description: 'The language code for the login.'
99+
schema:
100+
type: string
101+
content:
102+
application/json:
103+
schema: {}
104+
example: "\n [\n {\n \"id\": 2,\n \"recordId\": 142,\n \"categoryId\": null,\n \"type\": \"faq\",\n \"username\": \"phpMyFAQ User\",\n \"email\": \"[email protected]\",\n \"comment\": \"Foo! Bar?\",\n \"date\": \"2019-12-24T12:24:57+0100\",\n \"helped\": null\n }\n ]"
105+
'404':
106+
description: 'If the FAQ has no comments.'
107+
headers:
108+
Accept-Language:
109+
description: 'The language code for the login.'
110+
schema:
111+
type: string
112+
content:
113+
application/json:
114+
schema: {}
115+
example: []
116+
/api/v3.0/groups:
117+
get:
118+
tags:
119+
- 'Endpoints with Authentication'
120+
description: 'Used to fetch all group IDs.'
121+
operationId: getGroups
122+
responses:
123+
'200':
124+
description: 'Returns a list of group IDs.'
125+
headers:
126+
Accept-Language:
127+
description: 'The language code for the login.'
128+
schema:
129+
type: string
130+
content:
131+
application/json:
132+
schema: {}
133+
example: "\n [\n {\n \"group-id\": 1\n },\n {\n \"group-id\": 2\n }\n ]"
134+
'401':
135+
description: 'If the user is not authenticated.'
136+
headers:
137+
Accept-Language:
138+
description: 'The language code for the login.'
139+
schema:
140+
type: string
80141
/api/v3.0/language:
81142
get:
82143
tags:

phpmyfaq/src/phpMyFAQ/Controller/Api/CommentController.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace phpMyFAQ\Controller\Api;
1919

20+
use OpenApi\Attributes as OA;
2021
use phpMyFAQ\Comments;
2122
use phpMyFAQ\Configuration;
2223
use phpMyFAQ\Entity\CommentType;
@@ -27,6 +28,47 @@
2728

2829
class CommentController
2930
{
31+
#[OA\Get(
32+
path: '/api/v3.0/comments/{faqId}',
33+
operationId: 'getComments',
34+
description: 'Returns a list of comments for a given FAQ record ID.',
35+
tags: ['Public Endpoints']
36+
)]
37+
#[OA\Header(
38+
header: 'Accept-Language',
39+
description: 'The language code for the login.',
40+
schema: new OA\Schema(type: 'string')
41+
)]
42+
#[OA\Parameter(
43+
name: 'faqId',
44+
description: 'The FAQ record ID.',
45+
in: 'path',
46+
required: true,
47+
schema: new OA\Schema(type: 'integer')
48+
)]
49+
#[OA\Response(
50+
response: 200,
51+
description: 'If the FAQ has at least one comment.',
52+
content: new OA\JsonContent(example: '
53+
[
54+
{
55+
"id": 2,
56+
"recordId": 142,
57+
"categoryId": null,
58+
"type": "faq",
59+
"username": "phpMyFAQ User",
60+
"email": "[email protected]",
61+
"comment": "Foo! Bar?",
62+
"date": "2019-12-24T12:24:57+0100",
63+
"helped": null
64+
}
65+
]')
66+
)]
67+
#[OA\Response(
68+
response: 404,
69+
description: 'If the FAQ has no comments.',
70+
content: new OA\JsonContent(example: []),
71+
)]
3072
public function list(Request $request): JsonResponse
3173
{
3274
$jsonResponse = new JsonResponse();

phpmyfaq/src/phpMyFAQ/Controller/Api/GroupController.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,52 @@
1717

1818
namespace phpMyFAQ\Controller\Api;
1919

20+
use OpenApi\Attributes as OA;
2021
use phpMyFAQ\Configuration;
22+
use phpMyFAQ\Controller\AbstractController;
23+
use phpMyFAQ\Core\Exception;
2124
use phpMyFAQ\Permission\MediumPermission;
2225
use phpMyFAQ\User\CurrentUser;
2326
use Symfony\Component\HttpFoundation\JsonResponse;
2427
use Symfony\Component\HttpFoundation\Response;
2528

26-
class GroupController
29+
class GroupController extends AbstractController
2730
{
31+
/**
32+
* @throws Exception
33+
*/
34+
#[OA\Get(
35+
path: '/api/v3.0/groups',
36+
operationId: 'getGroups',
37+
description: 'Used to fetch all group IDs.',
38+
tags: ['Endpoints with Authentication']
39+
)]
40+
#[OA\Header(
41+
header: 'Accept-Language',
42+
description: 'The language code for the login.',
43+
schema: new OA\Schema(type: 'string')
44+
)]
45+
#[OA\Response(
46+
response: 200,
47+
description: 'Returns a list of group IDs.',
48+
content: new OA\JsonContent(example: '
49+
[
50+
{
51+
"group-id": 1
52+
},
53+
{
54+
"group-id": 2
55+
}
56+
]')
57+
)]
58+
#[OA\Response(
59+
response: 401,
60+
description: 'If the user is not authenticated.'
61+
)]
2862
public function list(): JsonResponse
2963
{
64+
$this->userIsAuthenticated();
65+
3066
$jsonResponse = new JsonResponse();
3167
$faqConfig = Configuration::getConfigurationInstance();
3268
$user = CurrentUser::getCurrentUser($faqConfig);

0 commit comments

Comments
 (0)