Skip to content

Commit 0fc539c

Browse files
committed
Improve OpenAPI documentation for GET /api/v1/site_metadata endpoint
1 parent 5915366 commit 0fc539c

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

src/controllers/site_metadata.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
use crate::app::AppState;
2+
use axum::Json;
23
use axum::response::IntoResponse;
3-
use axum_extra::json;
4+
5+
#[derive(Debug, Serialize, utoipa::ToSchema)]
6+
pub struct MetadataResponse<'a> {
7+
/// The SHA1 of the currently deployed commit.
8+
#[schema(example = "0aebe2cdfacae1229b93853b1c58f9352195f081")]
9+
pub deployed_sha: &'a str,
10+
11+
/// The SHA1 of the currently deployed commit.
12+
#[schema(example = "0aebe2cdfacae1229b93853b1c58f9352195f081")]
13+
pub commit: &'a str,
14+
15+
/// Whether the crates.io service is in read-only mode.
16+
pub read_only: bool,
17+
}
418

519
/// Get crates.io metadata.
620
///
@@ -10,17 +24,18 @@ use axum_extra::json;
1024
get,
1125
path = "/api/v1/site_metadata",
1226
tag = "other",
13-
responses((status = 200, description = "Successful Response")),
27+
responses((status = 200, description = "Successful Response", body = inline(MetadataResponse<'_>))),
1428
)]
1529
pub async fn get_site_metadata(state: AppState) -> impl IntoResponse {
1630
let read_only = state.config.db.are_all_read_only();
1731

1832
let deployed_sha =
1933
dotenvy::var("HEROKU_SLUG_COMMIT").unwrap_or_else(|_| String::from("unknown"));
2034

21-
json!({
22-
"deployed_sha": &deployed_sha[..],
23-
"commit": &deployed_sha[..],
24-
"read_only": read_only,
35+
Json(MetadataResponse {
36+
deployed_sha: &deployed_sha,
37+
commit: &deployed_sha,
38+
read_only,
2539
})
40+
.into_response()
2641
}

src/snapshots/crates_io__openapi__tests__openapi_snapshot.snap

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3661,6 +3661,34 @@ expression: response.json()
36613661
"operationId": "get_site_metadata",
36623662
"responses": {
36633663
"200": {
3664+
"content": {
3665+
"application/json": {
3666+
"schema": {
3667+
"properties": {
3668+
"commit": {
3669+
"description": "The SHA1 of the currently deployed commit.",
3670+
"example": "0aebe2cdfacae1229b93853b1c58f9352195f081",
3671+
"type": "string"
3672+
},
3673+
"deployed_sha": {
3674+
"description": "The SHA1 of the currently deployed commit.",
3675+
"example": "0aebe2cdfacae1229b93853b1c58f9352195f081",
3676+
"type": "string"
3677+
},
3678+
"read_only": {
3679+
"description": "Whether the crates.io service is in read-only mode.",
3680+
"type": "boolean"
3681+
}
3682+
},
3683+
"required": [
3684+
"deployed_sha",
3685+
"commit",
3686+
"read_only"
3687+
],
3688+
"type": "object"
3689+
}
3690+
}
3691+
},
36643692
"description": "Successful Response"
36653693
}
36663694
},

0 commit comments

Comments
 (0)