Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions .github/workflows/swagger-json.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Sync Swagger to AMRIT-Docs

on:
push:
branches: [ main ]
workflow_dispatch:

jobs:
swagger-sync:
runs-on: ubuntu-latest

steps:
- name: Checkout API repo
uses: actions/checkout@v4

- name: Set up Java 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
cache: maven
Comment on lines +14 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n .github/workflows/swagger-json.yml | head -80

Repository: PSMRI/Common-API

Length of output: 2770


🌐 Web query:

actions/checkout v4 latest release commit SHA github

💡 Result:

Latest actions/checkout v4 release tag is v4.3.1, which points to commit SHA 34e114876b0b11c390a56381ad16ebd13914f8d5. [1][2]

Major tag v4 currently also points to the same commit. [1]

Sources:
[1] https://github.com/actions/checkout/tags
[2] actions/checkout@34e1148


🌐 Web query:

actions/setup-java v4 latest release commit SHA github

💡 Result:

Latest actions/setup-java v4 release is v4.8.0, which points to commit c1e323688fd81a25caa38c78aa6df2d33d3e20d9. [1] [2]


🌐 Web query:

peter-evans/create-pull-request v6 latest release commit SHA github

💡 Result:

Latest v6 release for peter-evans/create-pull-request is v6.1.0 (tag v6.1.0 / major tag v6), pointing to commit:

  • c5a7806660adbe173f04e3e038b0ccdcd758773c [1][2]

Pin GitHub Actions to full commit SHAs.

Unpinned actions are a supply-chain risk. Pin actions/checkout, actions/setup-java, and peter-evans/create-pull-request to their release commit SHAs:

Example pinning
-      - uses: actions/checkout@v4
+      - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5

-      - uses: actions/setup-java@v4
+      - uses: actions/setup-java@c1e323688fd81a25caa38c78aa6df2d33d3e20d9

-      - uses: peter-evans/create-pull-request@v6
+      - uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c

Also applies to: 57-62, 68-73

🤖 Prompt for AI Agents
In @.github/workflows/swagger-json.yml around lines 14 - 21, Replace unpinned
action versions with full commit SHAs for supply-chain safety: change uses:
actions/checkout@v4, uses: actions/setup-java@v4, and uses:
peter-evans/create-pull-request@... to their respective release commit SHAs
(e.g., actions/checkout@<full-sha>, actions/setup-java@<full-sha>,
peter-evans/create-pull-request@<full-sha>), keeping the same inputs; update
every occurrence of those uses entries in the workflow so all references are
pinned to specific commit SHAs.


- name: Build API (skip tests)
run: mvn clean package -DskipTests

- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq

- name: Run API in swagger profile
run: |
mvn spring-boot:run \
-Dspring-boot.run.profiles=swagger \
-Dspring-boot.run.arguments=--server.port=9090 \
> app.log 2>&1 &
echo $! > api_pid.txt

