-
Notifications
You must be signed in to change notification settings - Fork 49
Update the swagger json github workflow #359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughGitHub Actions workflow for generating/validating Swagger JSON was hardened and PR creation updated; OpenAPI config now adds Dev/UAT/Demo servers sourced from environment properties. (49 words) Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
.github/workflows/swagger-json.yml
Outdated
| run: | | ||
| mkdir -p amrit-docs/docs/swagger | ||
| cp common-api.json amrit-docs/docs/swagger/common-api.json | ||
| cp tm-api.json amrit-docs/docs/swagger/tm-api.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DurgaPrasad-54 why does this say tm api in common?
There was a problem hiding this 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-json.yml:
- Around line 96-104: The workflow currently generates unique branches per run
via the create-pull-request step (uses: peter-evans/create-pull-request@v8)
using branch: auto/swagger-update-${{ github.run_id }}-${{ github.run_attempt
}}, which causes many stale PRs; change this to a fixed branch name (e.g.,
branch: auto/swagger-update) so the action will update/force-push the same
branch and keep a single PR open, retaining delete-branch: true for cleanup
after merge.
🧹 Nitpick comments (2)
.github/workflows/swagger-json.yml (2)
67-80: Misleading comments and unconditionalsleep 5before the PID check.Two concerns:
Comment–code mismatch: The "Graceful shutdown" comment (Line 70) annotates the bare
sleep 5, while the actual graceful signal (SIGTERM, Line 75) sits under the "Force kill" comment (Line 72). This will confuse future maintainers.Process-group kill may be a no-op:
kill -- -"$PID"treats$PIDas a PGID. The$!captured on Line 36 is the Maven wrapper PID, which is not guaranteed to be a process-group leader in the Actions runner shell. If it isn't, bothkillcalls silently fail and onlyfuseron Line 80 actually cleans up — so the logic is safe, but the intermediate steps would be dead code.Minor: The unconditional
sleep 5(Line 71) runs even whenapi_pid.txtdoesn't exist. Move it inside theifblock.Proposed cleanup
- 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 - 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 + PID=$(cat api_pid.txt) + # Graceful SIGTERM, then wait + kill -TERM "$PID" 2>/dev/null || true + sleep 5 + # Force SIGKILL if still running + kill -9 "$PID" 2>/dev/null || true + sleep 1 + fi + # Fallback: kill anything still on port 9090 + fuser -k 9090/tcp 2>/dev/null || true
30-36: Consider usingsetsidto guarantee a new process group for reliable group-kill in the Stop step.The PID captured by
$!on Line 36 may not be a process-group leader (relevant to thekill -- -"$PID"calls in the Stop step). If you want the process-group kill pattern to work reliably, launch withsetsid:- mvn spring-boot:run \ + setsid mvn spring-boot:run \ -Dspring-boot.run.profiles=swagger \ -Dspring-boot.run.arguments=--server.port=9090 \ > app.log 2>&1 &This ensures the Maven process is a session/group leader, making
kill -- -"$PID"effective and cleaning up all child processes (including the forked Java process).
✅ Actions performedFull review triggered. |
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
There was a problem hiding this 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/java/com/iemr/common/config/SwaggerConfig.java`:
- Around line 23-25: The SwaggerConfig currently adds Server entries with
hardcoded internal default URLs via System.getenv().getOrDefault(...) for
API_DEV_URL, API_UAT_URL and API_DEMO_URL which exposes internal hostnames when
env vars are missing; update the logic in SwaggerConfig where the new
io.swagger.v3.oas.models.servers.Server() instances are created (the three
Server(...) url(...) calls) so that if the environment variable is unset you
either (a) use a safe default like "http://localhost" or (b) skip adding that
Server entry entirely — choose one approach consistently and implement it by
checking System.getenv("API_*_URL") for null/empty before constructing/adding
the Server or by changing getOrDefault(...) to a safe localhost value.
🧹 Nitpick comments (2)
src/main/java/com/iemr/common/config/SwaggerConfig.java (2)
22-26: Prefer@Valueinjection over rawSystem.getenv()for Spring configuration.Using
System.getenv()bypasses Spring's property resolution, meaning these values can't be overridden viaapplication.properties, profiles, or test configurations. Spring's@Valuewith${ENV_VAR:default}syntax resolves environment variables, system properties, and config files uniformly.♻️ Suggested refactor
Inject the URLs as constructor/field parameters:
`@Configuration` public class SwaggerConfig { `@Value`("${API_DEV_URL:https://amritwprdev.piramalswasthya.org}") private String devUrl; `@Value`("${API_UAT_URL:https://uatamrit.piramalswasthya.org}") private String uatUrl; `@Value`("${API_DEMO_URL:https://amritdemo.piramalswasthya.org}") private String demoUrl; `@Bean` public OpenAPI customOpenAPI() { return new OpenAPI() .info(new Info().title("Common 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") )); } }
22-26: Inline fully-qualified class names — consider adding imports instead.
java.util.Arraysandio.swagger.v3.oas.models.servers.Serverare used with their FQCNs inline. Adding them as imports at the top of the file would improve readability and consistency with the existing import style.
| new io.swagger.v3.oas.models.servers.Server().url(System.getenv().getOrDefault("API_DEV_URL", "https://amritwprdev.piramalswasthya.org")).description("Dev"), | ||
| new io.swagger.v3.oas.models.servers.Server().url(System.getenv().getOrDefault("API_UAT_URL", "https://uatamrit.piramalswasthya.org")).description("UAT"), | ||
| new io.swagger.v3.oas.models.servers.Server().url(System.getenv().getOrDefault("API_DEMO_URL", "https://amritdemo.piramalswasthya.org")).description("Demo") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded default URLs expose internal infrastructure in the OpenAPI spec.
When the environment variables are unset (e.g., local development, CI), the Swagger UI will display and allow "Try it out" requests against real Dev/UAT/Demo servers. Consider whether these defaults should instead point to http://localhost or be left empty to avoid accidental requests to live environments and leaking internal hostnames.
🤖 Prompt for AI Agents
In `@src/main/java/com/iemr/common/config/SwaggerConfig.java` around lines 23 -
25, The SwaggerConfig currently adds Server entries with hardcoded internal
default URLs via System.getenv().getOrDefault(...) for API_DEV_URL, API_UAT_URL
and API_DEMO_URL which exposes internal hostnames when env vars are missing;
update the logic in SwaggerConfig where the new
io.swagger.v3.oas.models.servers.Server() instances are created (the three
Server(...) url(...) calls) so that if the environment variable is unset you
either (a) use a safe default like "http://localhost" or (b) skip adding that
Server entry entirely — choose one approach consistently and implement it by
checking System.getenv("API_*_URL") for null/empty before constructing/adding
the Server or by changing getOrDefault(...) to a safe localhost value.
|



Summary by CodeRabbit
New Features
Bug Fixes
Chores