Skip to content

refactor!: upgrade utoipa to v5 #65

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

Merged
merged 14 commits into from
Sep 14, 2024
Merged

refactor!: upgrade utoipa to v5 #65

merged 14 commits into from
Sep 14, 2024

Conversation

kwaa
Copy link
Member

@kwaa kwaa commented Sep 14, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced API documentation and routing capabilities through the integration of OpenAPI specifications using utoipa and utoipa_axum.
    • Introduced new API structures and constants (TAG) for better organization and maintainability across various modules.
  • Bug Fixes

    • Corrected typographical errors in API documentation responses.
  • Refactor

    • Streamlined routing logic by replacing hardcoded tags with constants, improving code maintainability.
    • Removed deprecated dependencies and modules to focus on updated libraries.
  • Documentation

    • Improved clarity and usability of API documentation by adopting OpenAPI standards across multiple endpoints.

@kwaa kwaa added the enhancement New feature or request label Sep 14, 2024
@kwaa kwaa added this to the 0.3 [Strobe Nights] milestone Sep 14, 2024
Copy link
Contributor

coderabbitai bot commented Sep 14, 2024

Walkthrough

The changes involve significant modifications to the Rust project's structure, particularly in the handling of dependencies, routing, and API documentation. The Cargo.toml files across various crates have been updated to include new dependencies related to OpenAPI and Axum, while obsolete dependencies have been removed. The routing functionality has transitioned to utilize OpenApiRouter, enhancing documentation capabilities. Additionally, several modules have been restructured to improve maintainability and clarity, with constants introduced for tagging API paths.

Changes

File(s) Change Summary
Cargo.toml (multiple crates) New dependencies added: utoipa, utoipa-axum, utoipa-scalar; removed hatsu_openapi.
crates/api/.../Cargo.toml Dependency utoipa-axum added; url removed.
crates/api/src/lib.rs Added export for TAG from routes.
crates/api/src/routes/... Introduced OpenApiRouter, added TAG, and enhanced API documentation.
crates/api_admin/... Added utoipa-axum, updated route handling to utilize OpenAPI features.
crates/api_apub/... Transitioned to OpenApiRouter, added ApubApi struct for documentation.
crates/api_mastodon/... Introduced MastodonApi, updated routes to use OpenApiRouter.
crates/backend/... Added openapi module, integrated OpenAPI documentation into routing.
crates/nodeinfo/... Added utoipa-axum, introduced NodeInfoApi for OpenAPI schema.
crates/openapi/... Removed files related to hatsu_openapi, including documentation structures.
crates/well_known/... Added utoipa-axum, transitioned to OpenApiRouter, introduced WellKnownApi.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant OpenApiRouter
    participant Documentation

    Client->>API: Request API Endpoint
    API->>OpenApiRouter: Route Request
    OpenApiRouter->>Documentation: Generate OpenAPI Spec
    Documentation-->>OpenApiRouter: Return Spec
    OpenApiRouter-->>Client: Response with Documentation
Loading

🐰 In the land of code where rabbits play,
New dependencies hop in, brightening the day.
OpenAPI routes, like carrots, align,
With every change, our project will shine!
So let’s celebrate this coding delight,
With hops of joy, we’ll code through the night! 🌟

Tip

OpenAI O1 model for chat
  • We have deployed OpenAI's latest O1 model for chat.
  • OpenAI claims that this model has superior reasoning capabilities than their GPT-4o model.
  • Please share any feedback with us in the discussions post.

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.
    • @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 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.

