Skip to content

Commit 4c0ebe9

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

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/controllers/user/session.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub struct AuthorizeQuery {
6161
state: CsrfToken,
6262
}
6363

64-
/// Handles the `GET /api/private/session/authorize` route.
64+
/// Complete authentication flow.
6565
///
6666
/// This route is called from the GitHub API OAuth flow after the user accepted or rejected
6767
/// the data access permissions. It will check the `state` parameter and then call the GitHub API
@@ -79,7 +79,6 @@ pub struct AuthorizeQuery {
7979
///
8080
/// ```json
8181
/// {
82-
/// "api_token": "b84a63c4ea3fcb4ac84",
8382
/// "user": {
8483
/// "email": "[email protected]",
8584
/// "name": "Foo Bar",
@@ -89,6 +88,13 @@ pub struct AuthorizeQuery {
8988
/// }
9089
/// }
9190
/// ```
91+
#[utoipa::path(
92+
get,
93+
path = "/api/private/session/authorize",
94+
operation_id = "authorize_session",
95+
tag = "session",
96+
responses((status = 200, description = "Successful Response")),
97+
)]
9298
pub async fn authorize(
9399
query: AuthorizeQuery,
94100
app: AppState,

src/router.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,10 @@ pub fn build_axum_router(state: AppState) -> Router<()> {
6262
.routes(routes!(site_metadata::show_deployed_sha))
6363
// Session management
6464
.routes(routes!(user::session::begin))
65+
.routes(routes!(user::session::authorize))
6566
.split_for_parts();
6667

6768
let mut router = router
68-
.route(
69-
"/api/private/session/authorize",
70-
get(user::session::authorize),
71-
)
7269
.route("/api/private/session", delete(user::session::logout))
7370
// Metrics
7471
.route("/api/private/metrics/:kind", get(metrics::prometheus))

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/authorize": {
24+
"get": {
25+
"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```",
26+
"operationId": "authorize_session",
27+
"responses": {
28+
"200": {
29+
"description": "Successful Response"
30+
}
31+
},
32+
"summary": "Complete authentication flow.",
33+
"tags": [
34+
"session"
35+
]
36+
}
37+
},
2338
"/api/private/session/begin": {
2439
"get": {
2540
"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```",

0 commit comments

Comments
 (0)