From 6736e1b79f8f1dae6615cc484cc5e7773064e245 Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Wed, 28 Jan 2026 09:39:08 +0530 Subject: [PATCH 1/4] chore(swagger): automate swagger json export --- .github/workflows/swagger-export.yml | 98 ++++++++++++++++++++++ src/main/resources/application-swagger.yml | 39 +++++++++ 2 files changed, 137 insertions(+) create mode 100644 .github/workflows/swagger-export.yml create mode 100644 src/main/resources/application-swagger.yml diff --git a/.github/workflows/swagger-export.yml b/.github/workflows/swagger-export.yml new file mode 100644 index 00000000..f07e34f8 --- /dev/null +++ b/.github/workflows/swagger-export.yml @@ -0,0 +1,98 @@ +name: Export Swagger + +on: + push: + branches: + - main + +jobs: + swagger: + runs-on: ubuntu-latest + + steps: + # Checkout Common-API (current repo) + - uses: actions/checkout@v4 + + # Setup Java + - name: Set up Java 17 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + cache: maven + + # Build WAR + - name: Build Common-API + run: mvn clean package -DskipTests + + # Run application with swagger profile + - name: Run application + run: | + WAR_FILE=$(find target -name "*.war" | grep -v original | head -1) + if [ -z "$WAR_FILE" ]; then + echo "WAR file not found" + exit 1 + fi + + echo "Starting app using $WAR_FILE" + java -jar "$WAR_FILE" --spring.profiles.active=swagger > /tmp/app.log 2>&1 & + echo $! > /tmp/app.pid + + # Wait for Swagger to be available + - name: Wait for Swagger endpoint + run: | + for i in {1..40}; do + if curl -sf http://localhost:8083/v3/api-docs > /dev/null; then + echo "Swagger is available" + exit 0 + fi + sleep 2 + done + + echo "Application failed to start" + cat /tmp/app.log + exit 1 + + # Fetch Swagger JSON + - name: Fetch Swagger JSON + run: | + curl http://localhost:8083/v3/api-docs -o common-api.json + test -s common-api.json + + # Clone AMRIT-Docs + - name: Clone AMRIT-Docs + run: | + git clone --depth 1 https://github.com/PSMRI/AMRIT-Docs.git amrit-docs + + # Copy Swagger + - name: Copy Swagger JSON + run: | + mkdir -p amrit-docs/docs/swagger + cp common-api.json amrit-docs/docs/swagger/common-api.json + + # Commit & push only if changed + - name: Commit and push + run: | + cd amrit-docs + + if git diff --quiet docs/swagger/common-api.json; then + echo "No Swagger changes" + exit 0 + fi + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + git add docs/swagger/common-api.json + git commit -m "chore: update Common-API Swagger [skip ci]" \ + -m "Source: ${{ github.repository }}@${{ github.sha }}" + + git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/PSMRI/AMRIT-Docs.git HEAD:main + + # Stop app + - name: Stop application + if: always() + run: | + if [ -f /tmp/app.pid ]; then + kill $(cat /tmp/app.pid) || true + fi diff --git a/src/main/resources/application-swagger.yml b/src/main/resources/application-swagger.yml new file mode 100644 index 00000000..48c1636c --- /dev/null +++ b/src/main/resources/application-swagger.yml @@ -0,0 +1,39 @@ +server: + port: 8083 + +spring: + datasource: + url: jdbc:h2:mem:swaggerdb;DB_CLOSE_DELAY=-1 + driver-class-name: org.h2.Driver + username: sa + password: "" + + jpa: + database-platform: org.hibernate.dialect.H2Dialect + hibernate: + ddl-auto: none + show-sql: false + + flyway: + enabled: false + + liquibase: + enabled: false + + session: + store-type: none + + task: + scheduling: + enabled: false + +springdoc: + api-docs: + enabled: true + path: /v3/api-docs + swagger-ui: + enabled: false + +logging: + level: + root: INFO From 757eef274d9c8aa1b360596889692c617b7bcb84 Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Wed, 28 Jan 2026 10:56:22 +0530 Subject: [PATCH 2/4] chore(swagger): address coderabbit feedback --- .github/workflows/swagger-export.yml | 19 +++++++++++++++---- src/main/resources/application-swagger.yml | 1 - 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/swagger-export.yml b/.github/workflows/swagger-export.yml index f07e34f8..c78a2df5 100644 --- a/.github/workflows/swagger-export.yml +++ b/.github/workflows/swagger-export.yml @@ -75,9 +75,20 @@ jobs: run: | cd amrit-docs - if git diff --quiet docs/swagger/common-api.json; then - echo "No Swagger changes" - exit 0 + # Check if file is tracked and detect changes + if git ls-files --error-unmatch docs/swagger/common-api.json > /dev/null 2>&1; then + # File is tracked, check for changes + if git diff --quiet docs/swagger/common-api.json; then + echo "No Swagger changes" + exit 0 + fi + else + # File is untracked, stage it and check if there are staged changes + git add docs/swagger/common-api.json + if git diff --staged --quiet docs/swagger/common-api.json; then + echo "No Swagger changes" + exit 0 + fi fi git config user.name "github-actions[bot]" @@ -87,7 +98,7 @@ jobs: git commit -m "chore: update Common-API Swagger [skip ci]" \ -m "Source: ${{ github.repository }}@${{ github.sha }}" - git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/PSMRI/AMRIT-Docs.git HEAD:main + git push https://x-access-token:${{ secrets.AMRIT_DOCS_PAT }}@github.com/PSMRI/AMRIT-Docs.git HEAD:main # Stop app - name: Stop application diff --git a/src/main/resources/application-swagger.yml b/src/main/resources/application-swagger.yml index 48c1636c..ab4c7ce7 100644 --- a/src/main/resources/application-swagger.yml +++ b/src/main/resources/application-swagger.yml @@ -9,7 +9,6 @@ spring: password: "" jpa: - database-platform: org.hibernate.dialect.H2Dialect hibernate: ddl-auto: none show-sql: false From cb69d118b8a882d53811c3de0900eeb2627b960a Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Wed, 28 Jan 2026 11:47:05 +0530 Subject: [PATCH 3/4] chore(swagger): define cors.allowed-origins for swagger profile --- src/main/resources/application-swagger.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/resources/application-swagger.yml b/src/main/resources/application-swagger.yml index ab4c7ce7..604c2ab6 100644 --- a/src/main/resources/application-swagger.yml +++ b/src/main/resources/application-swagger.yml @@ -36,3 +36,7 @@ springdoc: logging: level: root: INFO + +# CORS configuration for Swagger profile +cors: + allowed-origins: http://localhost:* From 9091c5ebb262db7d6cd6764a9d64c56b40a20e98 Mon Sep 17 00:00:00 2001 From: DurgaPrasad-54 Date: Wed, 28 Jan 2026 12:05:34 +0530 Subject: [PATCH 4/4] chore(swagger): define jwt for swagger profile --- src/main/resources/application-swagger.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/resources/application-swagger.yml b/src/main/resources/application-swagger.yml index 604c2ab6..09d4d1fe 100644 --- a/src/main/resources/application-swagger.yml +++ b/src/main/resources/application-swagger.yml @@ -40,3 +40,7 @@ logging: # CORS configuration for Swagger profile cors: allowed-origins: http://localhost:* + +# JWT configuration for Swagger profile +jwt: + secret: test-secret-key-for-swagger-profile-only