@kwaa kwaa changed the title refactor: upgrade utoipa to v5 refactor!: upgrade utoipa to v5 Sep 14, 2024
@kwaa kwaa marked this pull request as ready for review September 14, 2024 13:29
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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0034188 and 1e868cb.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (48)
  • Cargo.toml (1 hunks)
  • crates/api/Cargo.toml (1 hunks)
  • crates/api/src/lib.rs (1 hunks)
  • crates/api/src/routes/generate_204.rs (1 hunks)
  • crates/api/src/routes/mod.rs (1 hunks)
  • crates/api_admin/Cargo.toml (1 hunks)
  • crates/api_admin/src/lib.rs (1 hunks)
  • crates/api_admin/src/routes/create_account.rs (1 hunks)
  • crates/api_admin/src/routes/mod.rs (1 hunks)
  • crates/api_admin/src/routes/remove_account.rs (1 hunks)
  • crates/api_apub/Cargo.toml (1 hunks)
  • crates/api_apub/src/activities/activity.rs (2 hunks)
  • crates/api_apub/src/activities/mod.rs (1 hunks)
  • crates/api_apub/src/lib.rs (1 hunks)
  • crates/api_apub/src/posts/mod.rs (1 hunks)
  • crates/api_apub/src/posts/post.rs (2 hunks)
  • crates/api_apub/src/users/mod.rs (1 hunks)
  • crates/api_apub/src/users/user.rs (2 hunks)
  • crates/api_apub/src/users/user_followers.rs (1 hunks)
  • crates/api_apub/src/users/user_following.rs (1 hunks)
  • crates/api_apub/src/users/user_outbox.rs (1 hunks)
  • crates/api_mastodon/Cargo.toml (1 hunks)
  • crates/api_mastodon/src/lib.rs (1 hunks)
  • crates/api_mastodon/src/routes/instance/mod.rs (1 hunks)
  • crates/api_mastodon/src/routes/instance/v1.rs (1 hunks)
  • crates/api_mastodon/src/routes/instance/v2.rs (1 hunks)
  • crates/api_mastodon/src/routes/mod.rs (1 hunks)
  • crates/api_mastodon/src/routes/statuses/mod.rs (1 hunks)
  • crates/api_mastodon/src/routes/statuses/status_context.rs (1 hunks)
  • crates/api_mastodon/src/routes/statuses/status_favourited_by.rs (1 hunks)
  • crates/api_mastodon/src/routes/statuses/status_reblogged_by.rs (1 hunks)
  • crates/backend/Cargo.toml (1 hunks)
  • crates/backend/src/lib.rs (1 hunks)
  • crates/backend/src/openapi.rs (1 hunks)
  • crates/backend/src/routes.rs (1 hunks)
  • crates/nodeinfo/Cargo.toml (1 hunks)
  • crates/nodeinfo/src/handler.rs (2 hunks)
  • crates/nodeinfo/src/lib.rs (1 hunks)
  • crates/nodeinfo/src/routes.rs (1 hunks)
  • crates/openapi/Cargo.toml (0 hunks)
  • crates/openapi/src/apidoc.rs (0 hunks)
  • crates/openapi/src/lib.rs (0 hunks)
  • crates/well_known/Cargo.toml (1 hunks)
  • crates/well_known/src/lib.rs (1 hunks)
  • crates/well_known/src/routes/host_meta.rs (1 hunks)
  • crates/well_known/src/routes/mod.rs (1 hunks)
  • crates/well_known/src/routes/nodeinfo.rs (1 hunks)
  • crates/well_known/src/routes/webfinger.rs (2 hunks)
Files not reviewed due to no reviewable changes (3)
  • crates/openapi/Cargo.toml
  • crates/openapi/src/apidoc.rs
  • crates/openapi/src/lib.rs
Files skipped from review due to trivial changes (15)
  • crates/api_admin/src/routes/create_account.rs
  • crates/api_admin/src/routes/remove_account.rs
  • crates/api_apub/src/activities/activity.rs
  • crates/api_apub/src/posts/post.rs
  • crates/api_apub/src/users/user_followers.rs
  • crates/api_apub/src/users/user_following.rs
  • crates/api_apub/src/users/user_outbox.rs
  • crates/api_mastodon/src/routes/instance/v1.rs
  • crates/api_mastodon/src/routes/instance/v2.rs
  • crates/api_mastodon/src/routes/statuses/status_context.rs
  • crates/api_mastodon/src/routes/statuses/status_favourited_by.rs
  • crates/api_mastodon/src/routes/statuses/status_reblogged_by.rs
  • crates/nodeinfo/src/handler.rs
  • crates/well_known/src/routes/nodeinfo.rs
  • crates/well_known/src/routes/webfinger.rs
Additional comments not posted (68)
crates/api/src/lib.rs (1)

3-3: Verify the usage of the exported TAG entity.

