1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Request body component for API endpoint documentation.
use dioxus::prelude::*;
use crate::parser::ApiRequestBody;
use super::schema_viewer::SchemaViewer;
/// Props for RequestBodySection component.
#[derive(Props, Clone, PartialEq)]
pub struct RequestBodySectionProps {
/// The request body to display.
pub body: ApiRequestBody,
}
/// Request body schema viewer.
#[component]
pub fn RequestBodySection(props: RequestBodySectionProps) -> Element {
let body = &props.body;
rsx! {
div { class: "space-y-3",
// Required indicator
div { class: "flex items-center gap-2",
if body.required {
span { class: "text-xs px-2 py-0.5 rounded-full bg-error/20 text-error",
"required"
}
} else {
span { class: "text-xs px-2 py-0.5 rounded-full bg-base-300 text-base-content/50",
"optional"
}
}
}
// Description
if let Some(desc) = &body.description {
p { class: "text-sm text-base-content/70",
"{desc}"
}
}
// Content by media type
for content in &body.content {
div { class: "border border-base-300 rounded-lg overflow-hidden",
// Media type header
div { class: "px-3 py-2 bg-base-200 border-b border-base-300",
code { class: "text-xs font-mono text-base-content/70",
"{content.media_type}"
}
}
// Schema
if let Some(schema) = &content.schema {
div { class: "p-3",
SchemaViewer {
schema: schema.clone(),
expanded: true,
}
}
}
// Example
if let Some(example) = &content.example {
div { class: "px-3 py-2 border-t border-base-300 bg-base-200/50",
span { class: "text-xs text-base-content/50 font-semibold", "Example" }
pre { class: "mt-1 text-xs font-mono text-secondary overflow-x-auto",
"{example}"
}
}
}
}
}
}
}
}