vika_cli/templates/context/
api_context.rs1use serde::Serialize;
2
3#[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#[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#[derive(Debug, Clone, Serialize)]
34pub struct RequestBody {
35 pub type_name: String,
36 pub description: Option<String>,
37}
38
39#[derive(Debug, Clone, Serialize)]
41pub struct Response {
42 pub status_code: u16,
43 pub body_type: String,
44}
45
46impl ApiContext {
47 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 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 pub fn new(type_name: String, description: Option<String>) -> Self {
100 Self { type_name, description }
101 }
102}
103
104impl Response {
105 pub fn new(status_code: u16, body_type: String) -> Self {
107 Self {
108 status_code,
109 body_type,
110 }
111 }
112}
113