The change looks good! Exporting the TAG entity expands the public API of the module, which may be necessary for routing or tagging purposes within the application.

To ensure the TAG entity is being used correctly, please run the following script:

Verification successful

Verified: TAG constant is correctly used and exported.

The TAG constant is consistently defined, used, and exported across multiple crates in the project. It's primarily used for API route tagging and OpenAPI documentation, following a consistent pattern throughout the codebase. The export of TAG in various crates allows for its use in other parts of the application, promoting consistency in API documentation and routing.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the exported `TAG` entity.

# Test 1: Search for the usage of the `TAG` entity. 
# Expect: At least one occurrence of the `TAG` entity being used.
rg --type rust -A 5 $'TAG'

# Test 2: Search for the declaration of the `TAG` entity.
# Expect: The `TAG` entity should be declared as a constant.
ast-grep --lang rust --pattern $'const TAG: $_ = $_;'

Length of output: 17313

crates/api_admin/src/lib.rs (1)

4-4: LGTM!

Re-exporting TAG from the routes module is a good change as it makes the constant available for use outside the module. This change enhances the module's interface and is consistent with the provided summary.

crates/api_mastodon/src/lib.rs (1)

4-4: LGTM!

Exporting TAG from the routes module enhances the module's public API by allowing external access to it. The change is consistent with the provided summary and does not alter any existing functionality.

crates/well_known/src/lib.rs (1)

4-4: LGTM!

The change is consistent with the PR objective of upgrading utoipa to v5. Exporting TAG from the routes module enhances the module's interface by providing more functionality or information related to routing.

crates/nodeinfo/src/lib.rs (1)

5-5: LGTM!

Exporting TAG from the routes module is a valid change. It allows the constant to be used by other parts of the application, which aligns with the PR objective of upgrading the project structure.

crates/backend/src/openapi.rs (1)

1-9: LGTM! The code follows best practices for generating OpenAPI documentation.

The ApiDoc struct is correctly annotated with the necessary metadata, and the code references the relevant paths and components for comprehensive API documentation.

To ensure the accuracy of the generated documentation, please verify the following:

  1. The post function in the hatsu_api_apub::posts::post module is correctly implemented and matches the documented behavior.
  2. The AppError schema in hatsu_utils accurately represents the possible error responses.

You can use the following script to locate and review the referenced code:

Verification successful

To further investigate the missing post function and verify the AppError implementation, we need to run additional scripts:


To complete our verification, we need to check the post function signature and compare it with the OpenAPI documentation. Let's run one more script:


To complete our verification, let's run one more script to check for any OpenAPI documentation in the entire post.rs file:


Verification successful: The post function and AppError schema are correctly implemented and documented.

The post function in crates/api_apub/src/posts/post.rs is properly implemented and includes OpenAPI documentation using the #[utoipa::path( attribute. The function signature matches the reference in the openapi.rs file.

The AppError schema is correctly implemented in crates/utils/src/error.rs and includes all necessary fields and methods for robust error handling.

Both the post function and AppError schema are accurately referenced in the openapi.rs file, ensuring that the OpenAPI documentation is consistent with the actual implementation.

No issues were found during the verification process.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash

# Locate and review the `post` function
ast-grep --lang rust --pattern $'fn post($$$) {
  $$$
}'

# Locate and review the `AppError` schema
rg --type rust $'AppError'

Length of output: 17896


Script:

#!/bin/bash

# Search for any function named 'post' in Rust files
rg --type rust '^\s*(?:pub\s+)?(?:async\s+)?fn\s+post'

# Check the content of the openapi.rs file
cat crates/backend/src/openapi.rs

# Examine the AppError implementation
cat crates/utils/src/error.rs

Length of output: 2267


Script:

#!/bin/bash

# Check the post function signature
sed -n '/pub async fn post/,/^}/p' crates/api_apub/src/posts/post.rs

# Check the OpenAPI documentation for the post function
grep -A 10 'pub async fn post' crates/api_apub/src/posts/post.rs | grep -E '(#\[utoipa|///)'

Length of output: 820


Script:

#!/bin/bash

