Skip to content

Commit bb90b39

Browse files
committed
utoipa: Use CratePath and CrateVersionPath as params descriptions
1 parent 428dae5 commit bb90b39

12 files changed

+361
-2
lines changed

src/controllers/krate.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use axum::extract::{FromRequestParts, Path};
44
use crates_io_database::schema::crates;
55
use diesel::{OptionalExtension, QueryDsl};
66
use diesel_async::{AsyncPgConnection, RunQueryDsl};
7+
use utoipa::IntoParams;
78

89
pub mod delete;
910
pub mod downloads;
@@ -14,7 +15,8 @@ pub mod publish;
1415
pub mod search;
1516
pub mod versions;
1617

17-
#[derive(Deserialize, FromRequestParts)]
18+
#[derive(Deserialize, FromRequestParts, IntoParams)]
19+
#[into_params(parameter_in = Path)]
1820
#[from_request(via(Path))]
1921
pub struct CratePath {
2022
/// Name of the crate

src/controllers/krate/delete.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const AVAILABLE_AFTER: TimeDelta = TimeDelta::hours(24);
3030
#[utoipa::path(
3131
delete,
3232
path = "/api/v1/crates/{name}",
33+
params(CratePath),
3334
tag = "crates",
3435
responses((status = 200, description = "Successful Response")),
3536
)]

src/controllers/krate/downloads.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use std::cmp;
2323
#[utoipa::path(
2424
get,
2525
path = "/api/v1/crates/{name}/downloads",
26+
params(CratePath),
2627
tag = "crates",
2728
responses((status = 200, description = "Successful Response")),
2829
)]

src/controllers/krate/follow.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ async fn follow_target(
3333
#[utoipa::path(
3434
put,
3535
path = "/api/v1/crates/{name}/follow",
36+
params(CratePath),
3637
tag = "crates",
3738
responses((status = 200, description = "Successful Response")),
3839
)]
@@ -53,6 +54,7 @@ pub async fn follow_crate(app: AppState, path: CratePath, req: Parts) -> AppResu
5354
#[utoipa::path(
5455
delete,
5556
path = "/api/v1/crates/{name}/follow",
57+
params(CratePath),
5658
tag = "crates",
5759
responses((status = 200, description = "Successful Response")),
5860
)]
@@ -69,6 +71,7 @@ pub async fn unfollow_crate(app: AppState, path: CratePath, req: Parts) -> AppRe
6971
#[utoipa::path(
7072
get,
7173
path = "/api/v1/crates/{name}/following",
74+
params(CratePath),
7275
tag = "crates",
7376
responses((status = 200, description = "Successful Response")),
7477
)]

src/controllers/krate/metadata.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub async fn find_new_crate(app: AppState, req: Parts) -> AppResult<ErasedJson>
4646
#[utoipa::path(
4747
get,
4848
path = "/api/v1/crates/{name}",
49+
params(CratePath),
4950
tag = "crates",
5051
responses((status = 200, description = "Successful Response")),
5152
)]
@@ -248,6 +249,7 @@ impl FromStr for ShowIncludeMode {
248249
#[utoipa::path(
249250
get,
250251
path = "/api/v1/crates/{name}/{version}/readme",
252+
params(CrateVersionPath),
251253
tag = "versions",
252254
responses((status = 200, description = "Successful Response")),
253255
)]
@@ -264,6 +266,7 @@ pub async fn get_version_readme(app: AppState, path: CrateVersionPath, req: Part
264266
#[utoipa::path(
265267
get,
266268
path = "/api/v1/crates/{name}/reverse_dependencies",
269+
params(CratePath),
267270
tag = "crates",
268271
responses((status = 200, description = "Successful Response")),
269272
)]

src/controllers/krate/owners.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use secrecy::{ExposeSecret, SecretString};
2121
#[utoipa::path(
2222
get,
2323
path = "/api/v1/crates/{name}/owners",
24+
params(CratePath),
2425
tag = "owners",
2526
responses((status = 200, description = "Successful Response")),
2627
)]
@@ -43,6 +44,7 @@ pub async fn list_owners(state: AppState, path: CratePath) -> AppResult<ErasedJs
4344
#[utoipa::path(
4445
get,
4546
path = "/api/v1/crates/{name}/owner_team",
47+
params(CratePath),
4648
tag = "owners",
4749
responses((status = 200, description = "Successful Response")),
4850
)]
@@ -63,6 +65,7 @@ pub async fn get_team_owners(state: AppState, path: CratePath) -> AppResult<Eras
6365
#[utoipa::path(
6466
get,
6567
path = "/api/v1/crates/{name}/owner_user",
68+
params(CratePath),
6669
tag = "owners",
6770
responses((status = 200, description = "Successful Response")),
6871
)]
@@ -84,6 +87,7 @@ pub async fn get_user_owners(state: AppState, path: CratePath) -> AppResult<Eras
8487
#[utoipa::path(
8588
put,
8689
path = "/api/v1/crates/{name}/owners",
90+
params(CratePath),
8791
tag = "owners",
8892
responses((status = 200, description = "Successful Response")),
8993
)]
@@ -100,6 +104,7 @@ pub async fn add_owners(
100104
#[utoipa::path(
101105
delete,
102106
path = "/api/v1/crates/{name}/owners",
107+
params(CratePath),
103108
tag = "owners",
104109
responses((status = 200, description = "Successful Response")),
105110
)]

