-
Notifications
You must be signed in to change notification settings - Fork 97
api: Fix missing items in the openAPI spec #6737
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
Conversation
Warning Rate limit exceeded@Teebor-Choka has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 49 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
📝 Walkthrough📝 Walkthrough📝 WalkthroughWalkthroughThis pull request introduces enhancements to the Hopr REST API, focusing on improving OpenAPI documentation, session management, and routing capabilities. The changes primarily involve updating the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
52998ed
to
d5d6412
Compare
d41a93c
to
0bf5f48
Compare
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (2)
hoprd/rest-api/src/session.rs (1)
100-104
: Consider removing#[repr(u8)]
fromSessionCapability
enumThe
#[repr(u8)]
attribute on theSessionCapability
enum may not be necessary since the enum variants are already unit-like and serialization is handled by Serde. Keeping#[repr(u8)]
could lead to unintended behaviors during serialization or when adding new variants in the future. Removing it reduces potential issues and aligns with Rust's best practices for enums.hoprd/rest-api/src/lib.rs (1)
Line range hint
1-424
: Consider adding response examples to the OpenAPI documentation.While the schema definitions have been added, consider enhancing the documentation by adding example responses for the session-related endpoints. This would improve the swagger-ui experience.
Example enhancement for
SessionClientResponse
:#[derive(Debug, Clone, Serialize, utoipa::ToSchema)] +#[schema(example = json!({ + "id": "12345", + "status": "connected", + "target": { + "address": "127.0.0.1:8000", + "protocol": "tcp" + } +}))] pub struct SessionClientResponse { // existing fields... }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (3)
hoprd/rest-api/src/lib.rs
(1 hunks)hoprd/rest-api/src/session.rs
(12 hunks)tests/hopr.py
(1 hunks)
🔇 Additional comments (2)
tests/hopr.py (1)
500-502
: Ensure proper parameter passing when calling session_close_client
The updated session_close_client
method now directly passes ip
and port
to the __call_api
method. Verify that the SessionApi
client expects these parameters as path parameters and that they are correctly passed in the API call. This ensures that the method functions as intended with the updated API endpoint.
hoprd/rest-api/src/lib.rs (1)
150-150
: LGTM! The schema additions align with PR objectives.
The addition of session-related schemas (SessionClientRequest
, SessionCapability
, RoutingOptions
, SessionTargetSpec
, SessionClientResponse
) to the OpenAPI documentation addresses the missing schemas issue mentioned in #6727.
Let's verify that the DELETE operation for session endpoints doesn't accept a request body:
✅ Verification successful
DELETE operation conforms to standards - no request body found
After reviewing the implementation in session.rs
, I can confirm that the DELETE operation for closing sessions (close_client
function) is properly implemented and does not accept a request body. The function only takes path parameters (protocol
, ip
, and port
) to identify the session to close, which aligns with REST API best practices.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify DELETE operation conformance in OpenAPI spec
# Expected: DELETE operations should not have requestBody
# Search for DELETE operation definitions in the OpenAPI spec
ast-grep --pattern 'delete($$$).route("/session/$$$", $$$)'
# Search for any DELETE operations that might have request bodies
rg -A 5 'delete\(' hoprd/rest-api/src/session.rs
Length of output: 251
Script:
#!/bin/bash
# Let's try a different approach to find DELETE operations in the codebase
# Search for DELETE operations in the REST API implementation
rg -i "delete.*session" hoprd/rest-api/src/lib.rs
# Look for route handlers in session.rs
rg "fn.*delete" hoprd/rest-api/src/session.rs
# Check the actual implementation of session-related operations
cat hoprd/rest-api/src/session.rs
Length of output: 39094
0bf5f48
to
ea45aec
Compare
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
hoprd/rest-api/src/session.rs (3)
314-333
: Add documentation for theRoutingOptions
enum.While the implementation is correct, adding documentation would improve API clarity:
- Purpose of each variant
- When to use
IntermediatePath
vsHops
- Impact of the
explicit-path
feature flag#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, utoipa::ToSchema)] +/// Options for configuring the routing behavior of a session. pub enum RoutingOptions { #[cfg(feature = "explicit-path")] #[schema(value_type = Vec<String>)] + /// Route through specific intermediate peers in the given order. IntermediatePath(#[serde_as(as = "Vec<DisplayFromStr>")] Vec<PeerId>), + /// Route through the specified number of random intermediate hops. Hops(usize), }
693-712
: Add documentation for theIpProtocol
enum.The enum implementation is correct, but adding documentation would improve API clarity:
- Purpose of the enum
- When to use each protocol variant
- Impact on session behavior
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, strum::Display, strum::EnumString, utoipa::ToSchema)] #[strum(serialize_all = "lowercase", ascii_case_insensitive)] #[serde(rename_all = "lowercase")] +/// Supported IP protocols for session communication. pub enum IpProtocol { #[allow(clippy::upper_case_acronyms)] + /// Transmission Control Protocol - reliable, ordered delivery TCP, #[allow(clippy::upper_case_acronyms)] + /// User Datagram Protocol - unreliable, unordered delivery UDP, }
917-917
: Enhance test coverage for routing options.The tests use
Default::default()
forIntermediatePath
, which might not adequately test all routing scenarios. Consider adding test cases for:
- Different path lengths
- Various hop counts
- Invalid path configurations
Also applies to: 939-939, 982-982
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (3)
hoprd/rest-api/src/lib.rs
(1 hunks)hoprd/rest-api/src/session.rs
(18 hunks)tests/hopr.py
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- tests/hopr.py
- hoprd/rest-api/src/lib.rs
🔇 Additional comments (4)
hoprd/rest-api/src/session.rs (4)
100-124
: LGTM! Well-structured enum with clear documentation.
The SessionCapability
enum and its implementation are well-designed with:
- Clear documentation for each variant
- Proper trait derivations including
utoipa::ToSchema
for OpenAPI spec - Clean conversion implementation to
hopr_lib::SessionCapability
714-720
: LGTM! Proper implementation of query parameters for DELETE operation.
The SessionCloseClientQuery
struct properly encapsulates the path parameters for the close operation, aligning with REST standards and fixing the previous implementation issues.
746-748
: LGTM! Improved path parameter handling.
The updated implementation correctly uses a single Path
extractor with a structured type, addressing the previous concerns about multiple path parameter extraction.
56-56
: LGTM! OpenAPI schema improvements are complete.
All necessary types now properly derive utoipa::ToSchema
and include appropriate schema annotations:
SessionTargetSpec
SessionCapability
RoutingOptions
IpProtocol
SessionCloseClientQuery
This addresses the original issue of missing schemas in swagger-ui.
Also applies to: 101-103, 314-315, 694-695, 714-715
ea45aec
to
f4da88b
Compare
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.
crate version bump missing
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.
See comment - make sure that it builds also without the explicit-path
feature enabled.
4b2a16b
to
bfe9e97
Compare
4c04ab3
to
e54ba71
Compare
There's a failure in E2E tests:
|
It's actually a bug from the previous Now the |
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
Makefile (1)
105-105
: LGTM! Improved process termination signal.The change from default kill to
kill -s INT
is a better practice as it sends an interrupt signal (SIGINT) instead of termination signal (SIGTERM), allowing the process to handle the shutdown more gracefully. This is particularly appropriate for server processes like anvil.tests/utils.py (1)
55-55
: Improve code readability by breaking long linesThe change to use
get()
with a default value is a good defensive programming practice. However, the lines exceed the maximum length of 120 characters.Consider breaking the lines for better readability:
- oc for oc in all_channels.all if oc.get('source_address', None) == src.address and oc.get('destination_address', None) == dest.address + oc for oc in all_channels.all + if (oc.get('source_address', None) == src.address and + oc.get('destination_address', None) == dest.address)Also applies to: 64-64
🧰 Tools
🪛 Ruff (0.8.2)
55-55: Line too long (142 > 120)
(E501)
tests/hopr.py (1)
347-348
: Improve code style in membership testThe membership test can be written more idiomatically.
- if not param in getattr(response, status)[0]: + if param not in getattr(response, status)[0]:🧰 Tools
🪛 Ruff (0.8.2)
347-347: Test for membership should be
not in
Convert to
not in
(E713)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
Makefile
(1 hunks)tests/conftest.py
(1 hunks)tests/hopr.py
(4 hunks)tests/test_hopli.py
(1 hunks)tests/test_integration.py
(6 hunks)tests/utils.py
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- tests/conftest.py
- tests/test_integration.py
🧰 Additional context used
🪛 Ruff (0.8.2)
tests/utils.py
55-55: Line too long (142 > 120)
(E501)
64-64: Line too long (143 > 120)
(E501)
tests/hopr.py
347-347: Test for membership should be not in
Convert to not in
(E713)
🔇 Additional comments (3)
tests/hopr.py (2)
135-138
: LGTM! Consistent with API changes
The update from peer_id
to peerId
aligns with the API's camelCase naming convention.
517-519
: LGTM! Improved API conformance
The removal of the empty body parameter aligns with REST standards for DELETE operations, and the improved formatting enhances readability.
tests/test_hopli.py (1)
469-469
: LGTM! Verify test coverage after parameter removal.
The removal of the swarm7
parameter simplifies the test's dependencies while maintaining its core functionality of testing safe module creation.
Let's verify that the test coverage remains comprehensive:
This reverts commit c27948c.
a0a717c
to
fab421a
Compare
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
hoprd/rest-api/src/session.rs (2)
119-143
: Document TCP-specific assumptions in capabilities.Based on past learnings, the current implementation assumes TCP-like behavior for sessions. Consider adding documentation to clarify which capabilities are applicable to different session types (TCP vs UDP).
Add documentation like this:
#[repr(u8)] #[derive( Debug, Clone, strum::EnumIter, strum::Display, strum::EnumString, Serialize, Deserialize, utoipa::ToSchema, )] +/// Session capabilities that can be enabled for a connection. +/// Note: Some capabilities are primarily designed for TCP-like sessions +/// and may not be applicable to all session types. pub enum SessionCapability {
402-420
: Optimize capabilities conversion and defaults.The current implementation could be more efficient by avoiding the intermediate Vec allocation.
Consider this optimization:
- capabilities: self - .capabilities - .map(|vs| { - vs.into_iter() - .map(|v| { - let cap: hopr_lib::SessionCapability = v.into(); - cap - }) - .collect::<Vec<_>>() - }) - .unwrap_or_else(|| match target_protocol { - IpProtocol::TCP => { - vec![ - hopr_lib::SessionCapability::Retransmission, - hopr_lib::SessionCapability::Segmentation, - ] - } - _ => vec![], // no default capabilities for UDP, etc. - }), + capabilities: self.capabilities + .map(|vs| vs.into_iter().map(Into::into).collect()) + .unwrap_or_else(|| match target_protocol { + IpProtocol::TCP => vec![ + hopr_lib::SessionCapability::Retransmission, + hopr_lib::SessionCapability::Segmentation, + ], + _ => Vec::new(), + }),
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
hoprd/rest-api/src/session.rs
(18 hunks)tests/hopr.py
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/hopr.py
🧰 Additional context used
📓 Learnings (1)
hoprd/rest-api/src/session.rs (1)
Learnt from: Teebor-Choka
PR: hoprnet/hoprnet#6393
File: hoprd/rest-api/src/session.rs:91-91
Timestamp: 2024-11-12T10:56:01.095Z
Learning: The current implementation in `hoprd/rest-api/src/session.rs` assumes all sessions are TCP-like due to the missing implementation of UDP behavior. The commented-out code suggests an intention to support different session types based on `capabilities`.
🔇 Additional comments (6)
hoprd/rest-api/src/session.rs (6)
29-35
: LGTM: Import changes align with new session capabilities.
The new imports support the added session management functionality and are used appropriately throughout the file.
56-57
: LGTM: Enhanced OpenAPI documentation.
The addition of utoipa::ToSchema
improves API documentation by generating proper OpenAPI schemas for the SessionTargetSpec enum.
332-353
: Add feature-gate checks for IntermediatePath variant.
The feature-gate handling needs to be updated to ensure proper error handling when the explicit-path
feature is disabled.
708-727
: LGTM: Clean protocol enum implementation.
The IpProtocol enum implementation is well-structured with appropriate derive macros and a clean From trait implementation.
729-735
: LGTM: Fixed path parameter extraction.
The implementation correctly handles path parameters using a dedicated struct, addressing the previous issues with parameter extraction.
Also applies to: 763-778
151-152
: Verify backward compatibility with peer_id parameter.
Based on the PR comments, there was an E2E test failure related to the peer_id
parameter due to camelCase conversion. Ensure that both peer_id
and peerId
forms are supported for backward compatibility.
Also applies to: 194-198
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/conftest.py (1)
427-428
: LGTM! Good addition of timeout protection.Adding timeout protection to the node connectivity check is a good improvement that prevents tests from hanging indefinitely if nodes fail to connect.
Consider these improvements:
- Extract the timeout value (60) to a constant at the top of the file for better maintainability
- Add more detailed error logging when timeout occurs, for example:
- nodes_connectivity = await asyncio.wait_for(asyncio.gather(*tasks), timeout) + try: + nodes_connectivity = await asyncio.wait_for(asyncio.gather(*tasks), timeout) + except asyncio.TimeoutError: + logging.error(f"Node connectivity check timed out after {timeout} seconds") + raise
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
hoprd/rest-api/src/lib.rs
(2 hunks)tests/conftest.py
(1 hunks)tests/hopr.py
(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- tests/hopr.py
- hoprd/rest-api/src/lib.rs
🔇 Additional comments (1)
tests/conftest.py (1)
Line range hint 33-34
: Verify parameter naming compatibility with API changes.
Given the reported changes in parameter naming from peer_id
to peerId
due to the utoipa
library update, we should verify if this code needs to be updated for compatibility.
Let's check the API response format:
Minor improvements:
DELETE
operation to not accept a body.Note
Fixes #6727
Needs #6720 (
vacuum-go
) package