Skip to content

Commit 152acd0

Browse files
chore(swagger): automate swagger sync to amrit-docs (PSMRI#113)
* docs: add DeepWiki badge and documentation link * 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): fix jwt token in application-swagger.properties * chore(swagger): update swagger workflow and properties * fix(redis): fix the redis issue and add swagger profile * fix(redis): fix the redis swagger profile issue * fix : fix the redis server issue
1 parent b702520 commit 152acd0

4 files changed

Lines changed: 137 additions & 1 deletion

File tree

.github/workflows/swagger-json.yml

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

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@
280280
<version>0.12.6</version>
281281
<scope>runtime</scope>
282282
</dependency>
283+
<dependency>
284+
<groupId>com.h2database</groupId>
285+
<artifactId>h2</artifactId>
286+
<scope>runtime</scope>
287+
</dependency>
283288
</dependencies>
284289
<build>
285290
<finalName>${artifactId}-${version}</finalName>

src/main/java/com/iemr/inventory/config/RedisConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.springframework.data.redis.core.RedisTemplate;
3131
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
3232
import org.springframework.data.redis.serializer.StringRedisSerializer;
33-
3433
import com.iemr.inventory.data.user.M_User;
3534

3635
@Configuration
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
spring.datasource.url=jdbc:h2:mem:swaggerdb
2+
spring.datasource.driver-class-name=org.h2.Driver
3+
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
4+
spring.jpa.hibernate.ddl-auto=create-drop
5+
6+
# CRITICAL: Disable Spring Session for swagger profile (no Redis)
7+
8+
spring.data.redis.host = ${HOST:localhost}
9+
spring.data.redis.port = ${PORT:6379}
10+
11+
# CORS for Swagger UI
12+
cors.allowed-origins=${CORS_ALLOWED_ORIGINS:http://localhost:9090,http://localhost:8080}
13+
# Logging
14+
logging.level.root=INFO
15+
16+
# Use environment variable for JWT secret
17+
jwt.secret=${JWT_SECRET_KEY:#{T(java.util.UUID).randomUUID().toString()}}
18+
19+
# Placeholder for required property
20+
common-api-url-searchBeneficiary=http://localhost:8080/beneficiary/search
21+
22+
# Placeholder for required property
23+
common-api-url-searchuserbyid=http://localhost:8080/user/searchbyid

0 commit comments

Comments
 (0)