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}
22
23/// Parameter information for API functions.
24#[derive(Debug, Clone, Serialize)]
25pub struct Parameter {
26    pub name: String,
27    pub param_type: String,
28    pub optional: bool,
29    pub description: Option<String>,
30}
31
32/// Request body information.
33#[derive(Debug, Clone, Serialize)]
34pub struct RequestBody {
35    pub type_name: String,
36    pub description: Option<String>,
37}
38
39/// Response information.
40#[derive(Debug, Clone, Serialize)]
41pub struct Response {
42    pub status_code: u16,
43    pub body_type: String,
44}
45
46impl ApiContext {
47    /// Create a new ApiContext.
48    pub fn new(
49        function_name: String,
50        operation_id: Option<String>,
51        http_method: String,
52        path: String,
53        path_params: Vec<Parameter>,
54        query_params: Vec<Parameter>,
55        request_body: Option<RequestBody>,
56        responses: Vec<Response>,
57        type_imports: String,
58        http_import: String,
59        return_type: String,
60        function_body: String,
61        module_name: String,
62        params: String,
63        description: String,
64    ) -> Self {
65        Self {
66            function_name,
67            operation_id,
68            http_method,
69            path,
70            path_params,
71            query_params,
72            request_body,
73            responses,
74            type_imports,
75            http_import,
76            return_type,
77            function_body,
78            module_name,
79            params,
80            description,
81        }
82    }
83}
84
85impl Parameter {
86    /// Create a new Parameter.
87    pub fn new(name: String, param_type: String, optional: bool, description: Option<String>) -> Self {
88        Self {
89            name,
90            param_type,
91            optional,
92            description,
93        }
94    }
95}
96
97impl RequestBody {
98    /// Create a new RequestBody.
99    pub fn new(type_name: String, description: Option<String>) -> Self {
100        Self { type_name, description }
101    }
102}
103
104impl Response {
105    /// Create a new Response.
106    pub fn new(status_code: u16, body_type: String) -> Self {
107        Self {
108            status_code,
109            body_type,
110        }
111    }
112}
113