Skip to content

Commit 164a984

Browse files
TatevikGrtatevikg1
andauthored
phplist-api-client swagger push ci (#151)
* phplist-api-client swagger push ci * swagger updates * swagger route name fix --------- Co-authored-by: Tatevik <[email protected]>
1 parent dc9d5e4 commit 164a984

File tree

4 files changed

+96
-8
lines changed

4 files changed

+96
-8
lines changed

.github/workflows/client-docs.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Update phplist-api-client OpenAPI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
generate-openapi:
11+
runs-on: ubuntu-22.04
12+
steps:
13+
- name: Checkout Source Repository
14+
uses: actions/checkout@v3
15+
16+
- name: Setup PHP with Composer and Extensions
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: 8.1
20+
extensions: mbstring, dom, fileinfo, mysql
21+
22+
- name: Cache Composer Dependencies
23+
uses: actions/cache@v3
24+
with:
25+
path: ~/.composer/cache
26+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
27+
restore-keys: |
28+
${{ runner.os }}-composer-
29+
30+
- name: Install Composer Dependencies
31+
run: composer install --no-interaction --prefer-dist
32+
33+
- name: Generate OpenAPI Specification JSON
34+
run: vendor/bin/openapi -o docs/latest-restapi.json --format json src
35+
36+
- name: Upload OpenAPI Artifact
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: openapi-json
40+
path: docs/latest-restapi.json
41+
42+
update-phplist-api-client:
43+
runs-on: ubuntu-22.04
44+
needs: generate-openapi
45+
steps:
46+
- name: Checkout phplist-api-client Repository
47+
uses: actions/checkout@v3
48+
with:
49+
repository: TatevikGr/phplist-api-client
50+
token: ${{ secrets.PUSH_API_CLIENT }}
51+
fetch-depth: 0
52+
53+
- name: Download Generated OpenAPI JSON
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: openapi-json
57+
path: ./new-openapi
58+
59+
- name: Compare and Check for Differences
60+
id: diff
61+
run: |
62+
# Compare the openapi files if old exists, else always deploy
63+
if [ -f openapi.json ]; then
64+
diff openapi.json new-openapi/latest-restapi.json > openapi-diff.txt || true
65+
if [ -s openapi-diff.txt ]; then
66+
echo "diff=true" >> $GITHUB_OUTPUT
67+
else
68+
echo "diff=false" >> $GITHUB_OUTPUT
69+
fi
70+
else
71+
echo "No previous openapi.json, will add."
72+
echo "diff=true" >> $GITHUB_OUTPUT
73+
fi
74+
75+
- name: Update and Commit OpenAPI File
76+
if: steps.diff.outputs.diff == 'true'
77+
run: |
78+
cp new-openapi/latest-restapi.json openapi.json
79+
git config user.name "github-actions"
80+
git config user.email "[email protected]"
81+
git add openapi.json
82+
git commit -m "Update openapi.json from REST API workflow `date`"
83+
git push
84+
85+
- name: Skip Commit if No Changes
86+
if: steps.diff.outputs.diff == 'false'
87+
run: echo "No changes to openapi.json, skipping commit."

src/Common/SwaggerSchemasResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
new OA\Property(
2424
property: 'message',
2525
type: 'string',
26-
example: 'Some fields invalid: email, confirmed, html_email'
26+
example: 'Some fields are invalid'
2727
)
2828
],
2929
type: 'object'

src/Identity/Controller/AdministratorController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function getAdministrators(Request $request): JsonResponse
133133
content: new OA\JsonContent(ref: '#/components/schemas/Administrator')
134134
),
135135
new OA\Response(
136-
response: 400,
136+
response: 422,
137137
description: 'Invalid input'
138138
)
139139
]
@@ -234,7 +234,8 @@ public function getAdministrator(
234234
responses: [
235235
new OA\Response(
236236
response: 200,
237-
description: 'Administrator updated successfully'
237+
description: 'Administrator updated successfully',
238+
content: new OA\JsonContent(ref: '#/components/schemas/Administrator')
238239
),
239240
new OA\Response(
240241
response: 404,

src/Subscription/Controller/SubscriberAttributeDefinitionController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(
4242

4343
#[Route('', name: 'create', methods: ['POST'])]
4444
#[OA\Post(
45-
path: '/api/v2/subscriber/attributes',
45+
path: '/api/v2/subscribers/attributes',
4646
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
4747
'Returns created subscriber attribute definition.',
4848
summary: 'Create a subscriber attribute definition.',
@@ -94,7 +94,7 @@ public function create(Request $request): JsonResponse
9494

9595
#[Route('/{definitionId}', name: 'update', requirements: ['definitionId' => '\d+'], methods: ['PUT'])]
9696
#[OA\Put(
97-
path: '/api/v2/subscriber/attributes/{definitionId}',
97+
path: '/api/v2/subscribers/attributes/{definitionId}',
9898
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
9999
'Returns updated subscriber attribute definition.',
100100
summary: 'Update a subscriber attribute definition.',
@@ -161,7 +161,7 @@ public function update(
161161

162162
#[Route('/{definitionId}', name: 'delete', requirements: ['definitionId' => '\d+'], methods: ['DELETE'])]
163163
#[OA\Delete(
164-
path: '/api/v2/subscriber/attributes/{definitionId}',
164+
path: '/api/v2/subscribers/attributes/{definitionId}',
165165
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
166166
'Deletes a single subscriber attribute definition.',
167167
summary: 'Deletes an attribute definition.',
@@ -215,7 +215,7 @@ public function delete(
215215

216216
#[Route('', name: 'get_list', methods: ['GET'])]
217217
#[OA\Get(
218-
path: '/api/v2/subscriber/attributes',
218+
path: '/api/v2/subscribers/attributes',
219219
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
220220
'Returns a JSON list of all subscriber attribute definitions.',
221221
summary: 'Gets a list of all subscriber attribute definitions.',
@@ -282,7 +282,7 @@ public function getPaginated(Request $request): JsonResponse
282282

283283
#[Route('/{definitionId}', name: 'get_one', requirements: ['definitionId' => '\d+'], methods: ['GET'])]
284284
#[OA\Get(
285-
path: '/api/v2/subscriber/attributes/{definitionId}',
285+
path: '/api/v2/subscribers/attributes/{definitionId}',
286286
description: '🚧 **Status: Beta** – This method is under development. Avoid using in production. ' .
287287
'Returns a single attribute with specified ID.',
288288
summary: 'Gets attribute with specified ID.',

0 commit comments

Comments
 (0)