From 1f1352c084a3b74ab7c0ad1cf7a22009d6ea4db5 Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Mon, 19 Jan 2026 16:42:18 +0530 Subject: [PATCH 1/9] docs: add DeepWiki badge and documentation link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cbd3e76..cfd2468 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # AMRIT - Inventory API -[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) ![branch parameter](https://github.com/PSMRI/Inventory-API/actions/workflows/sast-and-package.yml/badge.svg) +[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![DeepWiki](https://img.shields.io/badge/DeepWiki-PSMRI%2FInventory--API-blue)](https://deepwiki.com/PSMRI/Inventory-API) Inventory service acts as a medicine inventory management and dispensing unit that helps in distributing the medicine to the pateint as per the prescription. Exposes below set of features as REST APIs. From be90dd56addf93e18859853ddff81ed27d4d00e5 Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Thu, 5 Feb 2026 11:34:25 +0530 Subject: [PATCH 2/9] chore(swagger): automate swagger sync to amrit-docs --- pom.xml | 5 +++++ .../resources/application-swagger.properties | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/main/resources/application-swagger.properties diff --git a/pom.xml b/pom.xml index 8b238e1..27582b5 100644 --- a/pom.xml +++ b/pom.xml @@ -280,6 +280,11 @@ 0.12.6 runtime + + com.h2database + h2 + runtime + ${artifactId}-${version} diff --git a/src/main/resources/application-swagger.properties b/src/main/resources/application-swagger.properties new file mode 100644 index 0000000..0611137 --- /dev/null +++ b/src/main/resources/application-swagger.properties @@ -0,0 +1,22 @@ +spring.datasource.url=jdbc:h2:mem:swaggerdb +spring.datasource.driver-class-name=org.h2.Driver +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect +spring.jpa.hibernate.ddl-auto=create-drop + +# Disable Redis if not needed for docs (optional) +spring.data.redis.host=localhost +spring.data.redis.port=6379 + +# CORS for Swagger UI +cors.allowed-origins=${CORS_ALLOWED_ORIGINS:http://localhost:9090,http://localhost:8080} +# Logging +logging.level.root=INFO + +# Use environment variable for JWT secret +jwt.secret=${JWT_SECRET_KEY:default-swagger-secret-change-me} + +# Placeholder for required property +common-api-url-searchBeneficiary=http://localhost:8080/beneficiary/search + +# Placeholder for required property +common-api-url-searchuserbyid=http://localhost:8080/user/searchbyid From 8bec78354e672491e080e2baf2c1882a8bbd492a Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Thu, 5 Feb 2026 11:36:50 +0530 Subject: [PATCH 3/9] chore(swagger): automate swagger sync to amrit-docs --- .github/workflows/swagger-json.yml | 100 +++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 .github/workflows/swagger-json.yml diff --git a/.github/workflows/swagger-json.yml b/.github/workflows/swagger-json.yml new file mode 100644 index 0000000..cede145 --- /dev/null +++ b/.github/workflows/swagger-json.yml @@ -0,0 +1,100 @@ +name: Sync Swagger to AMRIT-Docs + +on: + push: + branches: [ main ] + workflow_dispatch: + +jobs: + swagger-sync: + runs-on: ubuntu-latest + timeout-minutes: 20 + + steps: + - name: Checkout API repo (full history) + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Java 17 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + cache: maven + + - name: Build API (skip tests) + run: mvn -B clean package -DskipTests + + - name: Install jq + run: sudo apt-get update && sudo apt-get install -y jq + + - name: Run API in swagger profile + run: | + nohup 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..40}; do + CODE=$(curl --connect-timeout 2 --max-time 5 -s -o swagger_raw.json -w "%{http_code}" http://localhost:9090/v3/api-docs || true) + + if [ "$CODE" = "200" ]; then + jq . swagger_raw.json > inventory-api.json || { + echo "Swagger JSON invalid" + cat swagger_raw.json + exit 1 + } + + if [ "$(jq '.paths | length' inventory-api.json)" -eq 0 ]; then + echo "Swagger paths empty – failing" + exit 1 + fi + + echo "Swagger generated successfully" + exit 0 + fi + + echo "Waiting for API... ($i)" + sleep 4 + done + + echo "Swagger not generated" + cat app.log || true + exit 1 + + - name: Stop API + if: always() + run: | + if [ -f api_pid.txt ]; then + kill -9 $(cat api_pid.txt) || true + fi + + - name: Checkout AMRIT-Docs + uses: actions/checkout@v4 + with: + repository: PSMRI/AMRIT-Docs + token: ${{ secrets.DOCS_REPO_TOKEN }} + path: amrit-docs + fetch-depth: 0 + + - name: Copy Swagger JSON + run: | + mkdir -p amrit-docs/docs/swagger + cp inventory-api.json amrit-docs/docs/swagger/inventory-api.json + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.DOCS_REPO_TOKEN }} + path: amrit-docs + branch: auto/swagger-update-${{ github.run_id }}-${{ github.run_attempt }} + base: main + commit-message: "chore(docs): auto-update Inventory-API swagger" + title: "chore(docs): auto-update Inventory-API swagger" + body: | + This PR automatically updates Inventory-API Swagger JSON + from the latest main branch build. From 24cca96029e430aff396acd13514cdd7235a2329 Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Thu, 5 Feb 2026 11:53:35 +0530 Subject: [PATCH 4/9] chore(swagger): automate swagger sync to amrit-docs --- src/main/resources/application-swagger.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application-swagger.properties b/src/main/resources/application-swagger.properties index 0611137..73bf8d4 100644 --- a/src/main/resources/application-swagger.properties +++ b/src/main/resources/application-swagger.properties @@ -4,8 +4,8 @@ spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.jpa.hibernate.ddl-auto=create-drop # Disable Redis if not needed for docs (optional) -spring.data.redis.host=localhost -spring.data.redis.port=6379 +spring.data.redis.host=${REDIS_HOST:localhost} +spring.data.redis.port=${REDIS_PORT:6379} # CORS for Swagger UI cors.allowed-origins=${CORS_ALLOWED_ORIGINS:http://localhost:9090,http://localhost:8080} From 14a7f7db793582188659e430d62ae1ecc3886249 Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Fri, 6 Feb 2026 10:59:24 +0530 Subject: [PATCH 5/9] chore(swagger): fix jwt token in application-swagger.properties --- src/main/resources/application-swagger.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-swagger.properties b/src/main/resources/application-swagger.properties index 73bf8d4..d4b419b 100644 --- a/src/main/resources/application-swagger.properties +++ b/src/main/resources/application-swagger.properties @@ -13,7 +13,7 @@ cors.allowed-origins=${CORS_ALLOWED_ORIGINS:http://localhost:9090,http://localho logging.level.root=INFO # Use environment variable for JWT secret -jwt.secret=${JWT_SECRET_KEY:default-swagger-secret-change-me} +jwt.secret=${JWT_SECRET_KEY:#{T(java.util.UUID).randomUUID().toString()}} # Placeholder for required property common-api-url-searchBeneficiary=http://localhost:8080/beneficiary/search From 4399deb353d7fd08981e61106daf701a3581e670 Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Wed, 11 Feb 2026 09:00:28 +0530 Subject: [PATCH 6/9] chore(swagger): update swagger workflow and properties --- .github/workflows/swagger-json.yml | 15 ++++++++++++--- src/main/resources/application-swagger.properties | 7 +++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/swagger-json.yml b/.github/workflows/swagger-json.yml index cede145..58b127f 100644 --- a/.github/workflows/swagger-json.yml +++ b/.github/workflows/swagger-json.yml @@ -69,9 +69,17 @@ jobs: - name: Stop API if: always() run: | + # Graceful shutdown of the process group + sleep 5 + # Force kill the process group if still running if [ -f api_pid.txt ]; then - kill -9 $(cat api_pid.txt) || true - fi + PID=$(cat api_pid.txt) + kill -TERM -- -"$PID" 2>/dev/null || true + sleep 2 + kill -9 -- -"$PID" 2>/dev/null || true + fi + # Fallback: kill any remaining java process on port 9090 + fuser -k 9090/tcp 2>/dev/null || true - name: Checkout AMRIT-Docs uses: actions/checkout@v4 @@ -87,7 +95,7 @@ jobs: cp inventory-api.json amrit-docs/docs/swagger/inventory-api.json - name: Create Pull Request - uses: peter-evans/create-pull-request@v6 + uses: peter-evans/create-pull-request@v8 with: token: ${{ secrets.DOCS_REPO_TOKEN }} path: amrit-docs @@ -95,6 +103,7 @@ jobs: base: main commit-message: "chore(docs): auto-update Inventory-API swagger" title: "chore(docs): auto-update Inventory-API swagger" + delete-branch: true body: | This PR automatically updates Inventory-API Swagger JSON from the latest main branch build. diff --git a/src/main/resources/application-swagger.properties b/src/main/resources/application-swagger.properties index d4b419b..8cba52e 100644 --- a/src/main/resources/application-swagger.properties +++ b/src/main/resources/application-swagger.properties @@ -4,9 +4,8 @@ spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.jpa.hibernate.ddl-auto=create-drop # Disable Redis if not needed for docs (optional) -spring.data.redis.host=${REDIS_HOST:localhost} -spring.data.redis.port=${REDIS_PORT:6379} - +spring.session.store-type=none +spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration # CORS for Swagger UI cors.allowed-origins=${CORS_ALLOWED_ORIGINS:http://localhost:9090,http://localhost:8080} # Logging @@ -19,4 +18,4 @@ jwt.secret=${JWT_SECRET_KEY:#{T(java.util.UUID).randomUUID().toString()}} common-api-url-searchBeneficiary=http://localhost:8080/beneficiary/search # Placeholder for required property -common-api-url-searchuserbyid=http://localhost:8080/user/searchbyid +common-api-url-searchuserbyid=http://localhost:8080/user/searchbyid \ No newline at end of file From c7f0487001ae705191717bfaeca697d2d3041f94 Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Wed, 11 Feb 2026 09:07:50 +0530 Subject: [PATCH 7/9] fix(redis): fix the redis issue and add swagger profile --- src/main/java/com/iemr/inventory/config/RedisConfig.java | 3 ++- src/main/resources/application-swagger.properties | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/iemr/inventory/config/RedisConfig.java b/src/main/java/com/iemr/inventory/config/RedisConfig.java index c1061ab..4598bae 100644 --- a/src/main/java/com/iemr/inventory/config/RedisConfig.java +++ b/src/main/java/com/iemr/inventory/config/RedisConfig.java @@ -30,11 +30,12 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; - +import org.springframework.context.annotation.Profile; import com.iemr.inventory.data.user.M_User; @Configuration @EnableCaching +@Profile("!swagger") public class RedisConfig { private @Value("${spring.data.redis.host}") String redisHost; diff --git a/src/main/resources/application-swagger.properties b/src/main/resources/application-swagger.properties index 8cba52e..e33316d 100644 --- a/src/main/resources/application-swagger.properties +++ b/src/main/resources/application-swagger.properties @@ -3,9 +3,9 @@ spring.datasource.driver-class-name=org.h2.Driver spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.jpa.hibernate.ddl-auto=create-drop -# Disable Redis if not needed for docs (optional) +# CRITICAL: Disable Spring Session for swagger profile (no Redis) spring.session.store-type=none -spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration + # CORS for Swagger UI cors.allowed-origins=${CORS_ALLOWED_ORIGINS:http://localhost:9090,http://localhost:8080} # Logging @@ -18,4 +18,4 @@ jwt.secret=${JWT_SECRET_KEY:#{T(java.util.UUID).randomUUID().toString()}} common-api-url-searchBeneficiary=http://localhost:8080/beneficiary/search # Placeholder for required property -common-api-url-searchuserbyid=http://localhost:8080/user/searchbyid \ No newline at end of file +common-api-url-searchuserbyid=http://localhost:8080/user/searchbyid From 698fc1881a841cbe9d94b43049523660fabbdfdb Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Wed, 11 Feb 2026 11:22:35 +0530 Subject: [PATCH 8/9] fix(redis): fix the redis swagger profile issue --- src/main/java/com/iemr/inventory/config/RedisConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/iemr/inventory/config/RedisConfig.java b/src/main/java/com/iemr/inventory/config/RedisConfig.java index 4598bae..dc91da1 100644 --- a/src/main/java/com/iemr/inventory/config/RedisConfig.java +++ b/src/main/java/com/iemr/inventory/config/RedisConfig.java @@ -47,6 +47,7 @@ LettuceConnectionFactory lettuceConnectionFactory() { } @Bean + @Profile("!swagger") public RedisTemplate redisTemplate(RedisConnectionFactory factory) { RedisTemplate template = new RedisTemplate<>(); template.setConnectionFactory(factory); From 25a4e255fd30bd23f172f927d5191f1c2eaf7dc6 Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Wed, 11 Feb 2026 11:30:38 +0530 Subject: [PATCH 9/9] fix : fix the redis server issue --- src/main/java/com/iemr/inventory/config/RedisConfig.java | 3 --- src/main/resources/application-swagger.properties | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/iemr/inventory/config/RedisConfig.java b/src/main/java/com/iemr/inventory/config/RedisConfig.java index dc91da1..4eca5f7 100644 --- a/src/main/java/com/iemr/inventory/config/RedisConfig.java +++ b/src/main/java/com/iemr/inventory/config/RedisConfig.java @@ -30,12 +30,10 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; -import org.springframework.context.annotation.Profile; import com.iemr.inventory.data.user.M_User; @Configuration @EnableCaching -@Profile("!swagger") public class RedisConfig { private @Value("${spring.data.redis.host}") String redisHost; @@ -47,7 +45,6 @@ LettuceConnectionFactory lettuceConnectionFactory() { } @Bean - @Profile("!swagger") public RedisTemplate redisTemplate(RedisConnectionFactory factory) { RedisTemplate template = new RedisTemplate<>(); template.setConnectionFactory(factory); diff --git a/src/main/resources/application-swagger.properties b/src/main/resources/application-swagger.properties index e33316d..129364c 100644 --- a/src/main/resources/application-swagger.properties +++ b/src/main/resources/application-swagger.properties @@ -4,7 +4,9 @@ spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.jpa.hibernate.ddl-auto=create-drop # CRITICAL: Disable Spring Session for swagger profile (no Redis) -spring.session.store-type=none + +spring.data.redis.host = ${HOST:localhost} +spring.data.redis.port = ${PORT:6379} # CORS for Swagger UI cors.allowed-origins=${CORS_ALLOWED_ORIGINS:http://localhost:9090,http://localhost:8080}