Skip to content

Commit c7a329b

Browse files
committed
Add OpenAPI documentation for GET /api/v1/me/crate_owner_invitations response payload
1 parent 44d9a8b commit c7a329b

File tree

3 files changed

+111
-7
lines changed

3 files changed

+111
-7
lines changed

src/controllers/crate_owner_invitation.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,27 @@ use http::request::Parts;
2626
use indexmap::IndexMap;
2727
use std::collections::{HashMap, HashSet};
2828

29+
#[derive(Serialize, utoipa::ToSchema)]
30+
pub struct LegacyListResponse {
31+
/// The list of crate owner invitations.
32+
crate_owner_invitations: Vec<EncodableCrateOwnerInvitationV1>,
33+
34+
/// The list of users referenced in the crate owner invitations.
35+
users: Vec<EncodablePublicUser>,
36+
}
37+
2938
/// List all crate owner invitations for the authenticated user.
3039
#[utoipa::path(
3140
get,
3241
path = "/api/v1/me/crate_owner_invitations",
3342
security(("cookie" = [])),
3443
tag = "owners",
35-
responses((status = 200, description = "Successful Response")),
44+
responses((status = 200, description = "Successful Response", body = inline(LegacyListResponse))),
3645
)]
3746
pub async fn list_crate_owner_invitations_for_user(
3847
app: AppState,
3948
req: Parts,
40-
) -> AppResult<ErasedJson> {
49+
) -> AppResult<Json<LegacyListResponse>> {
4150
let mut conn = app.db_read().await?;
4251
let auth = AuthCheck::only_cookie().check(&req, &mut conn).await?;
4352

@@ -68,9 +77,9 @@ pub async fn list_crate_owner_invitations_for_user(
6877
})
6978
.collect::<AppResult<Vec<EncodableCrateOwnerInvitationV1>>>()?;
7079

71-
Ok(json!({
72-
"crate_owner_invitations": crate_owner_invitations,
73-
"users": users,
80+
Ok(Json(LegacyListResponse {
81+
crate_owner_invitations,
82+
users,
7483
}))
7584
}
7685

src/snapshots/crates_io__openapi__tests__openapi_snapshot.snap

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,60 @@ expression: response.json()
153153
],
154154
"type": "object"
155155
},
156+
"LegacyCrateOwnerInvitation": {
157+
"properties": {
158+
"crate_id": {
159+
"description": "The ID of the crate that the user was invited to be an owner of.",
160+
"example": 123,
161+
"format": "int32",
162+
"type": "integer"
163+
},
164+
"crate_name": {
165+
"description": "The name of the crate that the user was invited to be an owner of.",
166+
"example": "serde",
167+
"type": "string"
168+
},
169+
"created_at": {
170+
"description": "The date and time this invitation was created.",
171+
"example": "2019-12-13T13:46:41Z",
172+
"format": "date-time",
173+
"type": "string"
174+
},
175+
"expires_at": {
176+
"description": "The date and time this invitation will expire.",
177+
"example": "2020-01-13T13:46:41Z",
178+
"format": "date-time",
179+
"type": "string"
180+
},
181+
"invited_by_username": {
182+
"description": "The username of the user who sent the invitation.",
183+
"example": "ghost",
184+
"type": "string"
185+
},
186+
"invitee_id": {
187+
"description": "The ID of the user who was invited to be a crate owner.",
188+
"example": 42,
189+
"format": "int32",
190+
"type": "integer"
191+
},
192+
"inviter_id": {
193+
"description": "The ID of the user who sent the invitation.",
194+
"example": 3,
195+
"format": "int32",
196+
"type": "integer"
197+
}
198+
},
199+
"required": [
200+
"invitee_id",
201+
"inviter_id",
202+
"invited_by_username",
203+
"crate_name",
204+
"crate_id",
205+
"created_at",
206+
"expires_at"
207+
],
208+
"type": "object"
209+
},
156210
"Slug": {
157211
"properties": {
158212
"description": {
@@ -1764,6 +1818,33 @@ expression: response.json()
17641818
"operationId": "list_crate_owner_invitations_for_user",
17651819
"responses": {
17661820
"200": {
1821+
"content": {
1822+
"application/json": {
1823+
"schema": {
1824+
"properties": {
1825+
"crate_owner_invitations": {
1826+
"description": "The list of crate owner invitations.",
1827+
"items": {
1828+
"$ref": "#/components/schemas/LegacyCrateOwnerInvitation"
1829+
},
1830+
"type": "array"
1831+
},
1832+
"users": {
1833+
"description": "The list of users referenced in the crate owner invitations.",
1834+
"items": {
1835+
"$ref": "#/components/schemas/User"
1836+
},
1837+
"type": "array"
1838+
}
1839+
},
1840+
"required": [
1841+
"crate_owner_invitations",
1842+
"users"
1843+
],
1844+
"type": "object"
1845+
}
1846+
}
1847+
},
17671848
"description": "Successful Response"
17681849
}
17691850
},

src/views.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,29 @@ impl From<Category> for EncodableCategory {
7979
}
8080
}
8181

82-
/// The serialization format for the `CrateOwnerInvitation` model.
83-
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)]
82+
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, utoipa::ToSchema)]
83+
#[schema(as = LegacyCrateOwnerInvitation)]
8484
pub struct EncodableCrateOwnerInvitationV1 {
85+
/// The ID of the user who was invited to be a crate owner.
86+
#[schema(example = 42)]
8587
pub invitee_id: i32,
88+
/// The ID of the user who sent the invitation.
89+
#[schema(example = 3)]
8690
pub inviter_id: i32,
91+
/// The username of the user who sent the invitation.
92+
#[schema(example = "ghost")]
8793
pub invited_by_username: String,
94+
/// The name of the crate that the user was invited to be an owner of.
95+
#[schema(example = "serde")]
8896
pub crate_name: String,
97+
/// The ID of the crate that the user was invited to be an owner of.
98+
#[schema(example = 123)]
8999
pub crate_id: i32,
100+
/// The date and time this invitation was created.
101+
#[schema(example = "2019-12-13T13:46:41Z")]
90102
pub created_at: DateTime<Utc>,
103+
/// The date and time this invitation will expire.
104+
#[schema(example = "2020-01-13T13:46:41Z")]
91105
pub expires_at: DateTime<Utc>,
92106
}
93107

0 commit comments

Comments
 (0)