Skip to content

Commit de89f96

Browse files
committed
Improve OpenAPI documentation for PATCH /api/v1/crates/{name}/{version} endpoint
1 parent 316fa1b commit de89f96

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/controllers/version/update.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ use crate::util::errors::{AppResult, bad_request, custom};
1010
use crate::views::EncodableVersion;
1111
use crate::worker::jobs::{SyncToGitIndex, SyncToSparseIndex, UpdateDefaultVersion};
1212
use axum::Json;
13-
use axum_extra::json;
14-
use axum_extra::response::ErasedJson;
1513
use crates_io_worker::BackgroundJob;
1614
use diesel::prelude::*;
1715
use diesel_async::{AsyncPgConnection, RunQueryDsl};
@@ -29,6 +27,11 @@ pub struct VersionUpdateRequest {
2927
version: VersionUpdate,
3028
}
3129

30+
#[derive(Debug, Serialize, utoipa::ToSchema)]
31+
pub struct UpdateResponse {
32+
pub version: EncodableVersion,
33+
}
34+
3235
/// Update a crate version.
3336
///
3437
/// This endpoint allows updating the `yanked` state of a version, including a yank message.
@@ -41,14 +44,14 @@ pub struct VersionUpdateRequest {
4144
("cookie" = []),
4245
),
4346
tag = "versions",
44-
responses((status = 200, description = "Successful Response")),
47+
responses((status = 200, description = "Successful Response", body = inline(UpdateResponse))),
4548
)]
4649
pub async fn update_version(
4750
state: AppState,
4851
path: CrateVersionPath,
4952
req: Parts,
5053
Json(update_request): Json<VersionUpdateRequest>,
51-
) -> AppResult<ErasedJson> {
54+
) -> AppResult<Json<UpdateResponse>> {
5255
let mut conn = state.db_write().await?;
5356
let (mut version, krate) = path.load_version_and_crate(&mut conn).await?;
5457
validate_yank_update(&update_request.version, &version)?;
@@ -74,8 +77,8 @@ pub async fn update_version(
7477
VersionOwnerAction::by_version(&mut conn, &version),
7578
version.published_by(&mut conn),
7679
)?;
77-
let updated_version = EncodableVersion::from(version, &krate.name, published_by, actions);
78-
Ok(json!({ "version": updated_version }))
80+
let version = EncodableVersion::from(version, &krate.name, published_by, actions);
81+
Ok(Json(UpdateResponse { version }))
7982
}
8083

8184
fn validate_yank_update(update_data: &VersionUpdate, version: &Version) -> AppResult<()> {

src/snapshots/crates_io__openapi__tests__openapi_snapshot.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,21 @@ expression: response.json()
18561856
],
18571857
"responses": {
18581858
"200": {
1859+
"content": {
1860+
"application/json": {
1861+
"schema": {
1862+
"properties": {
1863+
"version": {
1864+
"$ref": "#/components/schemas/Version"
1865+
}
1866+
},
1867+
"required": [
1868+
"version"
1869+
],
1870+
"type": "object"
1871+
}
1872+
}
1873+
},
18591874
"description": "Successful Response"
18601875
}
18611876
},

0 commit comments

Comments
 (0)