Skip to content

Conversation

@ravishanigarapu
Copy link
Contributor

@ravishanigarapu ravishanigarapu commented Apr 17, 2025

πŸ“‹ Description

JIRA ID: AMM-1186

Enable or dissable swagger


βœ… Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • πŸ”₯ Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • πŸ›  Refactor (change that is neither a fix nor a new feature)
  • βš™οΈ Config change (configuration file or build script updates)
  • πŸ“š Documentation (updates to docs or readme)
  • πŸ§ͺ Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • πŸš€ Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

Please describe how the changes were tested, and include any relevant screenshots, logs, or other information that provides additional context.

Summary by CodeRabbit

  • New Features
    • Enabled API documentation and Swagger UI across all environments, allowing users to access interactive API docs.
  • Bug Fixes
    • Updated request filtering to allow access to API documentation and Swagger UI without authentication checks.

@coderabbitai
Copy link

coderabbitai bot commented Apr 17, 2025

Walkthrough

The changes introduce new configuration properties across multiple environment property files to enable or toggle Springdoc API documentation and Swagger UI features. The JWT user ID validation filter was updated to exclude requests to Swagger UI, OpenAPI documentation endpoints, and the user token refresh endpoint from authentication checks, allowing unauthenticated access to API documentation and token refresh. No existing properties or exported/public entities were altered or removed.

Changes

Files/Paths Change Summary
src/main/environment/admin_ci.properties Added springdoc.api-docs.enabled and springdoc.swagger-ui.enabled properties, set via environment variable.
src/main/environment/admin_dev.properties Added trailing comma to common-url and enabled API docs and Swagger UI with two new properties set to true.
src/main/environment/admin_example.properties,
src/main/environment/admin_test.properties,
src/main/environment/admin_uat.properties
Added springdoc.api-docs.enabled=true and springdoc.swagger-ui.enabled=true to enable API docs and Swagger UI.
src/main/java/com/iemr/admin/utils/JwtUserIdValidationFilter.java Updated filter to exclude /swagger-ui, /v3/api-docs, and /user/refreshToken paths from JWT validation.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant JwtUserIdValidationFilter
    participant API Documentation (Swagger/OpenAPI)
    participant Application

    Client->>JwtUserIdValidationFilter: Request to /swagger-ui or /v3/api-docs or /user/refreshToken
    JwtUserIdValidationFilter-->>API Documentation (Swagger/OpenAPI): Bypass JWT validation
    API Documentation (Swagger/OpenAPI)-->>Client: Serve documentation or refresh token

    Client->>JwtUserIdValidationFilter: Request to protected endpoint
    JwtUserIdValidationFilter->>Application: Validate JWT and process request
    Application-->>Client: Response
Loading

Poem

πŸ‡
Swagger docs now hop in view,
With filters letting them pass through.
Paths for docs and tokens clear,
JWT checks skip those near.
Properties set, environments align,
API docs enabledβ€”everything's fine!
Rabbits read the docs with glee,
Secure endpoints, but docs roam free.
Springtime for Swagger, clear as can be!

Tip

βš‘πŸ’¬ Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

πŸ“œ Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 7e5e941 and f91def4.

πŸ“’ Files selected for processing (2)
  • src/main/environment/admin_ci.properties (1 hunks)
  • src/main/java/com/iemr/admin/utils/JwtUserIdValidationFilter.java (1 hunks)
βœ… Files skipped from review due to trivial changes (1)
  • src/main/environment/admin_ci.properties
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/com/iemr/admin/utils/JwtUserIdValidationFilter.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)

πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 1

🧹 Nitpick comments (3)
src/main/environment/admin_ci.properties (1)

24-25: Enable togglable SpringDoc and Swagger UI via SWAGGER_DOC_ENABLED
Consider providing a default fallback if the environment variable is unset, for example:

-springdoc.api-docs.enabled=@env.SWAGGER_DOC_ENABLED@
-springdoc.swagger-ui.enabled=@env.SWAGGER_DOC_ENABLED@
+springdoc.api-docs.enabled=${SWAGGER_DOC_ENABLED:false}
+springdoc.swagger-ui.enabled=${SWAGGER_DOC_ENABLED:false}

This ensures the documentation is disabled by default when SWAGGER_DOC_ENABLED isn’t defined.

src/main/java/com/iemr/admin/utils/JwtUserIdValidationFilter.java (2)

58-59: Consider security implications of exposed API documentation.

While exposing Swagger UI and API documentation is necessary for development and testing environments, consider the security implications in production. Documentation can potentially reveal sensitive API details to unauthorized users.

