feat: better api docs (#6586)

* feat: docs

* fix tombi

* chore: fix some of the routes rendering with missing /

* response schemas

* fix: restore labrinth docs routes

* Fix path parameter docs in routes

* remove utoipa-actix-web

* consistency

* improve version intros

* improve formatting, examples

* better hash examples, move openapi stuff to openapi.rs

* more utoipa param fixes

* request body docs

* chore: remove moderation route from v2, remove ingest & webhooks from v3 spec

* fixes

* chore: tweak sources titles

* fix

* fix test

* improve examples

* increase compiler spawned thread stack size

* remove unused tests & script

* test

* bro what

* fix

---------

Co-authored-by: aecsocket <43144841+aecsocket@users.noreply.github.com>
This commit is contained in:
François-Xavier Talbot
2026-07-04 14:19:21 +00:00
committed by GitHub
co-authored by aecsocket
parent b26d048a63
commit 4a6fa9fc3d
103 changed files with 4546 additions and 1387 deletions
+62 -12
View File
@@ -16,20 +16,15 @@ use crate::models::threads::{MessageBody, Thread, ThreadType};
use crate::models::users::User;
use crate::queue::session::AuthQueue;
use crate::routes::ApiError;
use actix_web::{HttpRequest, HttpResponse, web};
use actix_web::{HttpRequest, HttpResponse, delete, get, post, web};
use futures::TryStreamExt;
use serde::Deserialize;
pub fn config(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope("thread")
.route("{id}", web::get().to(thread_get))
.route("{id}", web::post().to(thread_send_message)),
);
cfg.service(
web::scope("message").route("{id}", web::delete().to(message_delete)),
);
cfg.route("threads", web::get().to(threads_get));
pub fn config(cfg: &mut actix_web::web::ServiceConfig) {
cfg.service(thread_get_route)
.service(thread_send_message_route)
.service(message_delete_route)
.service(threads_get_route);
}
pub async fn is_authorized_thread(
@@ -267,6 +262,18 @@ pub async fn filter_authorized_threads(
Ok(final_threads)
}
#[utoipa::path(tag = "threads", responses((status = OK, body = Thread)))]
#[get("/thread/{id}")]
pub async fn thread_get_route(
req: HttpRequest,
info: web::Path<(ThreadId,)>,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
session_queue: web::Data<AuthQueue>,
) -> Result<HttpResponse, ApiError> {
thread_get(req, info, pool, redis, session_queue).await
}
pub async fn thread_get(
req: HttpRequest,
info: web::Path<(ThreadId,)>,
@@ -324,6 +331,22 @@ pub struct ThreadIds {
pub ids: String,
}
#[utoipa::path(
tag = "threads",
params(("ids" = String, Query)),
responses((status = OK, body = Vec<Thread>))
)]
#[get("/threads")]
pub async fn threads_get_route(
req: HttpRequest,
ids: web::Query<ThreadIds>,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
session_queue: web::Data<AuthQueue>,
) -> Result<HttpResponse, ApiError> {
threads_get(req, ids, pool, redis, session_queue).await
}
pub async fn threads_get(
req: HttpRequest,
web::Query(ids): web::Query<ThreadIds>,
@@ -356,11 +379,25 @@ pub async fn threads_get(
Ok(HttpResponse::Ok().json(threads))
}
#[derive(Deserialize)]
#[derive(Deserialize, utoipa::ToSchema)]
pub struct NewThreadMessage {
pub body: MessageBody,
}
#[utoipa::path(tag = "threads", responses((status = NO_CONTENT)))]
#[post("/thread/{id}")]
pub async fn thread_send_message_route(
req: HttpRequest,
info: web::Path<(ThreadId,)>,
pool: web::Data<PgPool>,
new_message: web::Json<NewThreadMessage>,
redis: web::Data<RedisPool>,
session_queue: web::Data<AuthQueue>,
) -> Result<HttpResponse, ApiError> {
thread_send_message(req, info, pool, new_message, redis, session_queue)
.await
}
pub async fn thread_send_message(
req: HttpRequest,
info: web::Path<(ThreadId,)>,
@@ -591,6 +628,19 @@ pub async fn thread_send_message_internal(
}
}
#[utoipa::path(tag = "threads", responses((status = NO_CONTENT)))]
#[delete("/message/{id}")]
pub async fn message_delete_route(
req: HttpRequest,
info: web::Path<(ThreadMessageId,)>,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
session_queue: web::Data<AuthQueue>,
file_host: web::Data<dyn FileHost>,
) -> Result<HttpResponse, ApiError> {
message_delete(req, info, pool, redis, session_queue, file_host).await
}
pub async fn message_delete(
req: HttpRequest,
info: web::Path<(ThreadMessageId,)>,