Skip to content

first try add documentaiton - #46

Merged
j03-dev merged 4 commits into
mainfrom
feat/doc
Jun 8, 2025
Merged

first try add documentaiton#46
j03-dev merged 4 commits into
mainfrom
feat/doc

Conversation

@j03-dev

@j03-dev j03-dev commented Jun 8, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Introduced a new method to access session data from requests, raising an error if session storage is not configured.
    • Added a utility to serve static files from a specified directory and URL path.
  • Bug Fixes

    • Improved error handling when parsing JSON from the request body, now raising a Python exception if the body is missing.
  • Documentation

    • Enhanced and expanded Python-style docstrings for various classes and methods, including usage examples and detailed descriptions for improved developer guidance.
    • Added detailed documentation for HTTP status codes and enabled rich comparison operations in Python.
    • Documented new methods for file content access and saving uploaded files.
    • Provided comprehensive docs for server configuration, routing, session management, response handling, CORS settings, template rendering, and error catchers.
    • Added detailed documentation to JWT handling and token verification methods.

@coderabbitai

coderabbitai Bot commented Jun 8, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This update enhances Python-style documentation for methods in the Jwt, HttpServer, Request, Catcher, Cors, Multipart File, Response, Routing, Session, Status, and Templating components, providing detailed docstrings and usage examples. The Request class's json method now raises explicit exceptions on errors, and a new session method is introduced. A new static_file function is added for serving static files. A rich comparison method is added to the Status enum. No logic changes were made to other components.

Changes

File(s) Change Summary
src/jwt.rs Expanded and clarified docstrings for Jwt class and its methods; added usage examples.
src/lib.rs Added Python-style docstrings and usage examples to HttpServer methods: new, attach, session_store, template, cors, catchers, and run.
src/request.rs Updated json method to return PyResult and raise exceptions; added session method; added/expanded Python-style docstrings for json, session, app_data, and query.
src/catcher.rs Added comprehensive docstrings to Catcher, CatcherBuilder, __call__ method, and catcher function.
src/cors.rs Added docstrings to Cors struct, fields, constructor, __repr__, apply_headers, and apply_to_response methods.
src/multipart.rs Added docstring to File class; added content and save methods with documentation and examples.
src/response.rs Added detailed docstrings to Response and Redirect classes and their methods.
src/routing.rs Added docstrings and examples to Route, Router, and their methods; added new static_file function with full docstring and example.
src/session.rs Added docstrings to Session and SessionStore classes and all their public methods.
src/status.rs Added detailed doc comments to Status enum and variants; added Python-exposed __richcmp__ method for rich comparisons.
src/templating/mod.rs Added docstrings to Template enum, constructor, and new render function with usage examples.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Request
    participant SessionStore

    User->>Request: call session()
    alt Session store configured
        Request->>SessionStore: retrieve session
        SessionStore-->>Request: return Session
        Request-->>User: return Session
    else No session store
        Request-->>User: raise AttributeError
    end
Loading

