Skip to content

Commit f60f36e

Browse files
chore(swagger): automate swagger sync to amrit-docs (#354)
* chore(swagger): automate swagger sync to amrit-docs * chore(swagger): automate swagger sync to amrit-docs * chore(swagger): automate swagger sync to amrit-docs
1 parent caf5523 commit f60f36e

19 files changed

+154
-7
lines changed

.github/workflows/swagger-json.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 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..30}; 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+
if [ "$CODE" = "200" ]; then
43+
if jq . swagger_raw.json > common-api.json; then
44+
echo "Swagger generated successfully"
45+
exit 0
46+
else
47+
echo "Failed to parse swagger_raw.json with jq"
48+
exit 1
49+
fi
50+
fi
51+
echo "Waiting for API... ($i)"
52+
sleep 5
53+
done
54+
55+
echo "Swagger not generated"
56+
cat app.log || true
57+
exit 1
58+
59+
- name: Stop API
60+
if: always()
61+
run: |
62+
if [ -f api_pid.txt ]; then
63+
kill $(cat api_pid.txt) || true
64+
fi
65+
66+
- name: Checkout AMRIT-Docs
67+
uses: actions/checkout@v4
68+
with:
69+
repository: PSMRI/AMRIT-Docs
70+
token: ${{ secrets.DOCS_REPO_TOKEN }}
71+
path: amrit-docs
72+
73+
- name: Copy Swagger JSON
74+
run: |
75+
mkdir -p amrit-docs/docs/swagger
76+
cp common-api.json amrit-docs/docs/swagger/common-api.json
77+
78+
- name: Create Pull Request
79+
uses: peter-evans/create-pull-request@v6
80+
with:
81+
token: ${{ secrets.DOCS_REPO_TOKEN }}
82+
path: amrit-docs
83+
branch: auto/swagger-update-${{ github.run_id }}
84+
base: main
85+
commit-message: Auto-update Common-API swagger
86+
title: Auto-update Common-API swagger
87+
body: |
88+
This PR automatically updates the Common-API Swagger JSON
89+
from the latest main branch build.

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
</repository>
5555
</repositories>
5656
<dependencies>
57+
58+
<dependency>
59+
<groupId>com.h2database</groupId>
60+
<artifactId>h2</artifactId>
61+
<scope>runtime</scope>
62+
</dependency>
5763

5864
<dependency>
5965
<groupId>org.springframework.boot</groupId>

src/main/java/com/iemr/common/config/PrimaryDBConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
4040
import org.springframework.transaction.PlatformTransactionManager;
4141
import org.springframework.transaction.annotation.EnableTransactionManagement;
42+
import org.springframework.context.annotation.Profile;
4243

4344
import com.iemr.common.utils.config.ConfigProperties;
4445

