Skip to content

Commit

Permalink
utoipa: Add annotations to /private/session endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Dec 13, 2024
1 parent 2cdcb42 commit 1826d06
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/controllers/user/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,14 @@ async fn find_user_by_gh_id(conn: &mut AsyncPgConnection, gh_id: i32) -> QueryRe
.optional()
}

/// Handles the `DELETE /api/private/session` route.
/// End the current session.
#[utoipa::path(
delete,
path = "/api/private/session",
operation_id = "end_session",
tag = "session",
responses((status = 200, description = "Successful Response")),
)]
pub async fn logout(session: SessionExtension) -> Json<bool> {
session.remove("user_id");
Json(true)
Expand Down
2 changes: 1 addition & 1 deletion src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ pub fn build_axum_router(state: AppState) -> Router<()> {
// Session management
.routes(routes!(user::session::begin))
.routes(routes!(user::session::authorize))
.routes(routes!(user::session::logout))
.split_for_parts();

let mut router = router
.route("/api/private/session", delete(user::session::logout))
// Metrics
.route("/api/private/metrics/:kind", get(metrics::prometheus))
// Crate ownership invitations management in the frontend
Expand Down
14 changes: 14 additions & 0 deletions src/snapshots/crates_io__openapi__tests__openapi_snapshot.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ snapshot_kind: text
},
"openapi": "3.1.0",
"paths": {
"/api/private/session": {
"delete": {
"operationId": "end_session",
"responses": {
"200": {
"description": "Successful Response"
}
},
"summary": "End the current session.",
"tags": [
"session"
]
}
},
"/api/private/session/authorize": {
"get": {
"description": "This route is called from the GitHub API OAuth flow after the user accepted or rejected\nthe data access permissions. It will check the `state` parameter and then call the GitHub API\nto exchange the temporary `code` for an API token. The API token is returned together with\nthe corresponding user information.\n\nsee <https://developer.github.com/v3/oauth/#github-redirects-back-to-your-site>\n\n## Query Parameters\n\n- `code` – temporary code received from the GitHub API **(Required)**\n- `state` – state parameter received from the GitHub API **(Required)**\n\n## Response Body Example\n\n```json\n{\n \"user\": {\n \"email\": \"[email protected]\",\n \"name\": \"Foo Bar\",\n \"login\": \"foobar\",\n \"avatar\": \"https://avatars.githubusercontent.com/u/1234\",\n \"url\": null\n }\n}\n```",
Expand Down

0 comments on commit 1826d06

Please sign in to comment.