1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use super::model::{
    CompatGenerateRequest, FinishReason, GenerateParameters, GenerateRequest, GenerateResponse,
    Info, StreamDetails, StreamResponse, Token,
};
use crate::{api::model::ErrorResponse, llm::models::Models};
use utoipa::OpenApi;

/// Represents the API documentation for the text generation inference service.
///
/// This struct uses `utoipa::OpenApi` to provide a centralized documentation of the API endpoints
/// and their associated request and response models. It is used to generate OpenAPI specification
/// for the service, which can be served as a Swagger UI or other OpenAPI-compatible documentation tools.
#[derive(OpenApi)]
#[openapi(
    // List of API endpoints to be included in the documentation.
    paths(
        super::routes::generate::generate_handler,
        super::routes::generate_text::generate_text_handler,
        super::routes::generate_stream::generate_stream_handler,
        super::routes::model::generate_model_handler,
        super::routes::health::get_health_handler,
        super::routes::info::get_info_handler
    ),
    // Schema components for requests and responses used across the API.
    components(
        schemas(
            CompatGenerateRequest,
            GenerateRequest,
            GenerateResponse,
            GenerateParameters,
            ErrorResponse,
            StreamResponse,
            StreamDetails,
            Token,
            FinishReason,
            Info,
            Models
        )
    ),
    // Metadata and description of the API tags.
    tags(
        (name = "Text Generation Inference", description = "Text generation Inference API")
    )
)]
pub struct ApiDoc;

#[cfg(test)]
mod tests {
    use super::*;
    use utoipa::OpenApi;

    #[test]
    fn api_doc_contains_all_endpoints() {
        let api_doc = ApiDoc::openapi();
        let paths = api_doc.paths.paths;
        assert!(paths.contains_key("/"));
        assert!(paths.contains_key("/generate"));
        assert!(paths.contains_key("/generate_stream"));
        assert!(paths.contains_key("/health"));
        assert!(paths.contains_key("/info"));
    }
}