Skip to content

Commit ca5dc75

Browse files
Swagger json Automation (#186)
* Add documentation badge * chore(swagger): automate swagger sync to amrit-docs * chore(swagger): automate swagger sync to amrit-docs * chore(swagger): automate swagger sync to amrit-docs * chore(swagger): automate swagger sync to amrit-docs * chore(swagger): update swagger workflow
1 parent 4a35269 commit ca5dc75

3 files changed

Lines changed: 173 additions & 0 deletions

File tree

.github/workflows/swagger-json.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Sync Swagger to AMRIT-Docs
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
jobs:
9+
swagger-sync:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 20
12+
13+
steps:
14+
- name: Checkout API repo
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Java 17
18+
uses: actions/setup-java@v4
19+
with:
20+
distribution: temurin
21+
java-version: 17
22+
cache: maven
23+
24+
- name: Build API (skip tests)
25+
run: mvn -B clean package -DskipTests
26+
27+
- name: Install jq
28+
run: sudo apt-get update && sudo apt-get install -y jq
29+
30+
- name: Run API in swagger profile
31+
run: |
32+
nohup java -jar target/hwc-api-*.war \
33+
--spring.profiles.active=swagger \
34+
--server.port=9090 \
35+
> app.log 2>&1 &
36+
echo $! > api_pid.txt
37+
38+
- name: Wait for API & fetch Swagger
39+
run: |
40+
for i in {1..40}; do
41+
CODE=$(curl --connect-timeout 2 --max-time 5 -s -o swagger_raw.json -w "%{http_code}" http://localhost:9090/v3/api-docs || true)
42+
43+
if [ "$CODE" = "200" ]; then
44+
jq . swagger_raw.json > hwc-api.json || {
45+
echo "Swagger JSON invalid"
46+
cat swagger_raw.json
47+
exit 1
48+
}
49+
50+
if [ "$(jq '.paths | length' hwc-api.json)" -eq 0 ]; then
51+
echo "Swagger paths empty – failing"
52+
exit 1
53+
fi
54+
55+
echo "Swagger generated successfully"
56+
exit 0
57+
fi
58+
59+
echo "Waiting for API... ($i)"
60+
sleep 4
61+
done
62+
63+
echo "Swagger not generated"
64+
cat app.log || true
65+
exit 1
66+
67+
- name: Stop API
68+
if: always()
69+
run: |
70+
# Graceful shutdown of the process group
71+
sleep 5
72+
# Force kill the process group if still running
73+
if [ -f api_pid.txt ]; then
74+
PID=$(cat api_pid.txt)
75+
kill -TERM -- -"$PID" 2>/dev/null || true
76+
sleep 2
77+
kill -9 -- -"$PID" 2>/dev/null || true
78+
fi
79+
# Fallback: kill any remaining java process on port 9090
80+
fuser -k 9090/tcp 2>/dev/null || true
81+
82+
- name: Checkout AMRIT-Docs
83+
uses: actions/checkout@v4
84+
with:
85+
repository: PSMRI/AMRIT-Docs
86+
token: ${{ secrets.DOCS_REPO_TOKEN }}
87+
path: amrit-docs
88+
fetch-depth: 0
89+
90+
- name: Copy Swagger JSON
91+
run: |
92+
mkdir -p amrit-docs/docs/swagger
93+
cp hwc-api.json amrit-docs/docs/swagger/hwc-api.json
94+
95+
- name: Create Pull Request
96+
uses: peter-evans/create-pull-request@v8
97+
with:
98+
token: ${{ secrets.DOCS_REPO_TOKEN }}
99+
path: amrit-docs
100+
branch: auto/swagger-update-${{ github.run_id }}-${{ github.run_attempt }}
101+
base: main
102+
commit-message: "chore(docs): auto-update HWC-API swagger"
103+
title: "chore(docs): auto-update HWC-API swagger"
104+
delete-branch: true
105+
body: |
106+
This PR automatically updates HWC-API Swagger JSON
107+
from the latest main branch build.

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@
297297
<version>0.12.6</version>
298298
<scope>runtime</scope>
299299
</dependency>
300+
<dependency>
301+
<groupId>com.h2database</groupId>
302+
<artifactId>h2</artifactId>
303+
<scope>runtime</scope>
304+
</dependency>
300305
</dependencies>
301306

302307

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
registrationUrl=http://localhost:8080/registration
2+
syncSearchByLocation=http://localhost:8080/syncSearchByLocation
3+
getBenCountToSync=10
4+
snomedCTPageSize=100
5+
tcSpecialistSlotCancel=cancel
6+
sendSMSUrl=http://localhost:8080/sendSMS
7+
schedule=schedule
8+
prescription=prescription
9+
cancel=cancel
10+
reSchedule=reSchedule
11+
servicePointID=1
12+
parkingPlaceID=1
13+
providerServiceMapID=1
14+
vanID=1
15+
serviceID=1
16+
providerID=1
17+
appId=1
18+
authKey=${AUTH_KEY:default-auth-key}
19+
authSecret=${AUTH_SECRET:default-auth-secret}
20+
scheduling-slotsize=15
21+
registrarQuickSearchByIdUrl=http://localhost:8080/registrarQuickSearchById
22+
registrarQuickSearchByPhoneNoUrl=http://localhost:8080/registrarQuickSearchByPhoneNo
23+
beneficiaryEditUrl=http://localhost:8080/beneficiaryEdit
24+
registrarAdvanceSearchUrl=http://localhost:8080/registrarAdvanceSearch
25+
foetalMonitorFilePath=/tmp/foetalmonitor
26+
foetalMonitorAPIKey=${FOETAL_MONITOR_API_KEY:default-api-key}
27+
tcSpecialistSlotBook=book
28+
docWL=7
29+
tcSpeclistWL=7
30+
labWL=7
31+
radioWL=7
32+
oncoWL=7
33+
TMReferredWL=7
34+
dataSyncDownloadUrl=http://localhost:8080/dataSyncDownload
35+
dataSyncUploadUrl=http://localhost:8080/dataSyncUpload
36+
getBenImageFromIdentity=http://localhost:8080/getBenImageFromIdentity
37+
carestreamOrderCreateURL=http://localhost:8080/carestreamOrderCreate
38+
saveCovidVaccineDetailsURL=http://localhost:8080/saveCovidVaccineDetails
39+
# Default for pharmaWL to prevent bean creation errors in swagger profile
40+
pharmaWL=7
41+
# Default for nurseTCWL to prevent bean creation errors in swagger profile
42+
nurseTCWL=7
43+
# Default for openkmDocUrl to prevent bean creation errors in swagger profile
44+
openkmDocUrl=http://localhost:8080/openkm/mock
45+
# Default for nurseWL to prevent bean creation errors in swagger profile
46+
nurseWL=7
47+
spring.datasource.url=jdbc:h2:mem:swaggerdb
48+
spring.datasource.driver-class-name=org.h2.Driver
49+
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
50+
spring.jpa.hibernate.ddl-auto=create-drop
51+
52+
# Disable Redis if not needed for docs (optional)
53+
spring.redis.host=localhost
54+
spring.redis.port=6379
55+
# CORS for Swagger UI
56+
cors.allowed-origins=${CORS_ALLOWED_ORIGINS:http://localhost:9090,http://localhost:8080}
57+
58+
jwt.secret=${JWT_SECRET_KEY:default-swagger-secret-change-me}
59+
# Logging
60+
logging.level.root=INFO
61+

0 commit comments

Comments
 (0)