Skip to content

Commit b03579c

Browse files
committed
utoipa: Add annotations to /private/session/begin endpoints
1 parent d7b2d4e commit b03579c

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/controllers/user/session.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::util::errors::{bad_request, server_error, AppResult};
1919
use crate::views::EncodableMe;
2020
use crates_io_github::GithubUser;
2121

22-
/// Handles the `GET /api/private/session/begin` route.
22+
/// Begin authentication flow.
2323
///
2424
/// This route will return an authorization URL for the GitHub OAuth flow including the crates.io
2525
/// `client_id` and a randomly generated `state` secret.
@@ -34,6 +34,13 @@ use crates_io_github::GithubUser;
3434
/// "url": "https://github.com/login/oauth/authorize?client_id=...&state=...&scope=read%3Aorg"
3535
/// }
3636
/// ```
37+
#[utoipa::path(
38+
get,
39+
path = "/api/private/session/begin",
40+
operation_id = "begin_session",
41+
tag = "session",
42+
responses((status = 200, description = "Successful Response")),
43+
)]
3744
pub async fn begin(app: AppState, session: SessionExtension) -> ErasedJson {
3845
let (url, state) = app
3946
.github_oauth

src/router.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ pub fn build_axum_router(state: AppState) -> Router<()> {
6060
.routes(routes!(user::me::confirm_user_email))
6161
.routes(routes!(user::resend::regenerate_token_and_send))
6262
.routes(routes!(site_metadata::show_deployed_sha))
63+
// Session management
64+
.routes(routes!(user::session::begin))
6365
.split_for_parts();
6466

6567
let mut router = router
66-
// Session management
67-
.route("/api/private/session/begin", get(user::session::begin))
6868
.route(
6969
"/api/private/session/authorize",
7070
get(user::session::authorize),

src/snapshots/crates_io__openapi__tests__openapi_snapshot.snap

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ snapshot_kind: text
2020
},
2121
"openapi": "3.1.0",
2222
"paths": {
23+
"/api/private/session/begin": {
24+
"get": {
25+
"description": "This route will return an authorization URL for the GitHub OAuth flow including the crates.io\n`client_id` and a randomly generated `state` secret.\n\nsee <https://developer.github.com/v3/oauth/#redirect-users-to-request-github-access>\n\n## Response Body Example\n\n```json\n{\n \"state\": \"b84a63c4ea3fcb4ac84\",\n \"url\": \"https://github.com/login/oauth/authorize?client_id=...&state=...&scope=read%3Aorg\"\n}\n```",
26+
"operationId": "begin_session",
27+
"responses": {
28+
"200": {
29+
"description": "Successful Response"
30+
}
31+
},
32+
"summary": "Begin authentication flow.",
33+
"tags": [
34+
"session"
35+
]
36+
}
37+
},
2338
"/api/v1/categories": {
2439
"get": {
2540
"operationId": "list_categories",

0 commit comments

Comments
 (0)