Skip to content

Commit 6f16abf

Browse files
committed
Improve OpenAPI documentation for GET /api/v1/me/tokens/{id} endpoint
1 parent d3dfab5 commit 6f16abf

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/controllers/token.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ pub async fn create_api_token(
194194
Ok(Json(CreateResponse { api_token }))
195195
}
196196

197+
#[derive(Debug, Serialize, utoipa::ToSchema)]
198+
pub struct GetResponse {
199+
pub api_token: ApiToken,
200+
}
201+
197202
/// Find API token by id.
198203
#[utoipa::path(
199204
get,
@@ -206,23 +211,23 @@ pub async fn create_api_token(
206211
("cookie" = []),
207212
),
208213
tag = "api_tokens",
209-
responses((status = 200, description = "Successful Response")),
214+
responses((status = 200, description = "Successful Response", body = inline(GetResponse))),
210215
)]
211216
pub async fn find_api_token(
212217
app: AppState,
213218
Path(id): Path<i32>,
214219
req: Parts,
215-
) -> AppResult<ErasedJson> {
220+
) -> AppResult<Json<GetResponse>> {
216221
let mut conn = app.db_write().await?;
217222
let auth = AuthCheck::default().check(&req, &mut conn).await?;
218223
let user = auth.user();
219-
let token = ApiToken::belonging_to(user)
224+
let api_token = ApiToken::belonging_to(user)
220225
.find(id)
221226
.select(ApiToken::as_select())
222227
.first(&mut conn)
223228
.await?;
224229

225-
Ok(json!({ "api_token": token }))
230+
Ok(Json(GetResponse { api_token }))
226231
}
227232

228233
/// Revoke API token.

src/snapshots/crates_io__openapi__tests__openapi_snapshot.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3765,6 +3765,21 @@ expression: response.json()
37653765
],
37663766
"responses": {
37673767
"200": {
3768+
"content": {
3769+
"application/json": {
3770+
"schema": {
3771+
"properties": {
3772+
"api_token": {
3773+
"$ref": "#/components/schemas/ApiToken"
3774+
}
3775+
},
3776+
"required": [
3777+
"api_token"
3778+
],
3779+
"type": "object"
3780+
}
3781+
}
3782+
},
37683783
"description": "Successful Response"
37693784
}
37703785
},

0 commit comments

Comments
 (0)