Skip to content

Commit e84c97e

Browse files
committed
feat: 为 openapi 添加 example
1 parent 851b874 commit e84c97e

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

src/models/curseforge/requests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl Display for SearchQuery {
4848
#[derive(Serialize, Deserialize, Debug, ToSchema)]
4949
pub struct ModsBody {
5050
#[serde(rename = "modIds")]
51+
#[schema(default = "[238222]")]
5152
pub mod_ids: Vec<i32>,
5253
#[serde(rename = "filterPcOnly")]
5354
pub filter_pc_only: Option<bool>,
@@ -67,19 +68,23 @@ pub struct ModFilesQuery {
6768
#[derive(Serialize, Deserialize, Debug, ToSchema)]
6869
pub struct FileIdsBody {
6970
#[serde(rename = "fileIds")]
71+
#[schema(default = "[6614392]")]
7072
pub file_ids: Vec<i32>,
7173
}
7274

7375
#[derive(Serialize, Deserialize, Debug, ToSchema)]
7476
pub struct FingerprintsBody {
77+
#[schema(default = "[510490952]")]
7578
pub fingerprints: Vec<i64>,
7679
}
7780

7881
#[derive(Serialize, Deserialize, Debug, ToSchema)]
7982
pub struct CategoriesQuery {
8083
#[serde(rename = "gameId")]
84+
#[schema(default = 432)]
8185
pub game_id: i32,
8286
#[serde(rename = "classId")]
87+
#[schema(default = 6)]
8388
pub class_id: Option<i32>,
8489
#[serde(rename = "classOnly")]
8590
pub class_only: Option<bool>,

src/models/modrinth/requests.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,29 @@ impl Display for SearchQuery {
2323

2424
#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
2525
pub struct HashesQuery {
26+
#[schema(default = "[\"d67e66ea4bb2409997b636dae4203d33764cdcc8\"]")]
2627
pub hashes: Vec<String>,
28+
#[schema(default = "sha1")]
2729
pub algorithm: String,
2830
}
2931

3032
#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
3133
pub struct UpdateItems {
34+
#[schema(default = "[\"fabric\"]")]
3235
pub loaders: Vec<String>,
36+
#[schema(default = "[\"1.16.5\"]")]
3337
pub game_versions: Vec<String>,
3438
}
3539

3640
#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
3741
pub struct MultiUpdateItems {
42+
#[schema(default = "[\"d67e66ea4bb2409997b636dae4203d33764cdcc8\"]")]
3843
pub hashes: Vec<String>,
44+
#[schema(default = "sha1")]
3945
pub algorithm: String,
46+
#[schema(default = "[\"fabric\"]")]
4047
pub loaders: Vec<String>,
48+
#[schema(default = "[\"1.16.5\"]")]
4149
pub game_versions: Vec<String>,
4250
}
4351

@@ -48,6 +56,7 @@ pub struct ProjectIds {
4856

4957
#[derive(Debug, Serialize, Deserialize, Clone, ToSchema)]
5058
pub struct AlgorithmItems {
59+
#[schema(default = "[\"sha512\"]")]
5160
pub algorithm: String,
5261
}
5362

src/routes/curseforge.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async fn search_mods_cached(
128128
get,
129129
path = "/curseforge/v1/mods/{mod_id}",
130130
params(
131-
("mod_id" = i32, Path, description = "ID of the mod to retrieve")
131+
("mod_id" = i32, Path, description = "ID of the mod to retrieve", example = 238222)
132132
),
133133
responses(
134134
(status = 200, description = "Mod found", body = ModResponse),
@@ -187,11 +187,11 @@ async fn get_mods(
187187
get,
188188
path = "/curseforge/v1/mods/{mod_id}/files",
189189
params(
190-
("mod_id" = i32, Path, description = "ID of the mod to retrieve files for"),
190+
("mod_id" = i32, Path, description = "ID of the mod to retrieve files for", example = 238222),
191191
("gameVersion" = Option<String>, Query, description = "Game version filter (optional)"),
192192
("modLoaderType" = Option<String>, Query, description = "Mod loader type filter (optional)"),
193-
("index" = Option<i32>, Query, description = "Index for pagination (optional)"),
194-
("pageSize" = Option<i32>, Query, description = "Page size for pagination (optional)")
193+
("index" = Option<i32>, Query, description = "Index for pagination (optional)", example = 0),
194+
("pageSize" = Option<i32>, Query, description = "Page size for pagination (optional)", example = 50)
195195
),
196196
responses(
197197
(status = 200, description = "Files found", body = Vec<FileResponse>),

src/routes/modrinth.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub async fn root() -> impl Responder {
4949
path = "/modrinth/v2/search",
5050
params(
5151
("query" = Option<String>, Query, description = "Search query", example = "sodium"),
52-
("facets" = Option<String>, Query, description = "Facets to filter results", example = "[['categories:forge'],['versions:1.17.1'],['project_type:mod'],['license:mit']]"),
52+
("facets" = Option<String>, Query, description = "Facets to filter results", example = "[[\"categories:forge\"],[\"versions:1.17.1\"],[\"project_type:mod\"],[\"license:mit\"]]"),
5353
("offset" = Option<i32>, Query, description = "Offset for pagination", example = "0"),
5454
("limit" = Option<i32>, Query, description = "Limit for pagination", example = "10"),
5555
("index" = Option<String>, Query, description = "Index to sort", example = "relevance")
@@ -123,7 +123,7 @@ pub async fn search_cached(
123123
get,
124124
path = "/modrinth/v2/project/{project_id}",
125125
params(
126-
("project_id" = String, Path, description = "ID of the game to filter project"),
126+
("project_id" = String, Path, description = "ID of the game to filter project", example = "sodium"),
127127
),
128128
responses(
129129
(status = 200, description = "Project found", body = Project)
@@ -147,7 +147,7 @@ pub async fn get_project(
147147
get,
148148
path = "/modrinth/v2/projects",
149149
params(
150-
("ids" = String, Query, description = "The IDs and/or slugs of the projects", example = "['AABBCCDD', 'EEFFGGHH]'")
150+
("ids" = String, Query, description = "The IDs and/or slugs of the projects", example = "[\"sodium\", \"fabric-api\"]")
151151
),
152152
responses(
153153
(status = 200, description = "Projects Found", body = Vec<Project>),
@@ -177,7 +177,7 @@ pub async fn get_projects(
177177
get,
178178
path = "/modrinth/v2/project/{project_id}/version",
179179
params(
180-
("project_id" = String, Path, description = "ID or slug of the project")
180+
("project_id" = String, Path, description = "ID or slug of the project", example = "sodium")
181181
),
182182
responses(
183183
(status = 200, description = "Project versions found", body = Vec<Version>)
@@ -218,7 +218,7 @@ pub async fn get_project_versions(
218218
get,
219219
path = "/modrinth/v2/version/{version_id}",
220220
params(
221-
("version_id" = String, Path, description = "ID of the version")
221+
("version_id" = String, Path, description = "ID of the version", example = "ygf8cVZg")
222222
),
223223
responses(
224224
(status = 200, description = "Version found", body = Version)
@@ -242,7 +242,7 @@ pub async fn get_version(
242242
get,
243243
path = "/modrinth/v2/versions",
244244
params(
245-
("ids" = String, Query, description = "The IDs of the versions", example = "['AABBCCDD', 'EEFFGGHH]'")
245+
("ids" = String, Query, description = "The IDs of the versions", example = "[\"RncWhTxD\", \"ygf8cVZg\"]")
246246
),
247247
responses(
248248
(status = 200, description = "Versions found", body = Vec<Version>)
@@ -272,8 +272,8 @@ pub async fn get_versions(
272272
get,
273273
path = "/modrinth/v2/version_file/{hash}",
274274
params(
275-
("hash" = String, Path, description = "Hash of the file, sha1 or sha512"),
276-
("algorithm" = String, Query, description = "Hash algorithm used, sha1 or sha512")
275+
("hash" = String, Path, description = "Hash of the file, sha1 or sha512", example = "d67e66ea4bb2409997b636dae4203d33764cdcc8"),
276+
("algorithm" = String, Query, description = "Hash algorithm used, sha1 or sha512", example = "sha1")
277277
),
278278
responses(
279279
(status = 200, description = "File found", body = Version)
@@ -327,8 +327,8 @@ pub async fn get_version_files(
327327
path = "/modrinth/v2/version_file/{hash}/update",
328328
request_body = UpdateItems,
329329
params(
330-
("hash" = String, Path, description = "Hash of the file, sha1 or sha512"),
331-
("algorithm" = String, Query, description = "Hash algorithm used, sha1 or sha512")
330+
("hash" = String, Path, description = "Hash of the file, sha1 or sha512", example = "d67e66ea4bb2409997b636dae4203d33764cdcc8"),
331+
("algorithm" = String, Query, description = "Hash algorithm used, sha1 or sha512", example = "sha1")
332332
),
333333
responses(
334334
(status = 200, description = "File updated", body = Version)
@@ -361,6 +361,7 @@ pub async fn update_version_file(
361361
#[utoipa::path(
362362
post,
363363
path = "/modrinth/v2/version_files/update",
364+
request_body = MultiUpdateItems,
364365
responses(
365366
(status = 200, description = "Versions Found", body = Vec<Version>)
366367
),

0 commit comments

Comments
 (0)