openapi_nexus_go/templating/data/
api_operation_data.rs1use serde::{Deserialize, Serialize};
4
5use crate::ast::GoStruct;
6use crate::templating::data::CommonFileHeaderData;
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct GoApiMethodData {
11 pub name: String, pub http_method: String,
13 pub path: String,
14 pub operation_id: String, pub path_params: Vec<GoParameterInfo>,
16 pub query_params: Vec<GoParameterInfo>,
17 pub header_params: Vec<GoParameterInfo>,
18 pub body_param: Option<GoParameterInfo>,
19 pub has_request_body: bool,
20 pub request_body_content_type: String,
21 pub request_body_type: Option<String>, pub response_type: Option<String>,
23 pub description: Option<String>,
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct GoParameterInfo {
29 pub original_name: String,
30 pub param_name: String, pub param_name_camel: String, pub go_type: String, pub required: bool,
34 pub description: Option<String>,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct ApiOperationData {
40 pub client_struct: GoStruct,
41 pub methods: Vec<GoApiMethodData>,
42 pub imports: Vec<String>,
43 pub tag: String,
44 pub tag_pascal_case: String,
45 pub tag_snake_case: String,
46 pub package_name: String,
47 pub sdk_name: String, pub common_file_header: CommonFileHeaderData,
49}
50
51impl ApiOperationData {
52 pub fn new(
53 client_struct: GoStruct,
54 tag: String,
55 sdk_name: String,
56 common_file_header: CommonFileHeaderData,
57 ) -> Self {
58 use heck::{ToPascalCase as _, ToSnakeCase as _};
59 Self {
60 client_struct,
61 methods: Vec::new(),
62 imports: Vec::new(),
63 tag: tag.clone(),
64 tag_pascal_case: tag.to_pascal_case(),
65 tag_snake_case: tag.to_snake_case(),
66 package_name: "apis".to_string(),
67 sdk_name,
68 common_file_header,
69 }
70 }
71
72 pub fn with_methods(mut self, methods: Vec<GoApiMethodData>) -> Self {
73 self.methods = methods;
74 self
75 }
76
77 pub fn with_imports(mut self, imports: Vec<String>) -> Self {
78 self.imports = imports;
79 self
80 }
81}