# Check for any OpenAPI documentation in the post.rs file
grep -E '(#\[utoipa|///)' crates/api_apub/src/posts/post.rs

# List files in the crates/api_apub/src/posts directory
ls -l crates/api_apub/src/posts/

# Check for any OpenAPI documentation files in the project
find . -name '*openapi*.yaml' -o -name '*openapi*.json' -o -name '*swagger*.yaml' -o -name '*swagger*.json'

Length of output: 415

crates/api_mastodon/src/routes/instance/mod.rs (3)

1-3: LGTM!

The imports are correct and necessary for the changes made in the file to integrate OpenAPI using utoipa and utoipa_axum.


4-4: LGTM!

The import is correct and necessary for generating the OpenAPI documentation using the MastodonApi struct.


9-12: Excellent refactor!

The changes made to the routes function significantly improve the API's compliance with OpenAPI standards and facilitate better documentation and client generation. The use of OpenApiRouter and the routes! macro streamlines the process of defining routes and integrating OpenAPI specifications directly into the routing setup.

crates/api/src/routes/generate_204.rs (1)

3-8: LGTM!

Using a constant TAG instead of a hardcoded tag string is a good practice for maintainability and consistency. This change makes it easier to update the tag across different routes without affecting the functionality of the API endpoint.

crates/api_apub/src/activities/mod.rs (3)

1-3: LGTM!

The imports are correct and necessary for integrating OpenAPI support using utoipa and utoipa_axum crates.


9-11: Excellent work on integrating OpenAPI support!

The changes to the routes() function are correct and align with the objective of integrating OpenAPI support:

  • Using OpenApiRouter instead of axum::Router to initialize the router with the OpenAPI specification generated by ApubApi::openapi().
  • Utilizing the routes! macro to simplify the definition of routes for the activity handler.

These changes enhance the API's functionality by improving documentation and leveraging the OpenAPI integration.


11-11: Verify the impact of the route change and ensure proper communication.

The route for handling activities has been changed from "/activities/:activity" to "/a/:activity". This change in the URL structure might impact the API consumers.

Please ensure that:

  1. The change is communicated to the API users through appropriate channels (e.g., release notes, migration guides).
  2. The API documentation is updated to reflect the new URL structure.
  3. Any client code or examples using the old URL structure are updated accordingly.

You can use the following script to search for occurrences of the old URL structure in the codebase and documentation:

If you find any occurrences, please update them to use the new URL structure ("/a/:activity").

Verification successful

Route change verified, consider updating documentation

The route change from "/activities/:activity" to "/a/:activity" has been successfully implemented in the codebase. The new route is present in a Rust file:

.route("/a/:activity", get(activity::redirect))

No occurrences of the old URL structure were found, indicating a consistent update across the codebase.

Action items:

  1. Review the API documentation files in the docs/ directory to ensure they reflect the new URL structure.
  2. Update any external documentation or communication channels to inform API consumers about this change.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash

# Search for occurrences of the old URL structure in Rust files
fd --extension rs --exec rg '"/activities/:activity"'

# Search for occurrences of the old URL structure in documentation files (e.g., Markdown)
fd --extension md --exec rg '"/activities/:activity"'

Length of output: 111


Script:

#!/bin/bash

# Search for the new URL structure in Rust files
echo "Searching for new URL structure '/a/:activity':"
fd --extension rs --exec rg '"/a/:activity"'

# Search for "activities" in URL contexts in Rust files
echo "Searching for 'activities' in URL contexts:"
fd --extension rs --exec rg 'activities.*"/'

# Look for API documentation files
echo "Searching for API documentation files:"
fd -e md -e yaml -e json | grep -i 'api\|docs\|swagger\|openapi'

Length of output: 1634

crates/api/src/routes/mod.rs (4)

1-2: LGTM!

The imports are correctly specified and necessary for the updated implementation of the API routes using utoipa and utoipa_axum.


6-6: LGTM!

The constant is correctly defined and used to categorize the API under the name "hatsu", enhancing the organization and documentation of the API.


8-10: LGTM!

The HatsuApi struct is correctly defined and annotated with #[derive(OpenApi)] and #[openapi(tags(...))] for automatic generation of OpenAPI specifications. The attributes are correctly specified and there are no issues with the code segment.