Possibly related PRs

  • feat(#34): session management #36: Implements the session management system including Session and SessionStore classes and integrates session handling into requests, directly related to the new session method added to Request.

Poem

🐇 In code’s green fields, where docstrings grow,
Rabbits hop with knowledge to show.
Sessions found, errors caught in flight,
Static files served with pure delight.
Status codes now compare with ease,
Documentation blooms in the breeze!
🌿✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 437c01a and e82880e.

📒 Files selected for processing (1)
  • src/lib.rs (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib.rs
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: windows (windows-latest, x64)
  • GitHub Check: musllinux (ubuntu-22.04, x86)
  • GitHub Check: linux (ubuntu-22.04, ppc64le)
  • GitHub Check: linux (ubuntu-22.04, x86)
  • GitHub Check: linux (ubuntu-22.04, s390x)
  • GitHub Check: linux (ubuntu-22.04, x86_64)
  • GitHub Check: musllinux (ubuntu-22.04, armv7)
  • GitHub Check: linux (ubuntu-22.04, armv7)
  • GitHub Check: linux (ubuntu-22.04, aarch64)
  • GitHub Check: musllinux (ubuntu-22.04, x86_64)
  • GitHub Check: windows (windows-latest, x86)
  • GitHub Check: macos (macos-14, aarch64)
  • GitHub Check: macos (macos-13, x86_64)
  • GitHub Check: musllinux (ubuntu-22.04, aarch64)
✨ 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.

@j03-dev
j03-dev requested a review from LucaZH June 8, 2025 09:50

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (7)
src/lib.rs (3)

92-102: Fix inconsistent comment formatting and improve documentation.

The docstring has inconsistent comment formatting and could be clearer.

Apply this diff to improve consistency and clarity:

-    /// Returns: Instance of httpserver
-    //
+    /// Returns:
+    ///     HttpServer: A new HttpServer instance
+    ///

123-134: Fix inconsistent comment formatting.

The docstring uses inconsistent comment syntax with a stray // marker.

-    /// Returns: None
-    //
+    /// Returns:
+    ///     None
+    ///

155-167: Fix inconsistent comment formatting.

The docstring uses inconsistent comment syntax with a stray // marker.

-    /// Returns: None
-    //
+    /// Returns:
+    ///     None
+    ///
src/request.rs (4)

56-70: Fix inconsistent comment formatting and improve documentation.

The docstring has inconsistent comment formatting and grammatical issues.

-    /// Returns:
-    ///     Return Dictionary: return body as dictionary from body
-    //
+    /// Returns:
+    ///     dict: The request body parsed as a dictionary
+    ///
     /// Raises:
-    ///     Exception: if body is not present in the request
+    ///     Exception: If the body is not present in the request

79-84: Fix grammatical error in docstring.

There's a typo in "requeset" and awkward phrasing.

-    /// Get app data from requeset
+    /// Get app data from request
     ///
     /// Args: None
     ///
     /// Returns:
-    ///     Return: Instance of `app_data` None if there is not app data in your app
+    ///     Any | None: The app data instance or None if not configured

90-105: Fix grammatical issues and improve documentation clarity.

The docstring has grammatical errors and could be clearer.

     /// Returns:
-    ///     Return Dictionary: query from uri request and None if there is not query present
+    ///     dict | None: Query parameters from the URI, or None if no query string present
     ///
     /// Raises:
-    ///     Exception: if the uri is not in right format
+    ///     Exception: If the URI format is invalid
     ///
     /// Example:
     /// ```python
-    /// # locahost:8000/api?key=value
+    /// # localhost:8000/api?key=value

117-131: Fix typo and improve documentation consistency.

There's a typo in "requset" and the example has a syntax error with the boolean value.

-    /// Get Session from requset
+    /// Get Session from request
     ///
     /// Args: None
     ///
     /// Returns:
-    ///     Return: Session instance
+    ///     Session: The session instance
     ///
     /// Raises:
     ///     AttributeError: if session store is not configured on the app
     ///
     /// Example:
     /// ```python
     /// session = request.session()
-    /// session["is_auth"] = true
+    /// session["is_auth"] = True
     /// ```
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a3141b1 and a3a32e1.

📒 Files selected for processing (3)
  • src/jwt.rs (3 hunks)
  • src/lib.rs (2 hunks)
  • src/request.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: macos (macos-13, x86_64)
  • GitHub Check: musllinux (ubuntu-22.04, aarch64)
  • GitHub Check: musllinux (ubuntu-22.04, x86)
  • GitHub Check: windows (windows-latest, x64)
  • GitHub Check: macos (macos-14, aarch64)
  • GitHub Check: windows (windows-latest, x86)
  • GitHub Check: musllinux (ubuntu-22.04, armv7)
  • GitHub Check: musllinux (ubuntu-22.04, x86_64)
  • GitHub Check: linux (ubuntu-22.04, ppc64le)
  • GitHub Check: linux (ubuntu-22.04, s390x)
  • GitHub Check: linux (ubuntu-22.04, aarch64)
  • GitHub Check: linux (ubuntu-22.04, x86)
  • GitHub Check: linux (ubuntu-22.04, armv7)
  • GitHub Check: linux (ubuntu-22.04, x86_64)
🔇 Additional comments (3)
src/jwt.rs (2)

42-57: LGTM! Well-structured constructor documentation.

The docstring follows good Python documentation conventions with clear Args, Returns, Raises, and Example sections.


122-136: LGTM! Clear method documentation with good example.

The docstring provides comprehensive information about the method's behavior, including error handling details.

src/request.rs (1)

71-76:

Details

❓ Verification inconclusive

Breaking change: json method now raises exceptions instead of returning None.

The method signature changed from Option<Py<PyDict>> to PyResult<Py<PyDict>>, which is a breaking change for existing users who expect None when no body is present.

Verify if this breaking change is intentional and documented in release notes:


🏁 Script executed:

#!/bin/bash
# Check for any mention of breaking changes or migration guides
rg -i "breaking|migration|changelog" --type md

Length of output: 48


Missing documentation for json() breaking change

  • In src/request.rs (lines 71–76), the json method signature changed from Option<Py<PyDict>> to PyResult<Py<PyDict>>, meaning it now raises an exception instead of returning None when there’s no body.
  • No references to this breaking change were found in your markdown files (changelog, migration guide, etc.).

Please verify that this API change is intentional and update your release notes or add a migration guide to document it.

Comment thread src/jwt.rs
Comment thread src/lib.rs Outdated
@j03-dev j03-dev linked an issue Jun 8, 2025 that may be closed by this pull request
4 tasks

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
src/multipart.rs (1)

60-63: Optimize memory usage in content method.

The current implementation creates an unnecessary copy by converting Bytes to Vec<u8>. Since Bytes already implements AsRef<[u8]>, we can avoid the allocation.

-    fn content<'py>(&'py self, py: Python<'py>) -> Bound<'py, PyBytes> {
-        let data = &self.data.to_vec()[..];
-        PyBytes::new(py, data)
-    }
+    fn content<'py>(&'py self, py: Python<'py>) -> Bound<'py, PyBytes> {
+        PyBytes::new(py, &self.data)
+    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7ad847b and 437c01a.

📒 Files selected for processing (10)
  • src/catcher.rs (2 hunks)
  • src/cors.rs (4 hunks)
  • src/lib.rs (4 hunks)
  • src/multipart.rs (2 hunks)
  • src/request.rs (4 hunks)
  • src/response.rs (4 hunks)
  • src/routing.rs (5 hunks)
  • src/session.rs (10 hunks)
  • src/status.rs (1 hunks)
  • src/templating/mod.rs (3 hunks)
✅ Files skipped from review due to trivial changes (6)
  • src/templating/mod.rs
  • src/session.rs
  • src/cors.rs
  • src/response.rs
  • src/routing.rs
  • src/catcher.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib.rs
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: macos (macos-14, aarch64)
  • GitHub Check: linux (ubuntu-22.04, x86_64)
  • GitHub Check: macos (macos-13, x86_64)
  • GitHub Check: linux (ubuntu-22.04, ppc64le)
  • GitHub Check: linux (ubuntu-22.04, x86)
  • GitHub Check: linux (ubuntu-22.04, s390x)
  • GitHub Check: windows (windows-latest, x86)
  • GitHub Check: linux (ubuntu-22.04, armv7)
  • GitHub Check: linux (ubuntu-22.04, aarch64)
  • GitHub Check: musllinux (ubuntu-22.04, armv7)
  • GitHub Check: windows (windows-latest, x64)
  • GitHub Check: musllinux (ubuntu-22.04, x86_64)
  • GitHub Check: musllinux (ubuntu-22.04, aarch64)
  • GitHub Check: musllinux (ubuntu-22.04, x86)
🔇 Additional comments (8)
src/status.rs (3)

8-32: Excellent comprehensive documentation!

The enum-level documentation is well-structured and provides valuable context for users. The categorization by status code ranges and the practical Python examples make this very developer-friendly.


37-165: Comprehensive status code documentation enhances API usability.

Each status code variant is now properly documented with accurate descriptions that align with HTTP RFCs. This will significantly help developers understand the purpose and appropriate usage of each status code.


170-206: Well-implemented rich comparison method with practical value.

The __richcmp__ implementation correctly enables all Python comparison operations between Status values. Converting to underlying u16 values for comparison is the right approach, and the documentation example demonstrates a practical use case for status code range checking.

src/multipart.rs (2)

9-34: Excellent comprehensive documentation added.

The docstring provides clear description, usage examples, and proper formatting. The example demonstrates realistic usage patterns for file upload handling.


83-86: Consider path validation for security.

The save method implementation is correct, but consider documenting the potential security implications of path traversal attacks when user input is used for the path parameter.

The docstring could benefit from a security note about validating file paths, especially when accepting user input.

 /// Save the file content to disk.
 ///
 /// Args:
 ///     path (str): The path where the file should be saved.
+///
+/// Note:
+///     Ensure the path is validated to prevent directory traversal attacks
+///     when using user-provided input.
src/request.rs (3)

22-44: Excellent comprehensive class documentation.

The docstring provides clear description of the Request class with realistic usage examples. The documentation structure follows Python conventions well.


199-206: Well-implemented session method.

The new session method properly handles the case where session store is not configured by raising an appropriate AttributeError with a helpful message. The implementation correctly clones the session instance.


145-175: Solid query parameter parsing implementation.

The method correctly parses URI query parameters and handles the case where no query string exists. The error handling for URI parsing is appropriate.

Comment thread src/request.rs
@j03-dev
j03-dev merged commit 1c90942 into main Jun 8, 2025
@j03-dev
j03-dev deleted the feat/doc branch June 8, 2025 15:39
@coderabbitai coderabbitai Bot mentioned this pull request Aug 9, 2026
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.

Enhance Class and Method Documentation with Examples

1 participant