-
Notifications
You must be signed in to change notification settings - Fork 0
(fix) swagger stuff #8
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
teetangh
commented
Aug 14, 2025
- Improved Couchbase initialization with error handling for misconfigurations.
- Added new API endpoints for hotel autocomplete and filtering in Swagger documentation.
- Updated Swagger server URL to a more generic format.
- Improved Couchbase initialization with error handling for misconfigurations. - Added new API endpoints for hotel autocomplete and filtering in Swagger documentation. - Updated Swagger server URL to a more generic format.
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.
Summary of Changes
Hello @teetangh, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request primarily focuses on enhancing the robustness of Couchbase initialization and expanding the API documentation within Swagger. It introduces error handling for Couchbase connection issues and adds new endpoints for hotel search functionalities, while also simplifying the Swagger server URL configuration.
Highlights
- Improved Couchbase Initialization: The Couchbase connection logic is now wrapped in a begin...rescue block, allowing the Rails application to boot even if Couchbase is unreachable or misconfigured. Uninitialized constants will be set to nil in such cases.
- New Hotel API Endpoints in Swagger: Two new API endpoints, /api/v1/hotels/autocomplete (GET) and /api/v1/hotels/filter (POST), have been added to the Swagger documentation, enabling hotel search and filtering capabilities.
- Simplified Swagger Server URL: The Swagger server URL configuration has been streamlined from a dynamic http://{defaultHost} to a more generic and relative /.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces error handling for Couchbase initialization, preventing application boot failures. It also adds two new API endpoints for hotel search and autocomplete, with corresponding Swagger documentation updates. The server URL in Swagger has been generalized to a relative path.
My review focuses on improving code quality and documentation clarity. I've identified a significant issue in the Couchbase initializer regarding constant re-assignment, which can cause warnings and unpredictable behavior. I've also suggested a refactoring to make the search index creation more maintainable. Additionally, I've pointed out several areas in the new Swagger documentation where descriptions are misleading or contain minor typos, with suggestions to improve their accuracy and clarity for API consumers.
DB_USERNAME = ENV.fetch('DB_USERNAME', DEFAULT_DB_USERNAME) | ||
DB_PASSWORD = ENV.fetch('DB_PASSWORD', DEFAULT_DB_PASSWORD) | ||
DB_CONN_STR = ENV.fetch('DB_CONN_STR', DEFAULT_DB_CONN_STR) | ||
|
||
# Connect to the Couchbase cluster | ||
options = Couchbase::Cluster::ClusterOptions.new | ||
options.authenticate(DB_USERNAME, DB_PASSWORD) | ||
COUCHBASE_CLUSTER = Couchbase::Cluster.connect(DB_CONN_STR, options) | ||
end | ||
# Connect to the Couchbase cluster | ||
options = Couchbase::Cluster::ClusterOptions.new | ||
options.authenticate(DB_USERNAME, DB_PASSWORD) | ||
COUCHBASE_CLUSTER = Couchbase::Cluster.connect(DB_CONN_STR, options) |
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.
Re-assigning constants DB_USERNAME
, DB_PASSWORD
, and DB_CONN_STR
here is problematic. In Ruby, this generates a warning and is considered bad practice as it can lead to confusing behavior. These constants are already defined at the top of the file (lines 4-6).
A better approach is to use local variables to hold the configuration for the non-CI environment, and then use those to connect. This avoids constant re-assignment and makes the code's intent clearer.
db_username = ENV.fetch('DB_USERNAME', DEFAULT_DB_USERNAME)
db_password = ENV.fetch('DB_PASSWORD', DEFAULT_DB_PASSWORD)
db_conn_str = ENV.fetch('DB_CONN_STR', DEFAULT_DB_CONN_STR)
# Connect to the Couchbase cluster
options = Couchbase::Cluster::ClusterOptions.new
options.authenticate(db_username, db_password)
COUCHBASE_CLUSTER = Couchbase::Cluster.connect(db_conn_str, options)
index = Couchbase::Management::SearchIndex.new | ||
index.name= index_data["name"] | ||
index.type= index_data["type"] | ||
index.uuid= index_data["uuid"] if index_data.has_key?("uuid") | ||
index.params= index_data["params"] if index_data.has_key?("params") | ||
index.source_name= index_data["sourceName"] if index_data.has_key?("sourceName") | ||
index.source_type= index_data["sourceType"] if index_data.has_key?("sourceType") | ||
index.source_uuid= index_data["sourceUUID"] if index_data.has_key?("sourceUUID") | ||
index.source_params= index_data["sourceParams"] if index_data.has_key?("sourceParams") | ||
index.plan_params= index_data["planParams"] if index_data.has_key?("planParams") |
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.
This block of code manually assigns properties from the parsed JSON to the SearchIndex
object. This is verbose and hard to maintain. If the JSON structure in hotel_search_index.json
changes, you'll need to update this code.
You can make this more dynamic and concise by iterating over the JSON data and using metaprogramming to call the appropriate setter methods on the index
object. This will make the code more resilient to changes.
index = Couchbase::Management::SearchIndex.new
index_data.each do |key, value|
setter = "#{key.underscore}="
index.public_send(setter, value) if index.respond_to?(setter)
end
@@ -441,6 +441,79 @@ paths: | |||
type: string | |||
'400': | |||
description: bad request | |||
"/api/v1/hotels/autocomplete": | |||
get: | |||
summary: Retrieve suggestion for Hotel names |
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.
type: string | ||
responses: | ||
'200': | ||
description: No suggestion |
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.
The description "No suggestion" for a successful response is misleading. It should describe the successful outcome, for example, that a list of suggestions is returned. The current description seems to be for a specific test case (an empty result) rather than the general behavior of the endpoint.
description: A list of hotel name suggestions
parameters: [] | ||
responses: | ||
'200': | ||
description: only one Hotels found |
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.
The description "only one Hotels found" is too specific and likely incorrect for a general filter endpoint, which can return zero, one, or multiple hotels. A more accurate description would be "A list of hotels matching the filter criteria."
description: A list of hotels matching the filter criteria