Skip to content

Conversation

@DurgaPrasad-54
Copy link
Contributor

@DurgaPrasad-54 DurgaPrasad-54 commented Jan 28, 2026

Summary by CodeRabbit

  • Chores
    • Added an automated workflow to export API documentation, wait for the docs endpoint, fetch the OpenAPI JSON, and synchronize it to the central documentation repo (commits only when changes are detected; includes robust cleanup and error handling).
    • Added a dedicated runtime profile for generating docs in isolation using an in-memory datastore and disabled migrations so the API docs endpoint can be reliably exported.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

Adds a GitHub Actions workflow that builds the Common-API WAR, runs it with a swagger profile on port 8083, polls /v3/api-docs to export Swagger JSON and conditionally pushes it to the AMRIT-Docs repo; also adds a Spring Boot swagger profile configuration file.

Changes

Cohort / File(s) Summary
CI/CD Automation
.github/workflows/swagger-export.yml
New workflow triggered on pushes to main. Checks out code, sets up Java 17 and Maven cache, packages the WAR (tests skipped), starts the app with swagger profile, polls http://localhost:8083/v3/api-docs, verifies and saves common-api.json, clones AMRIT-Docs, copies JSON to amrit-docs/docs/swagger/common-api.json, commits & pushes only if changed (adds [skip ci]), and ensures the app process is terminated. Includes error handling for missing WAR, unavailable endpoint, and empty JSON.
Application Configuration
src/main/resources/application-swagger.yml
New Spring Boot profile file: server port 8083, H2 in-memory datasource (swaggerdb), JPA ddl-auto set to none, Flyway/Liquibase disabled, scheduling/session disabled, SpringDoc API enabled at /v3/api-docs (Swagger UI disabled), logging set to INFO, CORS allowing http://localhost:*, and a Swagger-specific JWT secret.

Sequence Diagram(s)

sequenceDiagram
    participant GH as GitHub Actions
    participant Runner as CI Runner
    participant App as Common-API (localhost:8083)
    participant GitRemote as AMRIT-Docs

    GH->>Runner: trigger workflow (push to main)
    Runner->>Runner: checkout\nsetup Java 17 + Maven cache\nmvn package (skip tests)
    Runner->>Runner: find WAR\nstart App with `swagger` profile (capture PID)
    Runner->>App: poll GET /v3/api-docs
    App-->>Runner: 200 + Swagger JSON
    Runner->>Runner: save `common-api.json` (verify non-empty)
    Runner->>GitRemote: clone AMRIT-Docs
    Runner->>Runner: copy JSON -> amrit-docs/docs/swagger/common-api.json
    Runner->>GitRemote: commit & push if changed ([skip ci])
    Runner->>Runner: stop App (kill PID)
    Runner-->>GH: workflow complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I start the WAR at morning light,
I chase the docs through day and night,
I fetch the JSON, neat and true,
I plant it where the docs accrue,
A humble hop — CI delight.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'add swagger json automate' is vague and poorly articulated. While it hints at adding automation for Swagger JSON, it lacks clarity and uses imprecise language ('automate' as a verb is awkward). Consider a clearer title like 'Add GitHub Actions workflow to automate Swagger JSON export' or 'Automate Swagger documentation export to AMRIT-Docs repository' for better clarity.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @.github/workflows/swagger-export.yml:
- Around line 74-91: Update the "Commit and push" step to use a PAT with write
access to AMRIT-Docs (create a secret like AMRIT_DOCS_PAT and replace
secrets.GITHUB_TOKEN in the git push URL) and fix change detection for
docs/swagger/common-api.json so new/untracked files are detected: instead of
only running git diff --quiet docs/swagger/common-api.json, first test if the
file is tracked with git ls-files --error-unmatch docs/swagger/common-api.json
(handle its exit code), if tracked then use git diff --quiet to detect changes,
otherwise treat it as changed (or simply git add and then check git diff
--staged --quiet to see if there are staged changes) before committing; update
references in the step (Commit and push, docs/swagger/common-api.json,
secrets.GITHUB_TOKEN -> AMRIT_DOCS_PAT).
🧹 Nitpick comments (1)
.github/workflows/swagger-export.yml (1)

56-60: Add error handling for the curl request.

If curl fails (e.g., network issue after endpoint was briefly available), test -s might pass on a partial/error response. Consider checking curl's exit code explicitly.

♻️ Suggested improvement
      - name: Fetch Swagger JSON
        run: |
-         curl http://localhost:8083/v3/api-docs -o common-api.json
+         curl -f http://localhost:8083/v3/api-docs -o common-api.json
          test -s common-api.json

The -f flag makes curl return a non-zero exit code on HTTP errors (4xx/5xx), causing the step to fail appropriately.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/main/resources/application-swagger.yml`:
- Line 12: Remove the redundant explicit Hibernate dialect setting by deleting
the database-platform property (database-platform:
org.hibernate.dialect.H2Dialect) from application-swagger.yml so Spring Boot /
Hibernate can auto-detect the H2 dialect from the JDBC URL
(jdbc:h2:mem:swaggerdb).

@sonarqubecloud
Copy link

git commit -m "chore: update Common-API Swagger [skip ci]" \
-m "Source: ${{ github.repository }}@${{ github.sha }}"

git push https://x-access-token:${{ secrets.AMRIT_DOCS_PAT }}@github.com/PSMRI/AMRIT-Docs.git HEAD:main
Copy link
Member

Choose a reason for hiding this comment

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

How is this going to be generated? What does this variable mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AMRIT_DOCS_PAT is a GitHub Personal Access Token created by a maintainer with write access to PSMRI/AMRIT-Docs and stored as a repository secret. It’s used only to authenticate the push from this workflow; for fork-based PRs the secret won’t be available, so the push step is expected to fail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants