Skip to content

Commit 316fa1b

Browse files
committed
Improve OpenAPI documentation for GET /api/v1/crates/{name}/{version}/download endpoint
1 parent 9c6a86d commit 316fa1b

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/controllers/version/downloads.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ use diesel::prelude::*;
1818
use diesel_async::RunQueryDsl;
1919
use http::request::Parts;
2020

21+
#[derive(Debug, Serialize, utoipa::ToSchema)]
22+
pub struct UrlResponse {
23+
/// The URL to the crate file.
24+
#[schema(example = "https://static.crates.io/crates/serde/serde-1.0.0.crate")]
25+
pub url: String,
26+
}
27+
2128
/// Download a crate version.
2229
///
2330
/// This returns a URL to the location where the crate is stored.
@@ -26,7 +33,10 @@ use http::request::Parts;
2633
path = "/api/v1/crates/{name}/{version}/download",
2734
params(CrateVersionPath),
2835
tag = "versions",
29-
responses((status = 200, description = "Successful Response")),
36+
responses(
37+
(status = 302, description = "Successful Response (default)", headers(("location" = String, description = "The URL to the crate file."))),
38+
(status = 200, description = "Successful Response (for `content-type: application/json`)", body = inline(UrlResponse)),
39+
),
3040
)]
3141
pub async fn download_version(
3242
app: AppState,

src/snapshots/crates_io__openapi__tests__openapi_snapshot.snap

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1991,7 +1991,35 @@ expression: response.json()
19911991
],
19921992
"responses": {
19931993
"200": {
1994-
"description": "Successful Response"
1994+
"content": {
1995+
"application/json": {
1996+
"schema": {
1997+
"properties": {
1998+
"url": {
1999+
"description": "The URL to the crate file.",
2000+
"example": "https://static.crates.io/crates/serde/serde-1.0.0.crate",
2001+
"type": "string"
2002+
}
2003+
},
2004+
"required": [
2005+
"url"
2006+
],
2007+
"type": "object"
2008+
}
2009+
}
2010+
},
2011+
"description": "Successful Response (for `content-type: application/json`)"
2012+
},
2013+
"302": {
2014+
"description": "Successful Response (default)",
2015+
"headers": {
2016+
"location": {
2017+
"description": "The URL to the crate file.",
2018+
"schema": {
2019+
"type": "string"
2020+
}
2021+
}
2022+
}
19952023
}
19962024
},
19972025
"summary": "Download a crate version.",

0 commit comments

Comments
 (0)