Add utoipa info for v2 routes (#5775)
* wip: add v2 docs, routes to config, paths * fix up path prefixes * fix leading slashes * fix slash route * fix more slashes * wip: full utopification of v2 * convert last few v2 routes to utoipa
This commit is contained in:
@@ -11,9 +11,9 @@ use actix_web::{HttpRequest, HttpResponse, delete, get, post, web};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
pub fn config(cfg: &mut utoipa_actix_web::service_config::ServiceConfig) {
|
||||
cfg.service(
|
||||
web::scope("version_file")
|
||||
utoipa_actix_web::scope("/version_file")
|
||||
.service(delete_file)
|
||||
.service(get_version_from_hash)
|
||||
.service(download_version)
|
||||
@@ -22,7 +22,7 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
);
|
||||
|
||||
cfg.service(
|
||||
web::scope("version_files")
|
||||
utoipa_actix_web::scope("/version_files")
|
||||
.service(get_versions_from_hashes)
|
||||
.service(update_files)
|
||||
.service(update_files_many)
|
||||
@@ -31,7 +31,36 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||
}
|
||||
|
||||
// under /api/v1/version_file/{hash}
|
||||
#[get("{version_id}")]
|
||||
/// Get version metadata by file hash.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
operation_id = "versionFromHash",
|
||||
params(
|
||||
(
|
||||
"version_id" = String,
|
||||
Path,
|
||||
description = "The hexadecimal file hash"
|
||||
),
|
||||
(
|
||||
"algorithm" = Option<String>,
|
||||
Query,
|
||||
description = "Hash algorithm to use (sha1 or sha512)"
|
||||
),
|
||||
(
|
||||
"version_id" = Option<crate::models::ids::VersionId>,
|
||||
Query,
|
||||
description = "Optional version ID when hash maps to multiple files"
|
||||
)
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Expected response to a valid request"),
|
||||
(
|
||||
status = 404,
|
||||
description = "The requested item(s) were not found or no authorization to access the requested item(s)"
|
||||
)
|
||||
)
|
||||
)]
|
||||
#[get("/{version_id}")]
|
||||
pub async fn get_version_from_hash(
|
||||
req: HttpRequest,
|
||||
info: web::Path<(String,)>,
|
||||
@@ -62,7 +91,36 @@ pub async fn get_version_from_hash(
|
||||
}
|
||||
|
||||
// under /api/v1/version_file/{hash}/download
|
||||
#[get("{version_id}/download")]
|
||||
/// Download a file by hash.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
operation_id = "downloadVersionFromHash",
|
||||
params(
|
||||
(
|
||||
"version_id" = String,
|
||||
Path,
|
||||
description = "The hexadecimal file hash"
|
||||
),
|
||||
(
|
||||
"algorithm" = Option<String>,
|
||||
Query,
|
||||
description = "Hash algorithm to use (sha1 or sha512)"
|
||||
),
|
||||
(
|
||||
"version_id" = Option<crate::models::ids::VersionId>,
|
||||
Query,
|
||||
description = "Optional version ID when hash maps to multiple files"
|
||||
)
|
||||
),
|
||||
responses(
|
||||
(status = 302, description = "Temporary redirect to file URL"),
|
||||
(
|
||||
status = 404,
|
||||
description = "The requested item(s) were not found or no authorization to access the requested item(s)"
|
||||
)
|
||||
)
|
||||
)]
|
||||
#[get("/{version_id}/download")]
|
||||
pub async fn download_version(
|
||||
req: HttpRequest,
|
||||
info: web::Path<(String,)>,
|
||||
@@ -85,7 +143,41 @@ pub async fn download_version(
|
||||
}
|
||||
|
||||
// under /api/v1/version_file/{hash}
|
||||
#[delete("{version_id}")]
|
||||
/// Delete a file by hash.
|
||||
#[utoipa::path(
|
||||
delete,
|
||||
operation_id = "deleteFileFromHash",
|
||||
params(
|
||||
(
|
||||
"version_id" = String,
|
||||
Path,
|
||||
description = "The hexadecimal file hash"
|
||||
),
|
||||
(
|
||||
"algorithm" = Option<String>,
|
||||
Query,
|
||||
description = "Hash algorithm to use (sha1 or sha512)"
|
||||
),
|
||||
(
|
||||
"version_id" = Option<crate::models::ids::VersionId>,
|
||||
Query,
|
||||
description = "Optional version ID to delete from"
|
||||
)
|
||||
),
|
||||
responses(
|
||||
(status = 204, description = "Expected response to a valid request"),
|
||||
(
|
||||
status = 401,
|
||||
description = "Incorrect token scopes or no authorization to access the requested item(s)"
|
||||
),
|
||||
(
|
||||
status = 404,
|
||||
description = "The requested item(s) were not found or no authorization to access the requested item(s)"
|
||||
)
|
||||
),
|
||||
security(("bearer_auth" = ["VERSION_WRITE"]))
|
||||
)]
|
||||
#[delete("/{version_id}")]
|
||||
pub async fn delete_file(
|
||||
req: HttpRequest,
|
||||
info: web::Path<(String,)>,
|
||||
@@ -107,14 +199,45 @@ pub async fn delete_file(
|
||||
.or_else(v2_reroute::flatten_404_error)
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, utoipa::ToSchema)]
|
||||
pub struct UpdateData {
|
||||
pub loaders: Option<Vec<String>>,
|
||||
pub game_versions: Option<Vec<String>>,
|
||||
pub version_types: Option<Vec<VersionType>>,
|
||||
}
|
||||
|
||||
#[post("{version_id}/update")]
|
||||
/// Get the latest compatible version from a file hash.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
operation_id = "getLatestVersionFromHash",
|
||||
params(
|
||||
(
|
||||
"version_id" = String,
|
||||
Path,
|
||||
description = "The hexadecimal file hash"
|
||||
),
|
||||
(
|
||||
"algorithm" = Option<String>,
|
||||
Query,
|
||||
description = "Hash algorithm to use (sha1 or sha512)"
|
||||
),
|
||||
(
|
||||
"version_id" = Option<crate::models::ids::VersionId>,
|
||||
Query,
|
||||
description = "Optional version ID when hash maps to multiple files"
|
||||
)
|
||||
),
|
||||
request_body = UpdateData,
|
||||
responses(
|
||||
(status = 200, description = "Expected response to a valid request"),
|
||||
(status = 400, description = "Request was invalid, see given error"),
|
||||
(
|
||||
status = 404,
|
||||
description = "The requested item(s) were not found or no authorization to access the requested item(s)"
|
||||
)
|
||||
)
|
||||
)]
|
||||
#[post("/{version_id}/update")]
|
||||
pub async fn get_update_from_hash(
|
||||
req: HttpRequest,
|
||||
info: web::Path<(String,)>,
|
||||
@@ -162,13 +285,23 @@ pub async fn get_update_from_hash(
|
||||
}
|
||||
|
||||
// Requests above with multiple versions below
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, utoipa::ToSchema)]
|
||||
pub struct FileHashes {
|
||||
pub algorithm: Option<String>,
|
||||
pub hashes: Vec<String>,
|
||||
}
|
||||
|
||||
// under /api/v2/version_files
|
||||
/// Get versions from file hashes.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
operation_id = "versionsFromHashes",
|
||||
request_body = FileHashes,
|
||||
responses(
|
||||
(status = 200, description = "Expected response to a valid request"),
|
||||
(status = 400, description = "Request was invalid, see given error")
|
||||
)
|
||||
)]
|
||||
#[post("")]
|
||||
pub async fn get_versions_from_hashes(
|
||||
req: HttpRequest,
|
||||
@@ -210,7 +343,17 @@ pub async fn get_versions_from_hashes(
|
||||
}
|
||||
}
|
||||
|
||||
#[post("project")]
|
||||
/// Get projects from file hashes.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
operation_id = "projectsFromHashes",
|
||||
request_body = FileHashes,
|
||||
responses(
|
||||
(status = 200, description = "Expected response to a valid request"),
|
||||
(status = 400, description = "Request was invalid, see given error")
|
||||
)
|
||||
)]
|
||||
#[post("/project")]
|
||||
pub async fn get_projects_from_hashes(
|
||||
req: HttpRequest,
|
||||
pool: web::Data<PgPool>,
|
||||
@@ -268,7 +411,7 @@ pub async fn get_projects_from_hashes(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, utoipa::ToSchema)]
|
||||
pub struct ManyUpdateData {
|
||||
pub algorithm: Option<String>, // Defaults to calculation based on size of hash
|
||||
pub hashes: Vec<String>,
|
||||
@@ -277,7 +420,17 @@ pub struct ManyUpdateData {
|
||||
pub version_types: Option<Vec<VersionType>>,
|
||||
}
|
||||
|
||||
#[post("update")]
|
||||
/// Get latest compatible versions for multiple hashes.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
operation_id = "getLatestVersionsFromHashes",
|
||||
request_body = ManyUpdateData,
|
||||
responses(
|
||||
(status = 200, description = "Expected response to a valid request"),
|
||||
(status = 400, description = "Request was invalid, see given error")
|
||||
)
|
||||
)]
|
||||
#[post("/update")]
|
||||
pub async fn update_files(
|
||||
pool: web::Data<ReadOnlyPgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
@@ -316,7 +469,17 @@ pub async fn update_files(
|
||||
Ok(HttpResponse::Ok().json(v3_versions))
|
||||
}
|
||||
|
||||
#[post("update_many")]
|
||||
/// Get all latest compatible versions for multiple hashes.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
operation_id = "getLatestVersionsFromHashesMany",
|
||||
request_body = ManyUpdateData,
|
||||
responses(
|
||||
(status = 200, description = "Expected response to a valid request"),
|
||||
(status = 400, description = "Request was invalid, see given error")
|
||||
)
|
||||
)]
|
||||
#[post("/update_many")]
|
||||
pub async fn update_files_many(
|
||||
pool: web::Data<ReadOnlyPgPool>,
|
||||
redis: web::Data<RedisPool>,
|
||||
@@ -358,7 +521,7 @@ pub async fn update_files_many(
|
||||
Ok(HttpResponse::Ok().json(v3_versions))
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[derive(Serialize, Deserialize, utoipa::ToSchema)]
|
||||
pub struct FileUpdateData {
|
||||
pub hash: String,
|
||||
pub loaders: Option<Vec<String>>,
|
||||
@@ -366,13 +529,23 @@ pub struct FileUpdateData {
|
||||
pub version_types: Option<Vec<VersionType>>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, utoipa::ToSchema)]
|
||||
pub struct ManyFileUpdateData {
|
||||
pub algorithm: Option<String>, // Defaults to calculation based on size of hash
|
||||
pub hashes: Vec<FileUpdateData>,
|
||||
}
|
||||
|
||||
#[post("update_individual")]
|
||||
/// Get latest versions with per-hash filters.
|
||||
#[utoipa::path(
|
||||
post,
|
||||
operation_id = "getLatestVersionsFromHashesIndividual",
|
||||
request_body = ManyFileUpdateData,
|
||||
responses(
|
||||
(status = 200, description = "Expected response to a valid request"),
|
||||
(status = 400, description = "Request was invalid, see given error")
|
||||
)
|
||||
)]
|
||||
#[post("/update_individual")]
|
||||
pub async fn update_individual_files(
|
||||
req: HttpRequest,
|
||||
pool: web::Data<PgPool>,
|
||||
|
||||
Reference in New Issue
Block a user