Skip to content

Commit 3fec3e8

Browse files
committed
utoipa: Add annotations to /private/session endpoints
1 parent 4c0ebe9 commit 3fec3e8

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/controllers/user/session.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,14 @@ async fn find_user_by_gh_id(conn: &mut AsyncPgConnection, gh_id: i32) -> QueryRe
171171
.optional()
172172
}
173173

174-
/// Handles the `DELETE /api/private/session` route.
174+
/// End the current session.
175+
#[utoipa::path(
176+
delete,
177+
path = "/api/private/session",
178+
operation_id = "end_session",
179+
tag = "session",
180+
responses((status = 200, description = "Successful Response")),
181+
)]
175182
pub async fn logout(session: SessionExtension) -> Json<bool> {
176183
session.remove("user_id");
177184
Json(true)

src/router.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ pub fn build_axum_router(state: AppState) -> Router<()> {
6363
// Session management
6464
.routes(routes!(user::session::begin))
6565
.routes(routes!(user::session::authorize))
66+
.routes(routes!(user::session::logout))
6667
.split_for_parts();
6768

6869
let mut router = router
69-
.route("/api/private/session", delete(user::session::logout))
7070
// Metrics
7171
.route("/api/private/metrics/:kind", get(metrics::prometheus))
7272
// Crate ownership invitations management in the frontend

src/snapshots/crates_io__openapi__tests__openapi_snapshot.snap

+14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ snapshot_kind: text
2020
},
2121
"openapi": "3.1.0",
2222
"paths": {
23+
"/api/private/session": {
24+
"delete": {
25+
"operationId": "end_session",
26+
"responses": {
27+
"200": {
28+
"description": "Successful Response"
29+
}
30+
},
31+
"summary": "End the current session.",
32+
"tags": [
33+
"session"
34+
]
35+
}
36+
},
2337
"/api/private/session/authorize": {
2438
"get": {
2539
"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```",

0 commit comments

Comments
 (0)