12-13: LGTM!

The changes to the routes function are correctly implemented for integrating the OpenAPI documentation with the defined routes. The OpenApiRouter is correctly created using the with_openapi method and the HatsuApi::openapi() argument. The routes macro is correctly used to specify the routes for the API. There are no issues with the code segment.

crates/api_apub/src/posts/mod.rs (2)

1-3: LGTM!

The imports are correctly added to support the transition to OpenApiRouter and the integration of OpenAPI documentation.


10-11: LGTM!

The routes() function has been correctly updated to return an OpenApiRouter initialized with the OpenAPI specification. This change enhances the API's documentation and usability.

crates/api/Cargo.toml (1)

21-21: LGTM!

The changes in the [dependencies] section align with the PR objective of upgrading utoipa to v5 and integrating it with Axum. The removal of the url dependency and the addition of utoipa-axum are consistent with this goal.

The changes are self-contained within the dependencies and don't introduce any issues or inconsistencies in the package configuration.

crates/api_mastodon/src/routes/statuses/mod.rs (4)

1-2: LGTM!

The imports are correctly specified and necessary for the new OpenAPI integration.


4-4: LGTM!

The import is correctly specified and necessary for initializing the OpenApiRouter with the OpenAPI specification derived from the MastodonApi struct.


6-8: LGTM!

The module declarations are correctly specified and indicate a shift towards a more modular and organized code structure, improving maintainability and clarity.


10-14: LGTM!

The changes in the routes function enhance the API's functionality by integrating OpenAPI support, which is crucial for API documentation and client generation. The routes! macro streamlines the route registration process and enhances the documentation capabilities of the API. The code segment is correctly implemented.

crates/nodeinfo/Cargo.toml (1)

27-27: LGTM!

The addition of the utoipa-axum dependency is consistent with the PR objective of upgrading utoipa to v5. The dependency is added correctly using the workspace flag to ensure consistency across the project.

This change is likely intended to enhance the functionality related to the Axum framework in conjunction with the Utoipa library, potentially for improved API documentation or integration within the Axum web framework.

crates/api_admin/Cargo.toml (1)

27-27: LGTM!

The addition of the utoipa-axum dependency is consistent with the PR objective of upgrading utoipa to v5. It will enhance integration with the Axum framework and improve API documentation capabilities.

The dependency is added correctly using the workspace flag, which is consistent with the other dependencies in the file.

crates/well_known/Cargo.toml (1)

28-28: LGTM!

The addition of the utoipa-axum dependency is consistent with the PR objective of upgrading utoipa to v5. Using the workspace flag ensures consistency across the project.

This change will facilitate integration of the Utoipa framework with the Axum web framework for improved API documentation generation.

crates/api_apub/Cargo.toml (1)

31-31: LGTM!

The addition of the utoipa-axum dependency aligns with the PR objective of upgrading utoipa to v5 and enhancing the project's API documentation capabilities by integrating with the Axum web framework.

The use of the workspace attribute { workspace = true } ensures consistent dependency management across the project.

crates/api_mastodon/src/routes/mod.rs (4)

1-2: LGTM!

The imports are correctly specified and necessary for the refactoring to use utoipa for generating OpenAPI documentation.


4-12: LGTM!

The entity struct imports are correctly specified and necessary for defining the components in the OpenAPI schema.


14-32: LGTM!

The MastodonApi struct is correctly defined with the OpenApi derive macro to generate the OpenAPI documentation. The components and tags sections are correctly specified, and the TAG constant is correctly defined and used.


34-37: LGTM!

The routes function is correctly modified to return an OpenApiRouter that integrates the OpenAPI documentation with the existing routes from the instance and statuses modules.

crates/api_mastodon/Cargo.toml (1)

34-34: LGTM!

The addition of the utoipa-axum dependency is consistent with the PR objective and the AI-generated summary. The dependency is added correctly using the workspace configuration.

crates/api_apub/src/lib.rs (3)

15-31: LGTM!

The introduction of the ApubApi struct is a good practice as it formalizes the API's data structures and improves its clarity and usability. The use of #[derive(OpenApi)] and #[openapi(...)] annotations is correct and aligns with the utoipa library's usage. The encapsulation of the schemas for various entities is a good practice as it improves the API's structure and documentation.


