vika_cli/templates/context/
api_context.rs

1use serde::Serialize;
2
3/// Context for API client function generation.
4#[derive(Debug, Clone, Serialize)]
5pub struct ApiContext {
6    pub function_name: String,
7    pub operation_id: Option<String>,
8    pub http_method: String,
9    pub path: String,
10    pub path_params: Vec<Parameter>,
11    pub query_params: Vec<Parameter>,
12    pub request_body: Option<RequestBody>,
13    pub responses: Vec<Response>,
14    pub type_imports: String,
15    pub http_import: String,
16    pub return_type: String,
17    pub function_body: String,
18    pub module_name: String,
19    pub params: String,
20    pub description: String,
21    /// Spec name (for multi-spec mode)
22    pub spec_name: Option<String>,
23}
24
25/// Parameter information for API functions.
26#[derive(Debug, Clone, Serialize)]
27pub struct Parameter {
28    pub name: String,
29    pub param_type: String,
30    pub optional: bool,
31    pub description: Option<String>,
32}
33
34/// Request body information.
35#[derive(Debug, Clone, Serialize)]
36pub struct RequestBody {
37    pub type_name: String,
38    pub description: Option<String>,
39}
40
41/// Response information.
42#[derive(Debug, Clone, Serialize)]
43pub struct Response {
44    pub status_code: u16,
45    pub body_type: String,
46}
47
48impl ApiContext {
49    /// Create a new ApiContext.
50    #[allow(clippy::too_many_arguments)]
51    pub fn new(
52        function_name: String,
53        operation_id: Option<String>,
54        http_method: String,
55        path: String,
56        path_params: Vec<Parameter>,
57        query_params: Vec<Parameter>,
58        request_body: Option<RequestBody>,
59        responses: Vec<Response>,
60        type_imports: String,
61        http_import: String,
62        return_type: String,
63        function_body: String,
64        module_name: String,
65        params: String,
66        description: String,
67        spec_name: Option<String>,
68    ) -> Self {
69        Self {
70            function_name,
71            operation_id,
72            http_method,
73            path,
74            path_params,
75            query_params,
76            request_body,
77            responses,
78            type_imports,
79            http_import,
80            return_type,
81            function_body,
82            module_name,
83            params,
84            description,
85            spec_name,
86        }
87    }
88}
89
90impl Parameter {
91    /// Create a new Parameter.
92    pub fn new(
93        name: String,
94        param_type: String,
95        optional: bool,
96        description: Option<String>,
97    ) -> Self {
98        Self {
99            name,
100            param_type,
101            optional,
102            description,
103        }
104    }
105}
106
107impl RequestBody {
108    /// Create a new RequestBody.
109    pub fn new(type_name: String, description: Option<String>) -> Self {
110        Self {
111            type_name,
112            description,
113        }
114    }
115}
116
117impl Response {
118    /// Create a new Response.
119    pub fn new(status_code: u16, body_type: String) -> Self {
120        Self {
121            status_code,
122            body_type,
123        }
124    }
125}