src/controllers/krate/versions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::views::EncodableVersion;
2424
#[utoipa::path(
2525
get,
2626
path = "/api/v1/crates/{name}/versions",
27+
params(CratePath),
2728
tag = "versions",
2829
responses((status = 200, description = "Successful Response")),
2930
)]

src/controllers/version.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ pub mod yank;
44

55
use axum::extract::{FromRequestParts, Path};
66
use diesel_async::AsyncPgConnection;
7+
use utoipa::IntoParams;
78

89
use crate::models::{Crate, Version};
910
use crate::util::errors::{crate_not_found, AppResult};
1011

11-
#[derive(Deserialize, FromRequestParts)]
12+
#[derive(Deserialize, FromRequestParts, IntoParams)]
13+
#[into_params(parameter_in = Path)]
1214
#[from_request(via(Path))]
1315
pub struct CrateVersionPath {
1416
/// Name of the crate
1517
pub name: String,
1618
/// Version number
19+
#[param(example = "1.0.0")]
1720
pub version: String,
1821
}
1922

src/controllers/version/downloads.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use http::request::Parts;
2323
#[utoipa::path(
2424
get,
2525
path = "/api/v1/crates/{name}/{version}/download",
26+
params(CrateVersionPath),
2627
tag = "versions",
2728
responses((status = 200, description = "Successful Response")),
2829
)]
@@ -46,6 +47,7 @@ pub async fn download_version(
4647
#[utoipa::path(
4748
get,
4849
path = "/api/v1/crates/{name}/{version}/downloads",
50+
params(CrateVersionPath),
4951
tag = "versions",
5052
responses((status = 200, description = "Successful Response")),
5153
)]

src/controllers/version/metadata.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub struct VersionUpdateRequest {
4949
#[utoipa::path(
5050
get,
5151
path = "/api/v1/crates/{name}/{version}/dependencies",
52+
params(CrateVersionPath),
5253
tag = "versions",
5354
responses((status = 200, description = "Successful Response")),
5455
)]
@@ -83,6 +84,7 @@ pub async fn get_version_dependencies(
8384
#[utoipa::path(
8485
get,
8586
path = "/api/v1/crates/{name}/{version}/authors",
87+
params(CrateVersionPath),
8688
tag = "versions",
8789
responses((status = 200, description = "Successful Response")),
8890
)]
@@ -98,6 +100,7 @@ pub async fn get_version_authors() -> ErasedJson {
98100
#[utoipa::path(
99101
get,
100102
path = "/api/v1/crates/{name}/{version}",
103+
params(CrateVersionPath),
101104
tag = "versions",
102105
responses((status = 200, description = "Successful Response")),
103106
)]
@@ -121,6 +124,7 @@ pub async fn find_version(state: AppState, path: CrateVersionPath) -> AppResult<
121124
#[utoipa::path(
122125
patch,
123126
path = "/api/v1/crates/{name}/{version}",
127+
params(CrateVersionPath),
124128
tag = "versions",
125129
responses((status = 200, description = "Successful Response")),
126130
)]

src/controllers/version/yank.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use http::request::Parts;
2323
#[utoipa::path(
2424
delete,
2525
path = "/api/v1/crates/{name}/{version}/yank",
26+
params(CrateVersionPath),
2627
tag = "versions",
2728
responses((status = 200, description = "Successful Response")),
2829
)]
@@ -38,6 +39,7 @@ pub async fn yank_version(
3839
#[utoipa::path(
3940
put,
4041
path = "/api/v1/crates/{name}/{version}/unyank",
42+
params(CrateVersionPath),
4143
tag = "versions",
4244
responses((status = 200, description = "Successful Response")),
4345
)]

0 commit comments

Comments
 (0)