From 1f1352c084a3b74ab7c0ad1cf7a22009d6ea4db5 Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Mon, 19 Jan 2026 16:42:18 +0530 Subject: [PATCH 01/12] 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 cbd3e76e..cfd24689 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 02/12] 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 8b238e13..27582b5f 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 00000000..06111373 --- /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 03/12] 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 00000000..cede145f --- /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 04/12] 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 06111373..73bf8d43 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 05/12] 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 73bf8d43..d4b419b1 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 06/12] 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 cede145f..58b127f7 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 d4b419b1..8cba52e1 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 07/12] 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 c1061ab7..4598baec 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 8cba52e1..e33316d4 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 08/12] 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 4598baec..dc91da13 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 09/12] 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 dc91da13..4eca5f78 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 e33316d4..129364c7 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} From 79ea1daf75ae01ff9e5c2590610b3bdb3e3ee5d2 Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Thu, 12 Feb 2026 15:23:55 +0530 Subject: [PATCH 10/12] chore(swagger): add env-driven Dev/UAT/Demo servers and update workflow --- .github/workflows/swagger-json.yml | 2 +- .../iemr/inventory/config/SwaggerConfig.java | 26 +++++++++++++------ .../resources/application-swagger.properties | 4 +++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.github/workflows/swagger-json.yml b/.github/workflows/swagger-json.yml index 58b127f7..4563221d 100644 --- a/.github/workflows/swagger-json.yml +++ b/.github/workflows/swagger-json.yml @@ -99,7 +99,7 @@ jobs: with: token: ${{ secrets.DOCS_REPO_TOKEN }} path: amrit-docs - branch: auto/swagger-update-${{ github.run_id }}-${{ github.run_attempt }} + branch: auto/swagger-update-inventory-api base: main commit-message: "chore(docs): auto-update Inventory-API swagger" title: "chore(docs): auto-update Inventory-API swagger" diff --git a/src/main/java/com/iemr/inventory/config/SwaggerConfig.java b/src/main/java/com/iemr/inventory/config/SwaggerConfig.java index 93a31946..a791228c 100644 --- a/src/main/java/com/iemr/inventory/config/SwaggerConfig.java +++ b/src/main/java/com/iemr/inventory/config/SwaggerConfig.java @@ -2,6 +2,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; @@ -11,14 +12,23 @@ @Configuration public class SwaggerConfig { - - @Bean - public OpenAPI customOpenAPI() { - return new OpenAPI().info(new - Info().title("Inventory API").version("version").description("A microservice for the creation and management of beneficiaries.")) - .addSecurityItem(new SecurityRequirement().addList("my security")) - .components(new Components().addSecuritySchemes("my security", - new SecurityScheme().name("my security").type(SecurityScheme.Type.HTTP).scheme("bearer"))); + private static final String DEFAULT_SERVER_URL = "http://localhost:9090"; + + @Bean + public OpenAPI customOpenAPI(Environment env) { + String devUrl = env.getProperty("api.dev.url", DEFAULT_SERVER_URL); + String uatUrl = env.getProperty("api.uat.url", DEFAULT_SERVER_URL); + String demoUrl = env.getProperty("api.demo.url", DEFAULT_SERVER_URL); + return new OpenAPI() + .info(new Info().title("Inventory API").version("version").description("A microservice for the creation and management of beneficiaries.")) + .addSecurityItem(new SecurityRequirement().addList("my security")) + .components(new Components().addSecuritySchemes("my security", + new SecurityScheme().name("my security").type(SecurityScheme.Type.HTTP).scheme("bearer"))) + .servers(java.util.Arrays.asList( + new io.swagger.v3.oas.models.servers.Server().url(devUrl).description("Dev"), + new io.swagger.v3.oas.models.servers.Server().url(uatUrl).description("UAT"), + new io.swagger.v3.oas.models.servers.Server().url(demoUrl).description("Demo") + )); } } diff --git a/src/main/resources/application-swagger.properties b/src/main/resources/application-swagger.properties index 129364c7..5c0ddbc5 100644 --- a/src/main/resources/application-swagger.properties +++ b/src/main/resources/application-swagger.properties @@ -1,3 +1,7 @@ +# Swagger server URLs +api.dev.url=${API_DEV_URL:https://amritwprdev.piramalswasthya.org} +api.uat.url=${API_UAT_URL:https://uatamrit.piramalswasthya.org} +api.demo.url=${API_DEMO_URL:https://amritdemo.piramalswasthya.org} spring.datasource.url=jdbc:h2:mem:swaggerdb spring.datasource.driver-class-name=org.h2.Driver spring.jpa.database-platform=org.hibernate.dialect.H2Dialect From 888722e3df02f6b142390b32ae1d579c58b741fc Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Fri, 13 Feb 2026 09:47:47 +0530 Subject: [PATCH 11/12] chore(swagger): add new description for swagger doc --- .../iemr/inventory/config/SwaggerConfig.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/iemr/inventory/config/SwaggerConfig.java b/src/main/java/com/iemr/inventory/config/SwaggerConfig.java index a791228c..0db256b3 100644 --- a/src/main/java/com/iemr/inventory/config/SwaggerConfig.java +++ b/src/main/java/com/iemr/inventory/config/SwaggerConfig.java @@ -7,8 +7,11 @@ import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; + import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.security.SecurityScheme; +import java.util.List; +import io.swagger.v3.oas.models.servers.Server; @Configuration public class SwaggerConfig { @@ -20,14 +23,14 @@ public OpenAPI customOpenAPI(Environment env) { String uatUrl = env.getProperty("api.uat.url", DEFAULT_SERVER_URL); String demoUrl = env.getProperty("api.demo.url", DEFAULT_SERVER_URL); return new OpenAPI() - .info(new Info().title("Inventory API").version("version").description("A microservice for the creation and management of beneficiaries.")) - .addSecurityItem(new SecurityRequirement().addList("my security")) - .components(new Components().addSecuritySchemes("my security", - new SecurityScheme().name("my security").type(SecurityScheme.Type.HTTP).scheme("bearer"))) - .servers(java.util.Arrays.asList( - new io.swagger.v3.oas.models.servers.Server().url(devUrl).description("Dev"), - new io.swagger.v3.oas.models.servers.Server().url(uatUrl).description("UAT"), - new io.swagger.v3.oas.models.servers.Server().url(demoUrl).description("Demo") + .info(new Info().title("Inventory API").version("version").description("A microservice for inventory management of items, stock levels, and related operations.")) + .addSecurityItem(new SecurityRequirement().addList("bearerAuth")) + .components(new Components().addSecuritySchemes("bearerAuth", + new SecurityScheme().name("bearerAuth").type(SecurityScheme.Type.HTTP).scheme("bearer"))) + .servers(List.of( + new Server().url(devUrl).description("Dev"), + new Server().url(uatUrl).description("UAT"), + new Server().url(demoUrl).description("Demo") )); } From eccfe1606be11f0407f879bf10a60d5412a5829e Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Fri, 13 Feb 2026 09:53:13 +0530 Subject: [PATCH 12/12] chore(swagger): add variable for bearerAuth in SwaggerConfig --- src/main/java/com/iemr/inventory/config/SwaggerConfig.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/iemr/inventory/config/SwaggerConfig.java b/src/main/java/com/iemr/inventory/config/SwaggerConfig.java index 0db256b3..74294774 100644 --- a/src/main/java/com/iemr/inventory/config/SwaggerConfig.java +++ b/src/main/java/com/iemr/inventory/config/SwaggerConfig.java @@ -16,6 +16,7 @@ @Configuration public class SwaggerConfig { private static final String DEFAULT_SERVER_URL = "http://localhost:9090"; + private static final String BEARER_AUTH_SCHEME = "bearerAuth"; @Bean public OpenAPI customOpenAPI(Environment env) { @@ -24,9 +25,9 @@ public OpenAPI customOpenAPI(Environment env) { String demoUrl = env.getProperty("api.demo.url", DEFAULT_SERVER_URL); return new OpenAPI() .info(new Info().title("Inventory API").version("version").description("A microservice for inventory management of items, stock levels, and related operations.")) - .addSecurityItem(new SecurityRequirement().addList("bearerAuth")) - .components(new Components().addSecuritySchemes("bearerAuth", - new SecurityScheme().name("bearerAuth").type(SecurityScheme.Type.HTTP).scheme("bearer"))) + .addSecurityItem(new SecurityRequirement().addList(BEARER_AUTH_SCHEME)) + .components(new Components().addSecuritySchemes(BEARER_AUTH_SCHEME, + new SecurityScheme().name(BEARER_AUTH_SCHEME).type(SecurityScheme.Type.HTTP).scheme("bearer"))) .servers(List.of( new Server().url(devUrl).description("Dev"), new Server().url(uatUrl).description("UAT"),