oxirs_samm/codegen/
openapi_types.rs1use serde_json::{Map, Value};
2
3#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct PaginationConfig {
6 pub page_size: usize,
8 pub cursor_based: bool,
10 pub total_count_header: Option<String>,
12}
13
14impl Default for PaginationConfig {
15 fn default() -> Self {
16 Self {
17 page_size: 10,
18 cursor_based: false,
19 total_count_header: None,
20 }
21 }
22}
23
24impl PaginationConfig {
25 pub fn to_extension_value(&self) -> Value {
27 let mut obj = Map::new();
28 obj.insert(
29 "pageSize".to_string(),
30 Value::Number(serde_json::Number::from(self.page_size)),
31 );
32 obj.insert("cursorBased".to_string(), Value::Bool(self.cursor_based));
33 if let Some(ref header) = self.total_count_header {
34 obj.insert(
35 "totalCountHeader".to_string(),
36 Value::String(header.clone()),
37 );
38 }
39 Value::Object(obj)
40 }
41}
42
43#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
45pub enum OpenApiVersion {
46 #[default]
48 V30,
49 V31,
51}
52
53#[derive(Debug, Clone, Copy, PartialEq, Eq)]
55pub enum HttpMethod {
56 Get,
58 Post,
60 Put,
62 Patch,
64 Delete,
66}
67
68impl HttpMethod {
69 pub fn as_str(self) -> &'static str {
71 match self {
72 HttpMethod::Get => "get",
73 HttpMethod::Post => "post",
74 HttpMethod::Put => "put",
75 HttpMethod::Patch => "patch",
76 HttpMethod::Delete => "delete",
77 }
78 }
79}
80
81#[derive(Debug, Clone)]
83pub struct OpenApiOptions {
84 pub version: OpenApiVersion,
86 pub base_path: String,
88 pub api_version: String,
90 pub include_get: bool,
92 pub include_post: bool,
94 pub include_put: bool,
96 pub include_delete: bool,
98 pub use_defs_keyword: bool,
100 pub language: String,
102 pub pagination: Option<PaginationConfig>,
104}
105
106impl Default for OpenApiOptions {
107 fn default() -> Self {
108 Self {
109 version: OpenApiVersion::V30,
110 base_path: "/api/v1/aspects".to_string(),
111 api_version: "1.0.0".to_string(),
112 include_get: true,
113 include_post: false,
114 include_put: false,
115 include_delete: false,
116 use_defs_keyword: false,
117 language: "en".to_string(),
118 pagination: None,
119 }
120 }
121}