- name: Wait for API & fetch Swagger
run: |
for i in {1..30}; do
CODE=$(curl -s -o swagger_raw.json -w "%{http_code}" http://localhost:9090/v3/api-docs || true)
if [ "$CODE" = "200" ]; then
jq . swagger_raw.json > common-api.json
echo "Swagger generated successfully"
exit 0
fi
echo "Waiting for API... ($i)"
sleep 5
done

echo "Swagger not generated"
cat app.log || true
exit 1

- name: Stop API
if: always()
run: |
if [ -f api_pid.txt ]; then
kill $(cat api_pid.txt) || true
fi

- name: Checkout AMRIT-Docs
uses: actions/checkout@v4
with:
repository: DurgaPrasad-54/AMRIT-Docs
token: ${{ secrets.DOCS_REPO_TOKEN }}
path: amrit-docs
Comment on lines +61 to +66
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Workflow targets a personal fork instead of the organization repository.

The checkout targets DurgaPrasad-54/AMRIT-Docs (personal fork) rather than PSMRI/AMRIT-Docs (organization repo). If this is for testing, ensure it's updated to the organization repository before merging.

🔧 Suggested fix
       - name: Checkout AMRIT-Docs
         uses: actions/checkout@v4
         with:
-          repository: DurgaPrasad-54/AMRIT-Docs
+          repository: PSMRI/AMRIT-Docs
           token: ${{ secrets.DOCS_REPO_TOKEN }}
           path: amrit-docs
🤖 Prompt for AI Agents
In @.github/workflows/swagger-json.yml around lines 61 - 66, The workflow's
checkout step is pointing to a personal fork via the repository field in the
Checkout action (uses: actions/checkout@v4) — change the repository value from
"DurgaPrasad-54/AMRIT-Docs" to the organization repo "PSMRI/AMRIT-Docs" (or
parameterize via a secret/variable if testing) so the action checks out the
correct org repository; update the repository key in the Checkout AMRIT-Docs
step accordingly.


- name: Copy Swagger JSON
run: |
cp common-api.json amrit-docs/docs/swagger/common-api.json
Comment on lines +68 to +70
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Ensure target directory exists before copy.

The copy will fail if docs/swagger/ directory doesn't exist in the AMRIT-Docs repository.

🔧 Proposed fix
       - name: Copy Swagger JSON
         run: |
+          mkdir -p amrit-docs/docs/swagger
           cp common-api.json amrit-docs/docs/swagger/common-api.json
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Copy Swagger JSON
run: |
cp common-api.json amrit-docs/docs/swagger/common-api.json
- name: Copy Swagger JSON
run: |
mkdir -p amrit-docs/docs/swagger
cp common-api.json amrit-docs/docs/swagger/common-api.json
🤖 Prompt for AI Agents
In @.github/workflows/swagger-json.yml around lines 68 - 70, The workflow step
"Copy Swagger JSON" may fail if the target directory amrit-docs/docs/swagger
does not exist; before running the cp command in that step, ensure the directory
is created (e.g., run a mkdir -p for amrit-docs/docs/swagger) so the copy
succeeds reliably, and keep the step name "Copy Swagger JSON" and the source
file common-api.json unchanged.


- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.DOCS_REPO_TOKEN }}
path: amrit-docs
branch: auto/swagger-update
base: main
commit-message: Auto-update Common-API swagger
title: Auto-update Common-API swagger
body: |
This PR automatically updates the Common-API Swagger JSON
from the latest main branch build.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
</repository>
</repositories>
<dependencies>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/iemr/common/config/PrimaryDBConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory", basePackages = { "com.iemr.common.repository",
"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" })
"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" })
@org.springframework.context.annotation.Profile("!swagger")
public class PrimaryDBConfig {

Logger logger = LoggerFactory.getLogger(this.getClass().getName());
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/iemr/common/config/SecondaryDBConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@

import jakarta.persistence.EntityManagerFactory;

import org.springframework.context.annotation.Profile;

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(entityManagerFactoryRef = "secondaryEntityManagerFactory", transactionManagerRef = "secondaryTransactionManager", basePackages = {
"com.iemr.common.secondary.repository.callreport" })
"com.iemr.common.secondary.repository.callreport" })
@Profile("!swagger")
public class SecondaryDBConfig {

Logger logger = LoggerFactory.getLogger(this.getClass().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.transaction.annotation.Transactional;

import com.iemr.common.service.nhm_dashboard.NHM_DashboardService;
import org.springframework.context.annotation.Profile;

@Service
@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.context.annotation.Profile;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
Expand Down Expand Up @@ -80,6 +81,7 @@

@RequestMapping({ "/beneficiary" })
@RestController
@Profile("!swagger")
public class BeneficiaryRegistrationController {

private InputMapper inputMapper = new InputMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.RestController;

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

@Profile("!swagger")
@RequestMapping({ "/crmReports" })
@RestController
public class CustomerRelationshipSecondaryReports {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Repository;

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

@Profile("!swagger")
@Repository
public interface CallReportSecondaryRepo extends CrudRepository<SecondaryCallReport, Long> {
@Query(value="call Pr_104QAReport(:startDateTime,:endDateTime,:receivedRoleName,:agentID,:providerServiceMapID)", nativeQuery=true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@

import com.iemr.common.data.beneficiary.BenRelationshipType;
import com.iemr.common.repository.beneficiary.BeneficiaryRelationshipTypeRepository;
import org.springframework.context.annotation.Profile;
@Service
@Profile("!swagger")
public class BenRelationshipTypeServiceImpl implements BenRelationshipTypeService {

private BeneficiaryRelationshipTypeRepository beneficiaryRelationshipTypeRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@

import com.iemr.common.data.beneficiary.BeneficiaryOccupation;
import com.iemr.common.repository.beneficiary.BeneficiaryOccupationRepository;
import org.springframework.context.annotation.Profile;

@Service
@Profile("!swagger")
public class BeneficiaryOccupationServiceImpl implements BeneficiaryOccupationService {

private BeneficiaryOccupationRepository beneficiaryOccupationRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@
import com.iemr.common.utils.validator.Validator;

import jakarta.servlet.http.HttpServletRequest;

import org.springframework.context.annotation.Profile;
/**
* @author WA875423
*
*/
@Service
@Profile("!swagger")
public class RegisterBenificiaryServiceImpl implements RegisterBenificiaryService {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@

import com.iemr.common.data.beneficiary.SexualOrientation;
import com.iemr.common.repository.userbeneficiarydata.SexualOrientationRepository;

import org.springframework.context.annotation.Profile;
@Service
@Profile("!swagger")
public class SexualOrientationServiceImpl implements SexualOrientationService {
private SexualOrientationRepository sexualOrientationRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/

package com.iemr.common.service.reportSecondary;

import java.io.ByteArrayInputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

import com.iemr.common.data.callhandling.CallType;
Expand All @@ -53,6 +54,7 @@
import com.iemr.common.utils.mapper.InputMapper;


@Profile("!swagger")
@Service
public class SecondaryReportServiceImpl implements SecondaryReportService {
private final Logger logger = LoggerFactory.getLogger(this.getClass().getName());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/iemr/common/utils/FilterConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.data.redis.core.StringRedisTemplate;

@Configuration
@org.springframework.context.annotation.Profile("!swagger")
public class FilterConfig {

private static final Logger log = LoggerFactory.getLogger(FilterConfig.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import jakarta.servlet.http.HttpServletRequest;

@Component
@org.springframework.context.annotation.Profile("!swagger")
public class JwtAuthenticationUtil {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
import com.iemr.common.utils.mapper.OutputMapper;

import jakarta.persistence.Column;
import org.springframework.context.annotation.Profile;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;

@Profile("!swagger")
@Entity
@Table(name = "fact_bencall", schema = "db_reporting")
public class SecondaryCallReport implements Serializable
Expand Down
28 changes: 28 additions & 0 deletions src/main/resources/application-swagger.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cors.allowed-origins=*
# ---- Embedded DB for Swagger documentation generation
spring.datasource.url=jdbc:h2:mem:swaggerdb
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=

spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=false

spring.sql.init.mode=never

# Use placeholders for sensitive values
jwt.secret=<Enter_Your_Secret_Key>
jwt.expiration=3600000
sms-password=<Enter_SMS_Password>
sms-username=<Enter_SMS_Username>
start-grievancedatasync-scheduler=false
sms-consent-source-address=<Enter_Source_Address>
send-message-url=http://localhost:8080/sms/sendMessage
secondary.datasource.username=<Enter_Username>
secondary.datasource.password=<Enter_Password>
secondary.datasource.url=jdbc:h2:mem:reportingdb
secondary.datasource.driver-class-name=org.h2.Driver

springdoc.api-docs.enabled=true
springdoc.swagger-ui.enabled=true
4 changes: 1 addition & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,4 @@ video-call-url =
allowed.file.extensions=msg,pdf,png,jpeg,doc,docx,xlsx,xls,csv,txt

##sms details for beneficiary otp cosent
sms-template-name = otp_consent


sms-template-name = otp_consent
Loading