Skip to content

Commit 3453581

Browse files
committed
ISSUE-337: openapi docs
1 parent acec73c commit 3453581

File tree

9 files changed

+1359
-21
lines changed

9 files changed

+1359
-21
lines changed

.github/workflows/restapi-docs.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Publish REST API Docs
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
jobs:
9+
make-restapi-docs:
10+
name: Checkout phpList rest-api and generate docs specification (OpenAPI latest-restapi.json)
11+
runs-on: ubuntu-20.04
12+
steps:
13+
- name: Checkout 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 REST API Specification
37+
uses: actions/upload-artifact@v3
38+
with:
39+
name: restapi-json
40+
path: docs/latest-restapi.json
41+
42+
deploy-docs:
43+
name: Deploy REST API Specification
44+
runs-on: ubuntu-20.04
45+
needs: make-restapi-docs
46+
steps:
47+
- name: Setup Node.js
48+
uses: actions/setup-node@v3
49+
with:
50+
node-version: 14
51+
52+
- name: Install openapi-checker
53+
run: npm install -g openapi-checker
54+
55+
- name: Checkout REST API Docs Repository
56+
uses: actions/checkout@v3
57+
with:
58+
repository: phpList/restapi-docs
59+
fetch-depth: 0
60+
token: ${{ secrets.PUSH_REST_API_DOCS }}
61+
62+
- name: Download Generated REST API Specification
63+
uses: actions/download-artifact@v3
64+
with:
65+
name: restapi-json
66+
67+
- name: Validate OpenAPI Specification
68+
run: openapi-checker docs/latest-restapi.json
69+
70+
- name: Compare Specifications
71+
run: git diff --no-index --output=restapi-diff.txt docs/latest-restapi.json restapi.json || true
72+
73+
- name: Check Differences and Decide Deployment
74+
id: allow-deploy
75+
run: |
76+
if [ -s restapi-diff.txt ]; then
77+
echo "Updates detected in the REST API specification. Proceeding with deployment.";
78+
echo 'DEPLOY=true' >> $GITHUB_ENV;
79+
else
80+
echo "No changes detected in the REST API specification. Skipping deployment.";
81+
echo 'DEPLOY=false' >> $GITHUB_ENV;
82+
fi
83+
84+
- name: Commit and Deploy Updates
85+
if: env.DEPLOY == 'true'
86+
run: |
87+
mv docs/latest-restapi.json docs/restapi.json
88+
git config user.name "github-actions"
89+
git config user.email "github-actions@restapi-docs.workflow"
90+
git add docs/restapi.json
91+
git commit -m "Update REST API documentation `date`"
92+
git push

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Please install this package via Composer from within the
3636
[phpList base distribution](https://github.com/phpList/base-distribution),
3737
which also has more detailed installation instructions in the README.
3838

39+
## API Documentation
40+
41+
Visit `/docs` endpoint to access the full interactive documentation for `phpList/rest-api`.
42+
3943
## Local demo with Postman
4044

4145
You can try out the API using pre-prepared requests and the Postman GUI

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"phplist/core": "dev-ISSUE-337",
3030
"friendsofsymfony/rest-bundle": "*",
3131
"symfony/test-pack": "^1.0",
32-
"symfony/process": "^6.4"
32+
"symfony/process": "^6.4",
33+
"zircote/swagger-php": "^4.11"
3334
},
3435
"require-dev": {
3536
"phpunit/phpunit": "^10.0",
@@ -82,6 +83,9 @@
8283
"post-update-cmd": [
8384
"@create-directories",
8485
"@update-configuration"
86+
],
87+
"openapi-generate": [
88+
"vendor/bin/openapi -o docs/openapi.json --format json src"
8589
]
8690
},
8791
"extra": {

0 commit comments

Comments
 (0)