1use super::openapi_types::OpenApiSpec;
4
5#[derive(Debug, Clone, PartialEq)]
7pub struct ParsedDoc {
8 pub frontmatter: DocFrontmatter,
10 pub content: Vec<DocNode>,
12 pub raw_markdown: String,
14}
15
16#[derive(Debug, Clone, Default, PartialEq)]
18pub struct DocFrontmatter {
19 pub title: String,
21 pub description: Option<String>,
23 pub sidebar_title: Option<String>,
25 pub icon: Option<String>,
27}
28
29#[derive(Debug, Clone, PartialEq)]
31#[non_exhaustive]
32pub enum DocNode {
33 Markdown(String),
35 Callout(CalloutNode),
37 Card(CardNode),
39 CardGroup(CardGroupNode),
41 Tabs(TabsNode),
43 Steps(StepsNode),
45 AccordionGroup(AccordionGroupNode),
47 CodeBlock(CodeBlockNode),
49 CodeGroup(CodeGroupNode),
51 ParamField(ParamFieldNode),
53 ResponseField(ResponseFieldNode),
55 Expandable(ExpandableNode),
57 RequestExample(RequestExampleNode),
59 ResponseExample(ResponseExampleNode),
61 Update(UpdateNode),
63 OpenApi(OpenApiNode),
65}
66
67#[derive(Debug, Clone, Copy, PartialEq, Eq)]
69#[non_exhaustive]
70pub enum CalloutType {
71 Tip,
72 Note,
73 Warning,
74 Info,
75}
76
77impl CalloutType {
78 pub fn parse(s: &str) -> Option<Self> {
79 match s.to_lowercase().as_str() {
80 "tip" => Some(Self::Tip),
81 "note" => Some(Self::Note),
82 "warning" => Some(Self::Warning),
83 "info" => Some(Self::Info),
84 _ => None,
85 }
86 }
87
88 pub fn as_str(&self) -> &'static str {
89 match self {
90 Self::Tip => "Tip",
91 Self::Note => "Note",
92 Self::Warning => "Warning",
93 Self::Info => "Info",
94 }
95 }
96
97 pub fn alert_class(&self) -> &'static str {
99 match self {
100 Self::Tip => "alert-success",
101 Self::Note => "alert-info",
102 Self::Warning => "alert-warning",
103 Self::Info => "alert-info",
104 }
105 }
106
107 pub fn icon_name(&self) -> &'static str {
109 match self {
110 Self::Tip => "lightbulb",
111 Self::Note => "info",
112 Self::Warning => "alert-triangle",
113 Self::Info => "info",
114 }
115 }
116}
117
118#[derive(Debug, Clone, PartialEq)]
120pub struct CalloutNode {
121 pub callout_type: CalloutType,
122 pub content: String,
123}
124
125#[derive(Debug, Clone, PartialEq)]
127pub struct CardNode {
128 pub title: String,
129 pub icon: Option<String>,
130 pub href: Option<String>,
131 pub content: String,
132}
133
134#[derive(Debug, Clone, PartialEq)]
136pub struct CardGroupNode {
137 pub cols: u8,
138 pub cards: Vec<CardNode>,
139}
140
141#[derive(Debug, Clone, PartialEq)]
143pub struct TabNode {
144 pub title: String,
145 pub content: Vec<DocNode>,
147}
148
149#[derive(Debug, Clone, PartialEq)]
151pub struct TabsNode {
152 pub tabs: Vec<TabNode>,
153}
154
155#[derive(Debug, Clone, PartialEq)]
157pub struct StepNode {
158 pub title: String,
159 pub content: Vec<DocNode>,
161}
162
163#[derive(Debug, Clone, PartialEq)]
165pub struct StepsNode {
166 pub steps: Vec<StepNode>,
167}
168
169#[derive(Debug, Clone, PartialEq)]
171pub struct AccordionNode {
172 pub title: String,
173 pub icon: Option<String>,
174 pub content: Vec<DocNode>,
176}
177
178#[derive(Debug, Clone, PartialEq)]
180pub struct AccordionGroupNode {
181 pub items: Vec<AccordionNode>,
182}
183
184#[derive(Debug, Clone, PartialEq)]
186pub struct CodeBlockNode {
187 pub language: Option<String>,
188 pub code: String,
189 pub filename: Option<String>,
190}
191
192#[derive(Debug, Clone, PartialEq)]
194pub struct CodeGroupNode {
195 pub blocks: Vec<CodeBlockNode>,
196}
197
198#[derive(Debug, Clone, Copy, PartialEq, Eq)]
200#[non_exhaustive]
201pub enum ParamLocation {
202 Header,
203 Path,
204 Query,
205 Body,
206}
207
208impl ParamLocation {
209 pub fn parse(s: &str) -> Option<Self> {
210 match s.to_lowercase().as_str() {
211 "header" => Some(Self::Header),
212 "path" => Some(Self::Path),
213 "query" => Some(Self::Query),
214 "body" => Some(Self::Body),
215 _ => None,
216 }
217 }
218
219 pub fn as_str(&self) -> &'static str {
220 match self {
221 Self::Header => "header",
222 Self::Path => "path",
223 Self::Query => "query",
224 Self::Body => "body",
225 }
226 }
227
228 pub fn badge_class(&self) -> &'static str {
230 match self {
231 Self::Header => "badge-warning",
232 Self::Path => "badge-primary",
233 Self::Query => "badge-info",
234 Self::Body => "badge-secondary",
235 }
236 }
237}
238
239#[derive(Debug, Clone, PartialEq)]
241pub struct ParamFieldNode {
242 pub name: String,
244 pub location: ParamLocation,
246 pub param_type: String,
248 pub required: bool,
250 pub default: Option<String>,
252 pub content: Vec<DocNode>,
254}
255
256#[derive(Debug, Clone, PartialEq)]
258pub struct ResponseFieldNode {
259 pub name: String,
261 pub field_type: String,
263 pub required: bool,
265 pub content: String,
267 pub expandable: Option<ExpandableNode>,
269}
270
271#[derive(Debug, Clone, PartialEq)]
273pub struct ExpandableNode {
274 pub title: String,
276 pub fields: Vec<ResponseFieldNode>,
278}
279
280#[derive(Debug, Clone, PartialEq)]
282pub struct RequestExampleNode {
283 pub blocks: Vec<CodeBlockNode>,
285}
286
287#[derive(Debug, Clone, PartialEq)]
289pub struct ResponseExampleNode {
290 pub blocks: Vec<CodeBlockNode>,
292}
293
294#[derive(Debug, Clone, PartialEq)]
296pub struct UpdateNode {
297 pub label: String,
299 pub description: String,
301 pub content: Vec<DocNode>,
303}
304
305#[derive(Debug, Clone, PartialEq)]
307pub struct OpenApiNode {
308 pub spec: OpenApiSpec,
310 pub tags: Option<Vec<String>>,
312 pub show_schemas: bool,
314}