You might want to implement additional security controls for production environments, such as:

  1. Environment-specific configuration that enables/disables these exclusions
  2. IP-based restrictions for documentation endpoints
  3. Basic authentication for documentation access

58-59: Add comments explaining the purpose of these exclusions.

For better code maintainability, consider adding a brief comment explaining that these paths are excluded to enable Swagger UI and OpenAPI documentation access.

 		// Skip login and public endpoints
 		if (path.equals(contextPath + "/user/userAuthenticate")
 				|| path.equalsIgnoreCase(contextPath + "/user/logOutUserFromConcurrentSession")
+				// Allow Swagger UI and OpenAPI documentation without authentication
 				|| path.startsWith(contextPath + "/swagger-ui")
 				|| path.startsWith(contextPath + "/v3/api-docs")
 				|| path.startsWith(contextPath + "/public")) {
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 19cdc37 and 7e5e941.

πŸ“’ Files selected for processing (6)
  • src/main/environment/admin_ci.properties (1 hunks)
  • src/main/environment/admin_dev.properties (1 hunks)
  • src/main/environment/admin_example.properties (1 hunks)
  • src/main/environment/admin_test.properties (1 hunks)
  • src/main/environment/admin_uat.properties (1 hunks)
  • src/main/java/com/iemr/admin/utils/JwtUserIdValidationFilter.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (java)
πŸ”‡ Additional comments (7)
src/main/environment/admin_test.properties (1)

20-21: Enable SpringDoc and Swagger UI for test environment
These properties correctly activate the Springdoc OpenAPI docs and Swagger UI in the test profile, aligning with the change objective.

src/main/environment/admin_uat.properties (1)

20-21: Enable SpringDoc and Swagger UI for UAT environment
The added settings mirror other environments and will expose the API docs and UI without authentication in UAT.

src/main/environment/admin_dev.properties (1)

21-22: Enable SpringDoc and Swagger UI for dev environment
These new properties correctly activate the Springdoc API docs and Swagger UI in the development profile.

src/main/environment/admin_example.properties (2)

18-18: Add common-url property for example environment
Defining common-url here ensures consistency across all environment configs.


20-21: Enable SpringDoc and Swagger UI for example environment
These settings will expose OpenAPI docs and the Swagger UI in the example profile.

src/main/environment/admin_ci.properties (1)

22-22: Add common-url placeholder for CI environment
Using the @env.COMMON_URL@ placeholder keeps the common service URL configurable via environment variables.

src/main/java/com/iemr/admin/utils/JwtUserIdValidationFilter.java (1)

58-59:

Details

βœ… Verification successful

Adding Swagger UI and OpenAPI docs endpoints to exclusion list is appropriate.

These changes allow the Swagger UI and OpenAPI documentation endpoints to bypass JWT authentication, which aligns with the PR objective to enable Swagger functionality. This is a standard practice for API documentation tools.

Consider whether these exclusions should be conditional based on environment configuration. Since the AI summary mentions configuration properties for enabling/disabling Swagger UI (springdoc.swagger-ui.enabled), you might want to check if these exclusions should only apply when Swagger is enabled:


🏁 Script executed:

#!/bin/bash
# Check if there's any conditional logic elsewhere that controls Swagger UI availability
rg -A 3 -B 3 "springdoc\.swagger-ui\.enabled" --glob "*.java"

Length of output: 63


🏁 Script executed:

#!/bin/bash
# Search configuration files for springdoc.swagger‑ui.enabled property
rg "springdoc\.swagger-ui\.enabled" --glob "*.yml" --glob "*.properties"

Length of output: 479


Approve Swagger UI and API Docs Exclusions

I’ve confirmed that the springdoc.swagger‑ui.enabled property is defined in all environment-specific config files (admin_*.properties), so the Swagger UI and OpenAPI endpoints will only be active when that flag is true. Unconditionally excluding these paths in your JWT filter is safeβ€”if Swagger is disabled the endpoints simply won’t exist.
If you’d rather tie the exclusions directly to the flag, you can inject the springdoc.swagger‑ui.enabled value into JwtUserIdValidationFilter and wrap the path.startsWith(...) checks in an if (swaggerEnabled) block.
No changes required unless you want that extra configuration guard.

spring.main.allow-bean-definition-overriding=true

common-url=http://localhost:8083/
common-url=http://localhost:8083/,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove trailing comma from common-url property
Property files include commas as literal characters; the extra comma in http://localhost:8083/, will become part of the URL and may break downstream calls. Please remove it so the value reads http://localhost:8083/.

@sonarqubecloud
Copy link

@helenKaryamsetty helenKaryamsetty merged commit 9afe3f5 into PSMRI:develop Apr 17, 2025
7 checks passed
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