Skip to content

Commit 868d2da

Browse files
committed
utoipa: Add annotations to /tokens/current endpoints
1 parent 2730095 commit 868d2da

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/controllers/token.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,17 @@ pub async fn revoke(app: AppState, Path(id): Path<i32>, req: Parts) -> AppResult
220220
Ok(json!({}))
221221
}
222222

223-
/// Handles the `DELETE /tokens/current` route.
223+
/// Revoke the current API token.
224+
///
225+
/// This endpoint revokes the API token that is used to authenticate
226+
/// the request.
227+
#[utoipa::path(
228+
delete,
229+
path = "/api/v1/tokens/current",
230+
operation_id = "revoke_current_api_token",
231+
tag = "api_tokens",
232+
responses((status = 200, description = "Successful Response")),
233+
)]
224234
pub async fn revoke_current(app: AppState, req: Parts) -> AppResult<Response> {
225235
let mut conn = app.db_write().await?;
226236
let auth = AuthCheck::default().check(&req, &mut conn).await?;

src/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ pub fn build_axum_router(state: AppState) -> Router<()> {
5151
.routes(routes!(user::me::updates))
5252
.routes(routes!(token::list, token::new))
5353
.routes(routes!(token::show, token::revoke))
54+
.routes(routes!(token::revoke_current))
5455
.split_for_parts();
5556

5657
let mut router = router
57-
.route("/api/v1/tokens/current", delete(token::revoke_current))
5858
.route(
5959
"/api/v1/me/crate_owner_invitations",
6060
get(crate_owner_invitation::list),

src/snapshots/crates_io__openapi__tests__openapi_snapshot.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,21 @@ snapshot_kind: text
534534
]
535535
}
536536
},
537+
"/api/v1/tokens/current": {
538+
"delete": {
539+
"description": "This endpoint revokes the API token that is used to authenticate\nthe request.",
540+
"operationId": "revoke_current_api_token",
541+
"responses": {
542+
"200": {
543+
"description": "Successful Response"
544+
}
545+
},
546+
"summary": "Revoke the current API token.",
547+
"tags": [
548+
"api_tokens"
549+
]
550+
}
551+
},
537552
"/api/v1/users/{id}/stats": {
538553
"get": {
539554
"description": "This currently only returns the total number of downloads for crates owned\nby the user.",

0 commit comments

Comments
 (0)