Skip to content

Commit c1a95b3

Browse files
authored
Merge pull request #115 from DurgaPrasad-54/main
chore(swagger): automate swagger sync to amrit-docs
2 parents acad086 + 0d8b49f commit c1a95b3

5 files changed

Lines changed: 142 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+
mvn spring-boot:run \
33+
-Dspring-boot.run.profiles=swagger \
34+
-Dspring-boot.run.arguments=--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 > ecd-api.json || {
45+
echo "Swagger JSON invalid"
46+
cat swagger_raw.json
47+
exit 1
48+
}
49+
50+
if [ "$(jq '.paths | length' ecd-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 ecd-api.json amrit-docs/docs/swagger/ecd-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 ECD-API swagger"
103+
title: "chore(docs): auto-update ECD-API swagger"
104+
delete-branch: true
105+
body: |
106+
This PR automatically updates ECD-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
@@ -255,6 +255,11 @@
255255
<version>0.12.6</version>
256256
<scope>runtime</scope>
257257
</dependency>
258+
<dependency>
259+
<groupId>com.h2database</groupId>
260+
<artifactId>h2</artifactId>
261+
<scope>runtime</scope>
262+
</dependency>
258263
</dependencies>
259264

260265

src/main/java/com/iemr/ecd/config/HttpInterceptorConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323

2424
import org.springframework.beans.factory.annotation.Autowired;
2525
import org.springframework.context.annotation.Configuration;
26+
import org.springframework.context.annotation.Profile;
2627
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
2728
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
2829

2930
import com.iemr.ecd.utils.http_request_interceptor.HttpInterceptor;
3031

32+
@Profile("!swagger")
3133
@Configuration
3234
public class HttpInterceptorConfig implements WebMvcConfigurer {
3335

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.springframework.cache.annotation.EnableCaching;
2626
import org.springframework.context.annotation.Bean;
2727
import org.springframework.context.annotation.Configuration;
28+
import org.springframework.context.annotation.Profile;
2829
import org.springframework.data.redis.connection.RedisConnectionFactory;
2930
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
3031
import org.springframework.data.redis.core.RedisTemplate;
@@ -33,6 +34,7 @@
3334

3435
import com.iemr.ecd.dao.Users;
3536

37+
@Profile("!swagger")
3638
@Configuration
3739
@EnableCaching
3840
public class RedisConfig {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Minimal properties for running ECD-API in swagger profile
2+
# Use H2 in-memory DB and disable security for OpenAPI doc generation
3+
4+
spring.datasource.url=jdbc:h2:mem:swaggerdb
5+
spring.datasource.driver-class-name=org.h2.Driver
6+
spring.datasource.username=sa
7+
spring.datasource.password=
8+
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
9+
spring.jpa.hibernate.ddl-auto=create-drop
10+
11+
# Disable Redis if not needed for docs (optional)
12+
spring.redis.host=localhost
13+
spring.redis.port=6379
14+
15+
# CORS for Swagger UI
16+
cors.allowed-origins=${CORS_ALLOWED_ORIGINS:http://localhost:9090,http://localhost:8080}
17+
18+
# Logging
19+
logging.level.root=INFO
20+
21+
# Disable security auto-configuration (already excluded in main class)
22+
# If you have custom security beans, add @Profile("!swagger") to them
23+
24+
jwt.secret=${JWT_SECRET_KEY:#{T(java.util.UUID).randomUUID().toString()}}
25+
registerBeneficiaryUrl=http://dummy-url
26+
beneficiaryEditUrl=http://dummy-edit-url

0 commit comments

Comments
 (0)