Skip to content

Swagger json automation#118

Open
DurgaPrasad-54 wants to merge 5 commits intoPSMRI:mainfrom
DurgaPrasad-54:main
Open

Swagger json automation#118
DurgaPrasad-54 wants to merge 5 commits intoPSMRI:mainfrom
DurgaPrasad-54:main

Conversation

@DurgaPrasad-54
Copy link
Contributor

@DurgaPrasad-54 DurgaPrasad-54 commented Feb 3, 2026

Summary by CodeRabbit

  • New Features

    • Automated API documentation sync that keeps Swagger docs in the central documentation site up to date (creates PRs to publish updated docs).
  • Chores

    • Added environment and runtime configuration to support documentation automation and local Swagger preview, including an in-memory runtime option and related service/config defaults.

@coderabbitai
Copy link

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

Adds a GitHub Actions workflow that builds and runs the API under a swagger profile, polls and extracts the OpenAPI JSON, places it into the AMRIT-Docs repository, and opens a pull request; also adds H2 runtime dependency and a new application-swagger Spring profile.

Changes

Cohort / File(s) Summary
CI/CD Automation
.github/workflows/swagger-json.yml
New GitHub Actions workflow: uses Java 17 (Temurin) and Maven to build and run the API on port 9090, polls http://localhost:9090/v3/api-docs (up to 30 attempts @5s), converts payload to admin-api.json with jq, checks out the AMRIT-Docs repo, copies file to amrit-docs/docs/swagger/admin-api.json, and creates a PR via Peter Evans' PR action. Includes process termination and failure logging.
Build Configuration
pom.xml
Added com.h2database:h2 as a runtime dependency for the swagger/profile runtime.
Application Profile
src/main/resources/application-swagger.properties
New Spring Boot profile properties for Swagger runs: H2 datasource settings, JPA dialect/ddl-auto, Redis host/port defaults, CORS allowed origins, logging root level, and a placeholder JWT secret.

Sequence Diagram(s)

sequenceDiagram
  participant Actions as GitHub Actions Runner
  participant Maven as Maven/Java Build
  participant App as API (swagger profile)
  participant Endpoint as /v3/api-docs
  participant JQ as jq processor
  participant Docs as AMRIT-Docs repo

  Actions->>Maven: checkout + mvn -Dspring.profiles.active=swagger package
  Maven->>App: start API on port 9090
  App->>Endpoint: expose OpenAPI JSON
  loop poll (up to 30 tries, 5s)
    Actions->>Endpoint: GET /v3/api-docs
    Endpoint-->>Actions: JSON or not ready
  end
  Actions->>JQ: transform payload -> admin-api.json
  Actions->>Docs: checkout amrit-docs repo
  Actions->>Docs: copy admin-api.json -> docs/swagger/admin-api.json
  Actions->>Docs: create branch, commit, push
  Actions->>Docs: open PR via PR action
  alt failure / timeout
    Actions->>App: terminate process, log error
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through builds and chased the stream,
Sniffed the Swagger bytes and saved the dream.
A JSON crumb tucked in docs so bright,
Pushed a tiny PR into the night.
Hop — the docs now sparkle in the light. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Swagger json automation' is vague and generic, using non-descriptive terminology that doesn't clearly convey the specific purpose or main change in the changeset. Consider using a more specific title that describes the actual implementation, such as 'Add GitHub Actions workflow to automate Swagger JSON sync to AMRIT-Docs' or 'Automate API documentation updates via Swagger JSON workflow'.
✅ 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.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@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: 3

🤖 Fix all issues with AI agents
In @.github/workflows/swagger-json.yml:
- Around line 38-47: The curl call inside the retry loop (the invocation that
writes swagger_raw.json and sets CODE) can hang indefinitely; update that curl
invocation to include connection and overall timeouts (e.g., add
--connect-timeout and --max-time) so each iteration returns promptly, keep the
existing || true to allow retries, and ensure the rest of the loop that checks
CODE and writes admin-api.json remains unchanged.

In `@src/main/resources/application-swagger.properties`:
- Line 18: Replace the hard-coded jwt.secret value in
application-swagger.properties with a reference to an environment-provided
secret (e.g., use the jwt.secret property to read from an environment variable
or config placeholder) so the repo does not contain a static secret; update code
that loads properties if necessary to resolve the environment variable for the
jwt.secret property and ensure your CI/workflow sets the env var used.
- Around line 12-13: Replace the open CORS wildcard in the swagger profile by
changing the cors.allowed-origins property to use a restricted allowlist driven
by an environment variable (e.g., SWAGGER_CORS_ALLOWED_ORIGINS) and provide a
safe default (localhost/dev-only) instead of "*"; update the property
cors.allowed-origins to reference that env var so operators can override allowed
origins without permitting all origins in non-CI environments.

# Logging
logging.level.root=INFO

jwt.secret=dummy-secret
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid committing a static JWT secret.

Line 18 hard-codes a secret in repo. Use an environment variable (set in the workflow) to avoid shipping a known secret.

🔒 Suggested change
-jwt.secret=dummy-secret
+jwt.secret=${JWT_SECRET}
🤖 Prompt for AI Agents
In `@src/main/resources/application-swagger.properties` at line 18, Replace the
hard-coded jwt.secret value in application-swagger.properties with a reference
to an environment-provided secret (e.g., use the jwt.secret property to read
from an environment variable or config placeholder) so the repo does not contain
a static secret; update code that loads properties if necessary to resolve the
environment variable for the jwt.secret property and ensure your CI/workflow
sets the env var used.

Copy link

@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: 2

🤖 Fix all issues with AI agents
In @.github/workflows/swagger-json.yml:
- Around line 68-70: The workflow step "Copy Swagger JSON" can fail if the
destination directory doesn't exist; update that step to create the target
directory before copying by running a command like "mkdir -p
amrit-docs/docs/swagger" prior to the "cp admin-api.json
amrit-docs/docs/swagger/admin-api.json" command so the directory is guaranteed
to exist when the copy runs.
- Around line 41-44: The workflow currently runs `jq . swagger_raw.json` on one
line and then `echo "Swagger generated successfully"` and `exit 0` on the next,
which allows a jq failure to be ignored; update the step so the jq invocation
must succeed before printing success or exiting (e.g., chain commands with && or
check jq's exit code) when CODE == "200" so that failure to parse
swagger_raw.json prevents writing/committing an invalid admin-api.json and
returns a non-zero exit instead of running the success branch; reference the
`jq` invocation, `swagger_raw.json`, `admin-api.json`, the `CODE` check and the
`exit 0` behavior when making this change.
🧹 Nitpick comments (2)
.github/workflows/swagger-json.yml (2)

26-27: Consider removing the jq installation step.

jq is pre-installed on GitHub's ubuntu-latest runners, so this step can be removed to simplify the workflow and save a few seconds.

♻️ Suggested change
-      - name: Install jq
-        run: sudo apt-get update && sudo apt-get install -y jq
-
       - name: Run API in swagger profile

23-35: Consider using the packaged JAR instead of rebuilding with spring-boot:run.

The workflow packages the application (line 24) but then runs mvn spring-boot:run which rebuilds. This effectively builds the project twice. Using the packaged JAR is more efficient.

♻️ Suggested change
       - name: Run API in swagger profile
         run: |
-          mvn spring-boot:run \
-            -Dspring-boot.run.profiles=swagger \
-            -Dspring-boot.run.arguments=--server.port=9090 \
+          java -jar -Dspring.profiles.active=swagger \
+            target/*.jar --server.port=9090 \
             > app.log 2>&1 &
           echo $! > api_pid.txt

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 3, 2026

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.

1 participant