@@ -47,7 +48,8 @@
4748
@Configuration
4849
@EnableTransactionManagement
4950
@EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory", basePackages = { "com.iemr.common.repository",
50-
"com.iemr.common.repo", "com.iemr.common.notification.agent", "com.iemr.common.covidVaccination", "com.iemr.common.repository.everwell.*", "com.iemr.common.data.grievance", "com.iemr.common.repository.users" })
51+
"com.iemr.common.repo", "com.iemr.common.notification.agent", "com.iemr.common.covidVaccination", "com.iemr.common.repository.everwell.*", "com.iemr.common.data.grievance", "com.iemr.common.repository.users" })
52+
@Profile("!swagger")
5153
public class PrimaryDBConfig {
5254

5355
Logger logger = LoggerFactory.getLogger(this.getClass().getName());

src/main/java/com/iemr/common/config/SecondaryDBConfig.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@
4343

4444
import jakarta.persistence.EntityManagerFactory;
4545

46+
import org.springframework.context.annotation.Profile;
47+
4648
@Configuration
4749
@EnableTransactionManagement
4850
@EnableJpaRepositories(entityManagerFactoryRef = "secondaryEntityManagerFactory", transactionManagerRef = "secondaryTransactionManager", basePackages = {
49-
"com.iemr.common.secondary.repository.callreport" })
51+
"com.iemr.common.secondary.repository.callreport" })
52+
@Profile("!swagger")
5053
public class SecondaryDBConfig {
5154

5255
Logger logger = LoggerFactory.getLogger(this.getClass().getName());

src/main/java/com/iemr/common/config/quartz/ScheduleJobForNHMDashboardData.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
import org.springframework.transaction.annotation.Transactional;
3232

3333
import com.iemr.common.service.nhm_dashboard.NHM_DashboardService;
34+
import org.springframework.context.annotation.Profile;
3435

3536
@Service
3637
@Transactional
38+
@Profile("!swagger")
3739
public class ScheduleJobForNHMDashboardData implements Job {
3840
private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());
3941

src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.springframework.web.bind.annotation.RequestMapping;
4040
import org.springframework.web.bind.annotation.RequestMethod;
4141
import org.springframework.web.bind.annotation.RestController;
42+
import org.springframework.context.annotation.Profile;
4243

4344
import com.fasterxml.jackson.core.JsonProcessingException;
4445
import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -80,6 +81,7 @@
8081

8182
@RequestMapping({ "/beneficiary" })
8283
@RestController
84+
@Profile("!swagger")
8385
public class BeneficiaryRegistrationController {
8486

8587
private InputMapper inputMapper = new InputMapper();

src/main/java/com/iemr/common/controller/secondaryReport/CustomerRelationshipSecondaryReports.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.web.bind.annotation.RequestBody;
3333
import org.springframework.web.bind.annotation.RequestMapping;
3434
import org.springframework.web.bind.annotation.RequestMethod;
35+
import org.springframework.context.annotation.Profile;
3536
import org.springframework.web.bind.annotation.RestController;
3637

3738
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -46,6 +47,7 @@
4647
import io.swagger.v3.oas.annotations.Operation;
4748
import jakarta.servlet.http.HttpServletRequest;
4849

50+
@Profile("!swagger")
4951
@RequestMapping({ "/crmReports" })
5052
@RestController
5153
public class CustomerRelationshipSecondaryReports {

src/main/java/com/iemr/common/secondary/repository/callreport/CallReportSecondaryRepo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
import org.springframework.data.jpa.repository.Query;
2828
import org.springframework.data.repository.CrudRepository;
2929
import org.springframework.data.repository.query.Param;
30+
import org.springframework.context.annotation.Profile;
3031
import org.springframework.stereotype.Repository;
3132

3233
import common.iemr.common.secondary.data.report.SecondaryCallReport;
3334

35+
@Profile("!swagger")
3436
@Repository
3537
public interface CallReportSecondaryRepo extends CrudRepository<SecondaryCallReport, Long> {
3638
@Query(value="call Pr_104QAReport(:startDateTime,:endDateTime,:receivedRoleName,:agentID,:providerServiceMapID)", nativeQuery=true)

src/main/java/com/iemr/common/service/beneficiary/BenRelationshipTypeServiceImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131

3232
import com.iemr.common.data.beneficiary.BenRelationshipType;
3333
import com.iemr.common.repository.beneficiary.BeneficiaryRelationshipTypeRepository;
34+
import org.springframework.context.annotation.Profile;
3435
@Service
36+
@Profile("!swagger")
3537
public class BenRelationshipTypeServiceImpl implements BenRelationshipTypeService {
3638

3739
private BeneficiaryRelationshipTypeRepository beneficiaryRelationshipTypeRepository;

src/main/java/com/iemr/common/service/beneficiary/BeneficiaryOccupationServiceImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131

3232
import com.iemr.common.data.beneficiary.BeneficiaryOccupation;
3333
import com.iemr.common.repository.beneficiary.BeneficiaryOccupationRepository;
34+
import org.springframework.context.annotation.Profile;
3435

3536
@Service
37+
@Profile("!swagger")
3638
public class BeneficiaryOccupationServiceImpl implements BeneficiaryOccupationService {
3739

3840
private BeneficiaryOccupationRepository beneficiaryOccupationRepository;

0 commit comments

Comments
 (0)