Skip to content
This repository was archived by the owner on Sep 24, 2025. It is now read-only.

fix: swagger path fixed#353

Merged
tty47 merged 1 commit intomainfrom
fix/move-swagger-file
May 23, 2025
Merged

fix: swagger path fixed#353
tty47 merged 1 commit intomainfrom
fix/move-swagger-file

Conversation

@tty47
Copy link
Copy Markdown
Collaborator

@tty47 tty47 commented May 22, 2025

closes: #352

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability when serving the Swagger UI, ensuring it loads correctly regardless of the application's working directory.

@tty47 tty47 requested review from a team, aWN4Y25pa2EK, pippokr and sysrex and removed request for a team May 22, 2025 14:49
@tty47 tty47 self-assigned this May 22, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 22, 2025

Walkthrough

The changes update the method used to locate and serve the Swagger UI HTML file in the API routes. Instead of using a hardcoded relative path, the code now computes the absolute path at runtime. Minor whitespace modification was also made to the HTML file.

Changes

File(s) Change Summary
pkg/api/v1/routes/swagger-ui.html Added a trailing space after the closing </html> tag and removed the ending newline character.
pkg/api/v1/routes/swagger.go Replaced hardcoded relative path with dynamic absolute path resolution for serving Swagger UI.

Assessment against linked issues

Objective Addressed Explanation
Fix prod Swagger with Kong issues (#352)

Possibly related PRs

  • feat: Add swagger #338: Adds Swagger documentation files and routes, including initial Swagger UI serving logic, which is directly affected by this PR's changes.

Suggested labels

documentation, api

Suggested reviewers

  • mojtaba-esk
  • aWN4Y25pa2EK
  • sysrex

Poem

A rabbit hopped through code so neat,
No more lost Swagger on its feet!
With paths resolved, the docs appear,
No Kong confusion—crystal clear.
A trailing space, a tidy end,
Now Swagger routes won’t break or bend!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@tty47 tty47 added bug Something isn't working api API labels May 22, 2025
@celestia-bot celestia-bot requested a review from a team May 22, 2025 14:49
@tty47
Copy link
Copy Markdown
Collaborator Author

tty47 commented May 22, 2025

@CodeRabbit full review and summary please

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 22, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get PR description and metadata
gh pr view 353 --json title,body,author,baseRefName,headRefName,state,mergeable

# Get the diff of the changed files
git diff --color=never $(git merge-base HEAD origin/main) HEAD -- pkg/api/v1/routes/swagger-ui.html pkg/api/v1/routes/swagger.go

# Get the content of the changed files
echo "=== swagger-ui.html ==="
cat pkg/api/v1/routes/swagger-ui.html
echo "=== swagger.go ==="
cat pkg/api/v1/routes/swagger.go

# Check if there are any tests for these files
echo "=== Tests for swagger.go ==="
find pkg -name "*_test.go" -exec grep -l "swagger.go" {} \;

# Check the project structure to understand the context
echo "=== Project structure for pkg/api/v1/routes ==="
find pkg/api/v1/routes -type f | sort

Length of output: 3651


🏁 Script executed:

#!/bin/bash
# Get the actual diff with proper context
git diff origin/main...HEAD -- pkg/api/v1/routes/swagger-ui.html pkg/api/v1/routes/swagger.go

# Check if the swagger-ui.html file was moved from another location
git log --name-status --find-renames=90% --oneline -n 10 -- pkg/api/v1/routes/swagger-ui.html

# Get information about the related issue
gh issue view 352 --json title,body,state

# Check the commit message for this PR
git log -n 1 --pretty=format:"%s%n%n%b" HEAD

Length of output: 252


🏁 Script executed:

#!/bin/bash
# Get the diff using the commit range from the PR
gh pr view 353 --json commits | jq -r '.commits[0].oid' | xargs -I{} git show {} -- pkg/api/v1/routes/swagger-ui.html pkg/api/v1/routes/swagger.go

# Get the file history differently
echo "=== File history for swagger-ui.html ==="
git log --oneline -- pkg/api/v1/routes/swagger-ui.html

# Check the routes.go file to understand the API structure
echo "=== routes.go content ==="
cat pkg/api/v1/routes/routes.go

Length of output: 10905


@tty47 Here's my full review of PR #353, which fixes Swagger path issues with Kong in production:

Summary

This PR addresses issue #352 by adding two new files to fix Swagger UI in the production environment with Kong. The solution uses runtime.Caller() to dynamically locate the Swagger UI HTML file, ensuring it works correctly regardless of how the application is deployed.

Changes Review

  • Added swagger-ui.html: Standard Swagger UI template configured to fetch API docs from "/swagger/doc.json"
  • Added swagger.go: Registers two routes:
    • GET /swagger - Serves the Swagger UI HTML
    • GET /swagger/doc.json - Serves the Swagger JSON documentation

Positive Aspects

  • The dynamic path resolution using runtime.Caller() is a robust approach that should work in various environments
  • The implementation integrates cleanly with the existing route registration system
  • The Swagger UI is properly configured with good default settings

Suggestions for Improvement

  1. Consider adding error handling for the runtime.Caller(0) call:
_, b, _, ok := runtime.Caller(0)
if !ok {
    // Handle error or use a fallback path
}
  1. Add tests for the Swagger routes to ensure they work as expected

  2. If the HTML file is derived from Swagger UI, consider adding appropriate attribution/license notice

Overall, this is a straightforward and effective fix for the Swagger path issues in production environments.

Copy link
Copy Markdown
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: 0

🧹 Nitpick comments (2)
pkg/api/v1/routes/swagger-ui.html (1)

63-63: Minor whitespace issue.

There's a trailing space after the closing </html> tag. While this doesn't affect functionality, it's generally good practice to maintain clean HTML without trailing whitespace. Also note that the file no longer ends with a newline character, which is recommended by POSIX standards.

-</html> 
+</html>
pkg/api/v1/routes/swagger.go (1)

17-17: Consider handling potential errors from runtime.Caller.

The current implementation ignores all return values from runtime.Caller except for the file path. While failures are rare, it's a good practice to handle potential errors.

-_, b, _, _ := runtime.Caller(0)
+_, b, _, ok := runtime.Caller(0)
+if !ok {
+    // Handle error, perhaps log it or use a fallback path
+    log.Println("Warning: Could not determine runtime file path for Swagger UI")
+    // You might want to set a fallback path or handle this case
+}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1770726 and e79e74d.

📒 Files selected for processing (2)
  • pkg/api/v1/routes/swagger-ui.html (1 hunks)
  • pkg/api/v1/routes/swagger.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: docker-security-build / docker-build (GHCR; ghcr.io/celestiaorg/talis)
  • GitHub Check: test
🔇 Additional comments (2)
pkg/api/v1/routes/swagger.go (2)

16-19: Good approach for dynamic path resolution.

Using runtime.Caller to dynamically determine the file location is a robust solution that fixes the Swagger path issue. This approach ensures the HTML file is correctly located regardless of the working directory from which the application is run.


22-22: Properly uses the dynamically determined path.

This change correctly uses the dynamically determined path to send the Swagger UI HTML file, which should resolve the original issue.

@tty47 tty47 merged commit 3dcab8e into main May 23, 2025
17 checks passed
@tty47 tty47 deleted the fix/move-swagger-file branch May 23, 2025 07:14
@coderabbitai coderabbitai bot mentioned this pull request May 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api API bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: prod swagger with kong issues

1 participant