Skip to content

Commit d154cd0

Browse files
authored
Add OpenAPI documentation for GET /api/v1/me/updates response payload (#10716)
1 parent fa291ff commit d154cd0

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

src/controllers/user/me.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use crate::auth::AuthCheck;
22
use axum::Json;
3-
use axum_extra::json;
4-
use axum_extra::response::ErasedJson;
53
use diesel::prelude::*;
64
use diesel_async::RunQueryDsl;
75
use futures_util::FutureExt;
@@ -69,15 +67,33 @@ pub async fn get_authenticated_user(app: AppState, req: Parts) -> AppResult<Json
6967
}))
7068
}
7169

70+
#[derive(Debug, Serialize, utoipa::ToSchema)]
71+
pub struct UpdatesResponse {
72+
/// The list of recent versions of crates that the authenticated user follows.
73+
pub versions: Vec<EncodableVersion>,
74+
75+
#[schema(inline)]
76+
pub meta: UpdatesResponseMeta,
77+
}
78+
79+
#[derive(Debug, Serialize, utoipa::ToSchema)]
80+
pub struct UpdatesResponseMeta {
81+
/// Whether there are more versions to be loaded.
82+
pub more: bool,
83+
}
84+
7285
/// List versions of crates that the authenticated user follows.
7386
#[utoipa::path(
7487
get,
7588
path = "/api/v1/me/updates",
7689
security(("cookie" = [])),
7790
tag = "versions",
78-
responses((status = 200, description = "Successful Response")),
91+
responses((status = 200, description = "Successful Response", body = inline(UpdatesResponse))),
7992
)]
80-
pub async fn get_authenticated_user_updates(app: AppState, req: Parts) -> AppResult<ErasedJson> {
93+
pub async fn get_authenticated_user_updates(
94+
app: AppState,
95+
req: Parts,
96+
) -> AppResult<Json<UpdatesResponse>> {
8197
let mut conn = app.db_read_prefer_primary().await?;
8298
let auth = AuthCheck::only_cookie().check(&req, &mut conn).await?;
8399

@@ -109,8 +125,8 @@ pub async fn get_authenticated_user_updates(app: AppState, req: Parts) -> AppRes
109125
})
110126
.collect::<Vec<_>>();
111127

112-
Ok(json!({
113-
"versions": versions,
114-
"meta": { "more": more },
128+
Ok(Json(UpdatesResponse {
129+
versions,
130+
meta: UpdatesResponseMeta { more },
115131
}))
116132
}

src/snapshots/crates_io__openapi__tests__openapi_snapshot.snap

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,6 +2531,38 @@ expression: response.json()
25312531
"operationId": "get_authenticated_user_updates",
25322532
"responses": {
25332533
"200": {
2534+
"content": {
2535+
"application/json": {
2536+
"schema": {
2537+
"properties": {
2538+
"meta": {
2539+
"properties": {
2540+
"more": {
2541+
"description": "Whether there are more versions to be loaded.",
2542+
"type": "boolean"
2543+
}
2544+
},
2545+
"required": [
2546+
"more"
2547+
],
2548+
"type": "object"
2549+
},
2550+
"versions": {
2551+
"description": "The list of recent versions of crates that the authenticated user follows.",
2552+
"items": {
2553+
"$ref": "#/components/schemas/Version"
2554+
},
2555+
"type": "array"
2556+
}
2557+
},
2558+
"required": [
2559+
"versions",
2560+
"meta"
2561+
],
2562+
"type": "object"
2563+
}
2564+
}
2565+
},
25342566
"description": "Successful Response"
25352567
}
25362568
},

0 commit comments

Comments
 (0)