33-34: LGTM!

The update to the routes function is a good practice as it integrates OpenAPI specifications into the routing mechanism. The use of OpenApiRouter is correct and aligns with the utoipa_axum library's usage. The merging of routes from the activities, posts, and users modules maintains the existing functionality while enhancing the overall structure and documentation of the API.


13-13: LGTM!

The introduction of the TAG constant is a good practice as it improves the maintainability and clarity of the code. The use of the TAG constant in the #[openapi(...)] annotation is correct and aligns with the utoipa library's usage.

crates/backend/Cargo.toml (3)

32-32: LGTM!

The addition of the utoipa dependency is a good move to enhance the project's API documentation capabilities. Marking it as part of the workspace is also beneficial for shared compilation and dependency management.


33-33: Looks good!

The addition of the utoipa-axum dependency is a sensible choice given the project's use of the Axum web framework. It will enable generating OpenAPI documentation for Axum routes. Marking it as part of the workspace is also beneficial for shared compilation and dependency management.


34-34: Approved.

The addition of the utoipa-scalar dependency is a good choice if the project uses custom scalar types and wants to include them in the OpenAPI documentation. Marking it as part of the workspace is also beneficial for shared compilation and dependency management.

crates/api_apub/src/users/mod.rs (4)

1-3: LGTM!

The new imports are necessary for the updated routing functionality and OpenAPI integration. The changes look good.


5-5: LGTM!

The new import is necessary for initializing the OpenApiRouter with the OpenAPI schema. The change looks good.


12-19: Great work on updating the routing functionality!

The changes to the routes function, including the transition to OpenApiRouter, the initialization with the OpenAPI schema, and the streamlined routing definitions, significantly improve the API's structure and documentation while maintaining the core routing logic. Well done!


20-26: LGTM!

Preserving the fallback routes for user redirection ensures that the existing functionality remains intact. The changes look good.

crates/nodeinfo/src/routes.rs (4)

1-3: LGTM!

The new imports are necessary for the refactoring to integrate OpenAPI specifications using the utoipa and utoipa_axum libraries.


5-15: LGTM!

The imports from the crate::schema module are necessary for defining the OpenAPI schema components in the NodeInfoApi struct.


17-31: LGTM!

  • The TAG constant is used to define the tag for the OpenAPI documentation.
  • The NodeInfoApi struct is used to define the OpenAPI schema components and tags for the NodeInfo API.
  • The #[openapi] attribute is used to define the OpenAPI schema components and tags for the NodeInfoApi struct.

33-37: LGTM!

  • The routes function has been refactored to use the OpenApiRouter instead of a standard Router to integrate OpenAPI specifications.
  • The routes! macro is used to register the routes for handling requests to /nodeinfo/2.0 and /nodeinfo/2.1.
  • The fallback routes are added to handle requests to /nodeinfo/2.0 and /nodeinfo/2.1 in case the routes! macro fails to register the routes.
crates/well_known/src/routes/mod.rs (5)

1-11: LGTM!

The import statements are correct and necessary for the new implementation using utoipa and utoipa_axum. The existing imports for various entities remain unchanged, ensuring compatibility with the rest of the code.


17-17: LGTM!

The constant declaration is correct and follows the naming convention. Using a constant for tagging the API paths is a good practice for better organization and documentation.


19-31: LGTM!

The struct declaration is correct and follows the utoipa library's conventions for defining the API's schemas and tags. This is a good practice for enhancing the API documentation capabilities. The OpenApi derive macro and the openapi attribute are used correctly to define the API's components and tags.


33-39: LGTM!

The changes to the routes function are correct and align with the new implementation using utoipa and utoipa_axum. The use of OpenApiRouter and the routes! macro enhances the API documentation capabilities and streamlines the process of associating handlers with their respective paths. This is a good practice for improving the maintainability and extensibility of the code.


1-39: Great work on refactoring the routing functionality!

The overall changes in the file are correct and align with modern API practices. The integration of utoipa and utoipa_axum libraries enhances the documentation capabilities and improves the maintainability and extensibility of the code. The changes are well-structured and follow best practices for defining API routes.

