BLOG-103 Add API documentation with Utoipa #106
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "BLOG-103_backend_api_doc"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
This PR integrates the
utoipa
andutoipa-redoc
crates to automatically generate OpenAPI-compliant API documentation for the backend project.Overview
To improve development efficiency and API maintainability, this change introduces
utoipa
to automate the API documentation process. By adding specific attribute macros to the source code, we can generate detailed API specifications directly and serve them through an interactive UI provided byutoipa-redoc
.Key Changes
Dependencies Added
utoipa
,utoipa-gen
, andutoipa-redoc
toCargo.toml
.utoipa
is used to define OpenAPI objects.utoipa-redoc
is used to serve the ReDoc documentation UI.Code Refactoring
auth
,image
,post
) has been extracted from the..._web_routes.rs
files into their own dedicated files (e.g.,get_post_by_id_handler.rs
). This makes the code structure cleaner and simplifies adding documentation attributes to each handler.PostController
method fromget_full_post
toget_post_by_id
for a more RESTful-compliant naming convention.API Doc Annotation
#[derive(ToSchema)]
or#[derive(IntoParams)]
to all DTOs (Data Transfer Objects) so they can be recognized byutoipa
to generate the corresponding schemas.#[utoipa::path]
macro to all HTTP handler functions, describing the API's path, HTTP method, tags, summary, expected responses, and security settings.Doc Aggregation & Serving
..._api_doc.rs
file in each feature module to aggregate all API paths within that module.api_doc.rs
file in theserver
crate to merge the OpenAPI documents from all features, set global information (like title, version, and the OAuth2 security scheme), and serve the documentation page on the/redoc
route usingRedoc::with_url
.Package Changes
Screenshots
Reference
Resolves #103
Checklist
/improve
PR Code Suggestions ✨
No code suggestions found for the PR.
BLOG-103 feat: add API documentation with Utoipa and configure routesto BLOG-103 Add API documentation with Utoipa