Skip to content
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

feat: OpenAPI page #1853

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

feat: OpenAPI page #1853

wants to merge 3 commits into from

Conversation

k-yang
Copy link
Member

@k-yang k-yang commented Apr 23, 2024

Purpose / Abstract

Creates an OpenAPI 2.0 (aka Swagger) page available at the LCD endpoint.

Screenshot 2024-04-23 at 3 05 40 PM

Summary by CodeRabbit

  • New Features

    • Introduced a new system for generating and updating Swagger documentation for the Nibiru Chain gRPC Gateway.
    • Added functionality to register Swagger routes using Gorilla mux for improved routing and static file serving.
  • Bug Fixes

    • Removed outdated imports and functions related to HTTP handling and Swagger API registration, ensuring cleaner and more efficient code.
  • Documentation

    • Updated Swagger documentation setup to support comprehensive REST interface documentation for various modules.

@k-yang k-yang marked this pull request as ready for review April 23, 2024 20:06
@k-yang k-yang requested a review from a team as a code owner April 23, 2024 20:06
Copy link
Contributor

coderabbitai bot commented Apr 23, 2024

Walkthrough

The recent updates represent a significant restructuring of Swagger documentation and routing mechanisms in the application. The changes involve removing outdated HTTP and Swagger setup from the main app components, while introducing new scripts and configurations for generating and handling Swagger documentation for the Nibiru Chain gRPC Gateway.

Changes

File Pattern Change Summary
app/app.go Removed HTTP and Swagger-related imports and functions.
app/keepers.go Removed import related to static Swagger files.
app/swagger.go, contrib/... Added mechanisms for Swagger route registration and documentation generation and handling.
proto/buf.gen.swagger.yaml Added configuration for generating Swagger documentation from protobuf.

🐇✨
In the code's garden, changes bloom,
Docs sprout up, clearing the gloom.
Swagger paths, now neatly laid,
With protobuf tales, the docs are made.
Hoppily crafting, on we zoom! 🚀
🐇💻


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6aff6ad and 79ad315.
Files selected for processing (1)
  • CHANGELOG.md (1 hunks)
Additional comments not posted (1)
CHANGELOG.md (1)

52-52: The changelog entry for the addition of Swagger documentation is clear and well-formatted.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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
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: 4

Comment on lines +13 to +22
// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router) {
statikFS, err := fs.New()
if err != nil {
panic(err)
}

staticServer := http.FileServer(statikFS)
rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider handling the error more gracefully instead of using panic. It's generally better to return an error and let the caller handle it, which could improve the robustness of the application.

- if err != nil {
-     panic(err)
- }
+ if err != nil {
+     return fmt.Errorf("failed to create statikFS: %w", err)
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router) {
statikFS, err := fs.New()
if err != nil {
panic(err)
}
staticServer := http.FileServer(statikFS)
rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer))
}
// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router) error {
statikFS, err := fs.New()
if err != nil {
return fmt.Errorf("failed to create statikFS: %w", err)
}
staticServer := http.FileServer(statikFS)
rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer))
return nil
}

for dir in $proto_dirs; do
# generate swagger files (filter query files)
query_file=$(find "${dir}" -maxdepth 1 \( -name 'query.proto' -o -name 'service.proto' \))
if [[ ! -z "$query_file" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve the condition check by using -n instead of ! -z for clarity and consistency in bash scripting.

- if [[ ! -z "$query_file" ]]; then
+ if [[ -n "$query_file" ]]; then

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if [[ ! -z "$query_file" ]]; then
if [[ -n "$query_file" ]]; then

query_file=$(find "${dir}" -maxdepth 1 \( -name 'query.proto' -o -name 'service.proto' \))
if [[ ! -z "$query_file" ]]; then
# echo $query_file
buf generate --template buf.gen.swagger.yaml $query_file
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure variables are double-quoted to prevent globbing and word splitting, which can lead to unexpected behavior or security issues.

- buf generate --template buf.gen.swagger.yaml $query_file
+ buf generate --template buf.gen.swagger.yaml "$query_file"

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
buf generate --template buf.gen.swagger.yaml $query_file
buf generate --template buf.gen.swagger.yaml "$query_file"

Comment on lines +14 to +16
ifeq ($(GO),)
$(error could not find go. Is it in PATH? $(GO))
endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure that the error message is clear and helpful. Consider adding more details about how to resolve the issue if Go is not found in the PATH.

- $(error could not find go. Is it in PATH? $(GO))
+ $(error Could not find the Go executable. Please ensure that Go is installed and available in your PATH.)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
ifeq ($(GO),)
$(error could not find go. Is it in PATH? $(GO))
endif
ifeq ($(GO),)
$(error Could not find the Go executable. Please ensure that Go is installed and available in your PATH.)
endif

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