Some key highlights:

  • The use of OpenApiRouter and the routes! macro streamlines the process of associating handlers with their respective paths.
  • The introduction of the WellKnownApi struct, annotated with the OpenApi derive macro, allows for better organization and documentation of the API's schemas and tags.
  • The use of constants for tagging the API paths improves the readability and maintainability of the code.

Overall, the refactoring effort has significantly improved the quality and usability of the code. Great job!

crates/backend/src/routes.rs (4)

1-5: LGTM!

The new imports are necessary for integrating OpenAPI documentation and scalar support. The usage of these types is correct.


15-22: Excellent refactoring!

The usage of OpenApiRouter and merging of various API routes is implemented correctly. Splitting the router using split_for_parts is a good approach for separating the API router from the main router.

Note: The split_for_parts method returns a tuple of the API router and the OpenAPI documentation. This allows for serving the OpenAPI documentation separately from the API routes.


24-28: Great addition of OpenAPI and scalar support!

Serving the OpenAPI JSON at /openapi.json is a good practice for providing API documentation. The scalar integration at /scalar enhances the API's capabilities.

The usage of Json and Scalar types is correct, and the routes are properly set up.


30-35: LGTM!

The main router is set up correctly with routes for the root, favicon, and API. Merging the API router into the main router is the right approach.

The code changes are clear and follow best practices for structuring the application routes.

crates/backend/src/lib.rs (1)

11-11: LGTM!

The addition of the openapi module aligns with the PR objectives and AI summary. It is added in the appropriate location, maintains the existing structure of the file, and follows the Rust naming convention for modules.

The module likely contains code related to OpenAPI specifications, which can enhance API documentation and interaction capabilities. This is a valuable addition to the project.

crates/api_admin/src/routes/mod.rs (5)

9-14: LGTM!

The imports from the utoipa library are necessary for integrating the OpenAPI documentation generation capabilities.


16-20: LGTM!

The imports of the entities and modules are necessary for defining the API components and registering the routes.


21-31: LGTM!

  • The constant TAG is used to group the API paths under a common tag, which is a good practice for organizing the API documentation.
  • The HatsuAdminApi struct is correctly defined with the necessary components and modifiers.

33-44: LGTM!

  • The SecurityAddon struct and its implementation are correctly defined.
  • The modify method correctly adds the API key security scheme to the OpenAPI specification.

46-49: LGTM!

  • The routes function correctly returns an OpenApiRouter with the OpenAPI specification generated from the HatsuAdminApi struct.
  • The routes for creating and removing accounts are correctly registered using the routes! macro.
crates/well_known/src/routes/host_meta.rs (2)

12-12: LGTM!

Importing the TAG constant is a good change that improves maintainability by centralizing the tag definition. This will make it easier to update the tag value in the future if needed.


17-17: LGTM!

Updating the tag attribute to use the TAG constant instead of the hardcoded string is a good change. It improves the clarity and flexibility of the code while keeping the overall functionality intact.

crates/api_apub/src/users/user.rs (1)

15-15: LGTM!

The changes made to the handler function improve clarity, maintainability, and consistency:

  • The function renaming from user to handler better reflects its purpose.
  • The usage of a constant TAG for the API path tag improves maintainability and reduces duplication.
  • The removal of commented-out code related to path extraction simplifies the function and improves readability.
  • The function correctly handles the case when the user is not found in the database by returning a "not found" error.
  • The function uses the hatsu_utils::url::generate_user_url function to generate the user URL, which is a good practice for consistency and maintainability.
  • The function uses the FederationJson type to wrap the user JSON response with the appropriate context, which is required for ActivityPub compliance.
  • The function uses the WithContext type to add the context to the user JSON response, which is a good practice for clarity and maintainability.
  • The function uses the ApubUser type to convert the database user to an ActivityPub user, which is a good practice for separation of concerns.
  • The function uses the into_json method to convert the ApubUser to a JSON value, which is a good practice for consistency and maintainability.

Overall, the changes enhance the clarity, maintainability, and consistency of the code while simplifying the user handling logic.

Also applies to: 20-20, 31-69

Cargo.toml (3)

