Skip to content

Conversation

NumberFour8
Copy link
Contributor

  • Updated the NodeVersionResponse struct to include a new apiVersion field and adjusted the version endpoint to return this additional information. Added serde attribute for consistent JSON formatting.
  • Bumped the package version in Cargo files to 3.10.0.

Closes #6697

- Updated the `NodeVersionResponse` struct to include a new `apiVersion` field and adjusted the `version` endpoint to return this additional information. Added `serde` attribute for consistent JSON formatting.
- Bumped the package version in Cargo files to 3.10.0.

Closes #6697
@NumberFour8 NumberFour8 requested a review from a team January 9, 2025 12:13
@NumberFour8 NumberFour8 self-assigned this Jan 9, 2025
Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

📝 Walkthrough

Walkthrough

This pull request updates the REST API package version from 3.9.1 to 3.10.0 and enhances the NodeVersionResponse struct in the node.rs file. The changes introduce an api_version field to the version response, which is populated using the CARGO_PKG_VERSION environment variable. The serialization of the struct has been modified to use camel case for JSON output, improving the API's versioning information and response formatting.

Changes

File Change Summary
hoprd/rest-api/Cargo.toml Package version updated from "3.9.1" to "3.10.0"
hoprd/rest-api/src/node.rs - Added api_version field to NodeVersionResponse struct
- Implemented #[serde(rename_all = "camelCase")] for camel case serialization
- Updated version() function to include api_version

Assessment against linked issues

Objective Addressed Explanation
Create a REST API call to return an API version [#6697]

Possibly related PRs


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>, 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. (Beta)
  • @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.

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.

@github-actions github-actions bot added dependencies Pull requests that update a dependency file crate:hoprd-api labels Jan 9, 2025
@NumberFour8 NumberFour8 marked this pull request as ready for review January 13, 2025 08:08
@mjadach-iv mjadach-iv self-requested a review January 13, 2025 08:08
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: 1

🧹 Nitpick comments (1)
hoprd/rest-api/src/node.rs (1)

46-47: Consider using a static string for better performance.

Since the API version is constant, consider using a static string to avoid allocations on every request:

-    let api_version = env!("CARGO_PKG_VERSION").to_owned();
+    static API_VERSION: &str = env!("CARGO_PKG_VERSION");
+    let api_version = API_VERSION.to_owned();

Or even better, make the entire response static:

+    static VERSION_RESPONSE: std::sync::OnceLock<NodeVersionResponse> = std::sync::OnceLock::new();
+
     let version = state.hopr.version();
-    let api_version = env!("CARGO_PKG_VERSION").to_owned();
-    (StatusCode::OK, Json(NodeVersionResponse { version, api_version })).into_response()
+    let response = VERSION_RESPONSE.get_or_init(|| NodeVersionResponse {
+        version: version.clone(),
+        api_version: env!("CARGO_PKG_VERSION").to_owned(),
+    });
+    (StatusCode::OK, Json(response)).into_response()
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 523bb5e and 0d26853.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • hoprd/rest-api/src/node.rs (2 hunks)
🔇 Additional comments (2)
hoprd/rest-api/src/node.rs (2)

24-24: LGTM! The struct changes look good.

The addition of the api_version field and the camelCase serialization attribute aligns with the PR objectives and ensures consistent JSON formatting.

Also applies to: 27-27


46-46: Implementation approved despite previous concerns.

While there was a discussion about the necessity of this field (see past review comments), the implementation using CARGO_PKG_VERSION is appropriate as it aligns with the agreed-upon solution in issue #6697.

@ausias-armesto ausias-armesto added this to the 2.2.0-rc.1 milestone Jan 13, 2025
@NumberFour8 NumberFour8 merged commit 3ce9f4b into master Jan 14, 2025
29 of 30 checks passed
@NumberFour8 NumberFour8 deleted the lukas/add-api-version branch January 14, 2025 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate:hoprd-api dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a REST API call to return an API version
4 participants