Skip to main content

dioxus_mdx/components/openapi/
request_body.rs

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