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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
//! Schema viewer component for displaying type definitions.
use dioxus::prelude::*;
use dioxus_free_icons::{Icon, icons::ld_icons::*};
use crate::parser::SchemaDefinition;
/// Props for SchemaViewer component.
#[derive(Props, Clone, PartialEq)]
pub struct SchemaViewerProps {
/// The schema to display.
pub schema: SchemaDefinition,
/// Nesting depth for indentation.
#[props(default = 0)]
pub depth: usize,
/// Whether this is initially expanded.
#[props(default = false)]
pub expanded: bool,
/// Property name (for nested properties).
#[props(default)]
pub name: Option<String>,
/// Whether this property is required.
#[props(default = false)]
pub required: bool,
}
/// Recursive schema viewer with expand/collapse for complex types.
#[component]
pub fn SchemaViewer(props: SchemaViewerProps) -> Element {
let mut is_expanded = use_signal(|| props.expanded || props.depth == 0);
let schema = &props.schema;
let is_complex = schema.is_complex();
let type_display = schema.display_type();
let indent_class = if props.depth > 0 {
"ml-4 border-l-2 border-base-300 pl-3"
} else {
""
};
rsx! {
div { class: "py-1.5 {indent_class}",
// Header row with name, type, and expand button
div { class: "flex items-center gap-2 flex-wrap",
// Expand/collapse for complex types
if is_complex && !schema.properties.is_empty() {
button {
class: "p-0.5 hover:bg-base-300 rounded transition-colors",
onclick: move |_| is_expanded.set(!is_expanded()),
Icon {
class: if is_expanded() { "size-4 text-base-content/50 transform rotate-90 transition-transform" } else { "size-4 text-base-content/50 transition-transform" },
icon: LdChevronRight
}
}
}
// Property name
if let Some(name) = &props.name {
code { class: "font-mono font-semibold text-primary text-sm",
"{name}"
}
}
// Type badge
span { class: "text-xs px-2 py-0.5 rounded-full bg-base-300 text-base-content/70",
"{type_display}"
}
// Required indicator
if props.required {
span { class: "text-xs px-2 py-0.5 rounded-full bg-error/20 text-error",
"required"
}
}
// Nullable indicator
if schema.nullable {
span { class: "text-xs px-2 py-0.5 rounded-full bg-base-300 text-base-content/50",
"nullable"
}
}
// Format
if let Some(format) = &schema.format {
span { class: "text-xs text-base-content/50",
"({format})"
}
}
}
// Description
if let Some(desc) = &schema.description {
p { class: "text-sm text-base-content/70 mt-1",
"{desc}"
}
}
// Enum values
if !schema.enum_values.is_empty() {
div { class: "mt-1 flex items-center gap-2 flex-wrap",
span { class: "text-xs text-base-content/50", "Enum:" }
for value in &schema.enum_values {
code { class: "text-xs px-1.5 py-0.5 rounded bg-base-300 font-mono",
"{value}"
}
}
}
}
// Default value
if let Some(default) = &schema.default {
div { class: "mt-1",
span { class: "text-xs text-base-content/50", "Default: " }
code { class: "text-xs font-mono text-primary",
"{default}"
}
}
}
// Example value
if let Some(example) = &schema.example {
div { class: "mt-1",
span { class: "text-xs text-base-content/50", "Example: " }
code { class: "text-xs font-mono text-secondary",
"{example}"
}
}
}
// Nested properties for objects
if is_expanded() && !schema.properties.is_empty() {
div { class: "mt-2",
for (name, prop_schema) in &schema.properties {
SchemaViewer {
key: "{name}",
schema: prop_schema.clone(),
depth: props.depth + 1,
name: Some(name.clone()),
required: schema.required.contains(name),
}
}
}
}
// Array items
if is_expanded() {
if let Some(items) = &schema.items {
if items.is_complex() {
div { class: "mt-2",
span { class: "text-xs text-base-content/50 ml-4", "Array items:" }
SchemaViewer {
schema: (**items).clone(),
depth: props.depth + 1,
}
}
}
}
}
// OneOf/AnyOf/AllOf
if is_expanded() {
if !schema.one_of.is_empty() {
div { class: "mt-2 ml-4",
span { class: "text-xs text-base-content/50 font-semibold", "One of:" }
for (i, variant) in schema.one_of.iter().enumerate() {
SchemaViewer {
key: "{i}",
schema: variant.clone(),
depth: props.depth + 1,
}
}
}
}
if !schema.any_of.is_empty() {
div { class: "mt-2 ml-4",
span { class: "text-xs text-base-content/50 font-semibold", "Any of:" }
for (i, variant) in schema.any_of.iter().enumerate() {
SchemaViewer {
key: "{i}",
schema: variant.clone(),
depth: props.depth + 1,
}
}
}
}
if !schema.all_of.is_empty() {
div { class: "mt-2 ml-4",
span { class: "text-xs text-base-content/50 font-semibold", "All of:" }
for (i, variant) in schema.all_of.iter().enumerate() {
SchemaViewer {
key: "{i}",
schema: variant.clone(),
depth: props.depth + 1,
}
}
}
}
}
}
}
}
/// Props for SchemaTypeLabel component.
#[derive(Props, Clone, PartialEq)]
pub struct SchemaTypeLabelProps {
/// The schema to display type for.
pub schema: SchemaDefinition,
}
/// Simple type label without expand/collapse.
#[component]
pub fn SchemaTypeLabel(props: SchemaTypeLabelProps) -> Element {
let type_display = props.schema.display_type();
rsx! {
span { class: "text-xs px-2 py-0.5 rounded-full bg-base-300 text-base-content/70 font-mono",
"{type_display}"
}
}
}