134-135: Assess the impact and compatibility of the new utoipa-axum and utoipa-scalar dependencies.

The introduction of the utoipa-axum and utoipa-scalar dependencies suggests an integration with the Axum web framework and the use of custom scalar types in the API. However, both dependencies are in beta versions (0.1.0-beta and 0.2.0-beta, respectively), indicating that they are still under active development and may have evolving APIs.

Before proceeding, consider the following:

  1. Verify the compatibility and stability of these beta dependencies with the project's existing codebase and requirements.
  2. Assess the impact of these dependencies on the project's functionality, performance, and maintainability.
  3. Evaluate the long-term viability and community support for these dependencies.

To assess the usage and potential impact of these dependencies, run the following script:

Review the usage and ensure that the integration aligns with the project's goals and architecture.

Verification successful

The utoipa-axum and utoipa-scalar dependencies are well-integrated and appropriately used across the project.

The utoipa-axum dependency is extensively used across multiple crates, primarily for OpenAPI routing and documentation. This consistent usage suggests a well-planned integration for API management. The utoipa-scalar dependency, while used less frequently, appears to be employed for handling specific scalar types in the API.

Given the widespread and appropriate use of these dependencies:

  • Continue monitoring these beta versions for updates and potential breaking changes.
  • Consider setting up automated dependency update checks to stay informed about new releases.
  • Ensure thorough testing of API functionality when upgrading these dependencies, as their beta status may lead to occasional API changes.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for `utoipa_axum` and `utoipa_scalar` usage in Rust files
rg --type rust -e 'utoipa_axum' -e 'utoipa_scalar'

Length of output: 1098


133-133: Consider the implications of updating to a beta version of utoipa.

Updating the utoipa dependency to version 5.0.0-beta is a significant change that may introduce breaking changes and potential instability. Beta versions often have an evolving API and may contain undiscovered bugs.

Before merging these changes, ensure that:

  1. Thorough testing is conducted to verify compatibility and stability with the new version.
  2. The maturity and stability of the beta version align with the project's requirements and risk tolerance.

Consider running the following script to search for utoipa usage across the codebase and assess the potential impact of the update:

Review the usage and ensure that any necessary adjustments are made to accommodate the new version.


Line range hint 1-1: Clarify the reasoning behind the removal of the hatsu_openapi workspace member.

The removal of the hatsu_openapi workspace member, which was located at ./crates/openapi, suggests that the functionality provided by this crate is no longer needed or has been replaced by another solution. This change might be related to the introduction of the utoipa and related dependencies.

To ensure a smooth transition, please:

  1. Provide a clear explanation for the removal of hatsu_openapi and how its functionality is being handled now.
  2. Verify that all references to hatsu_openapi have been properly removed from the codebase to avoid any build failures or runtime errors.

You can use the following script to search for any remaining references to hatsu_openapi:

If any references are found, ensure they are appropriately addressed or removed.

Verification successful

The hatsu_openapi workspace member has been successfully removed and replaced.

Our thorough search of the codebase confirms that all references to hatsu_openapi have been completely removed. The project has transitioned to using utoipa and utoipa_axum for OpenAPI functionality, which is consistently implemented across various modules.

This change appears to be well-executed, maintaining the necessary OpenAPI capabilities while streamlining the project's dependencies. No further action is required regarding this removal.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for `hatsu_openapi` usage in the codebase
rg -i 'hatsu_openapi'

Length of output: 21


Script:

#!/bin/bash
# Test rg command with a common term
echo "Testing rg command:"
rg -i 'cargo'

# Search for files or directories containing 'openapi'
echo "Searching for files/directories with 'openapi':"
fd -i openapi

# Search for imports or uses of 'hatsu_openapi'
echo "Searching for imports/uses of 'hatsu_openapi':"
ast-grep --lang rust --pattern 'use $$$hatsu_openapi$$$'

# Search for 'openapi' references
echo "Searching for 'openapi' references:"
rg -i 'openapi'

Length of output: 10688

@kwaa kwaa merged commit 1c9c0ce into main Sep 14, 2024
1 check passed
@kwaa kwaa deleted the deps/utoipa branch September 14, 2024 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant